[Distutils] Responses to proposal

Fred L. Drake Fred L. Drake, Jr." <fdrake@acm.org
Wed, 20 Jan 1999 10:42:56 -0500 (EST)

Greg Ward writes:
 > My impetus for this was the need for specific module distributions to be
 > told where to go looking for external C libraries.  For instance, the

  Why do these need to be application specific?  Appropriate options
can be defined (such as -I and -L;) to do this without making them
application specific.

 > However, let's not limit ourselves to "where's this header file, where's
 > that library?" questions: lots of modules could have configuration
 > options that the builder might want to supply at build time.  And keep

  These should be easily handled using command-specific options, which 
may or may not need to be application-specific:  A few basic options
might be useful in the standard implementation simply so that the
option names are consistent (where to put temp files, config files,
  I'm inclined to think we need to elaborate on the command dispatch
mechanics a little to make sure we do the right thing to support both
application-specific extensibililty and site-specific extensibility.
  I'll make a mini-proposal:  Each command should be defined by a
class.  What class that is is determined using a registry initialized
from a configuration file for the site (to allow site administration
hooks) and the contents of a distutils sub-package.  The application
can update the registry as needed.  This might look like this:

import distutils.registry

baseclass = distutils.registry.get_cmd_class("install")

class DerivedInstallCmd(baseclass):
    LONG_OPTIONS = baseclass.LONG_OPTIONS + ["enable-foo", "disable-foo"]

    use_foo = 0

    def __init__(self, options):
        for item in options[:]:
            opt, arg = item
            if opt == "--enable-foo":
                self.use_foo = 1
            elif opt == "--disable-foo":
                self.use_foo = 0
        baseclass.__init__(self, options)

    def run(self):
        # use self.use_foo somehow...

distutils.registry.set_cmd_class("install", DerivedInstallCmd)

  The command dispatcher can use the same
distutils.registry.get_cmd_class() function to get the class that
should actually be used to implement the command, allowing all the
"hooked-in" functionality to remain.


Fred L. Drake, Jr.	     <fdrake@acm.org>
Corporation for National Research Initiatives
1895 Preston White Dr.	    Reston, VA  20191