[Distutils] clean -b argument ignored; set_undefined_options doesn't

Nicholas Riley njriley at uiuc.edu
Thu Sep 25 17:54:42 EDT 2003


Here's something that I think should work:

% python setup.py --help clean
Options for 'clean' command:
  --build-base (-b)  base build directory (default: 'build.build-base')
% python setup.py clean -b ../builds
running clean

Nothing happens.  This works, however:

% python setup.py build -b ../builds clean
running build
running build_py
running build_ext
running config
gcc -E -I/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3 -o_configtest.i _configtest.c
removing: _configtest.c _configtest.i
running clean
removing '../builds/temp.darwin-6.8-Power_Macintosh-2.3' (and everything under it)

The logic to set build_temp from build_base (-b) is only present in
the build command, not in the clean command.  The code to set this
option runs from clean.set_undefined_options.  But it's clean's
build_base option which is set at the time, not build's, so it
propagates an empty path.

The test command class I found posted to this mailing list has a
workaround for the above problem, which looks like this:

    def finalize_options(self):
        build = self.distribution.get_command_obj('build')
        build_options = ('build_base', 'build_purelib', 'build_platlib')
        for option in build_options:
            setattr(build, option, getattr(self, option))
        for option in build_options:
            setattr(self, option, getattr(build, option))

and doesn't call self.set_undefined_options at all, though the last
three lines could be replaced by it.

There are several solutions I can think of:

- set_undefined_options should be changed to propagate set options to
  the source command object before calling src_cmd_obj.ensure_finalized.

- another method should be added to the cmd class, which does the above
  propagation then calls set_undefined_options.

- a workaround such as the one above should be placed in the
  distutils.command.clean.clean class.

Does this make sense?  Unless there's a huge compatibility issue, I'd
favor the first option, but my experience with distutils is limited.

=Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>

More information about the Distutils-SIG mailing list