[Distutils] Problem adding a new setup command..

Phillip J. Eby pje at telecommunity.com
Thu Sep 27 18:16:18 CEST 2007


At 05:09 PM 9/11/2007 -0400, Etienne Robillard wrote:
>     % (source, command_name, option))
>distutils.errors.DistutilsOptionError: error in
>command line: command 'install_media' has no such
>option 'a     rgs'
>
>Here's the setuptools.Command subclass:
>
>from setuptools import Command
>class install_media(Command):
>     description = "Install app-specific media files"
>     command_consumes_arguments = True

You only set 'command_consumes_arguments' if it accepts *non-option* 
arguments, in which case your instances must have an 'args' attribute 
initialized in initialize_options.


>     # List of options for this command
>     user_options = [
>         # Perhaps the better option is to use the
>'--prefix' arg.
>         # ('with-docroot=', None, 'Install media files
>to this directory'),
>         ('with-apps=', None,
>          "Search theses subdirs for media files
>(comma-separated list)")
>     ]
>     def initialize_options(self):
>         pass
>     def finalize_options(self):
>         pass

These two methods are broken: initialize_options must set the 
instance's with_docroot and with_apps attributes to None, since those 
are options.  The finalize_options method must set these attributes 
to default values if they are still None.

These requirements come from the distutils, and I believe they are 
documented as such.

(Please note that initializing the attributes to None *anywhere* 
other than initialize_options is NOT sufficient to create a correct 
distutils command class, because then it is impossible to 
"reinitialize" a command instance, which the distutils sometimes needs to do.)


>     def run(self):
>         return self._find_media_files()
>     def _find_media_files(self):
>         pass
>
>
>Any insightful hints how to debug this problem?
>The Big Idea was to add a new setup command (named
>install_media) which could presumely allow things
>like:
>
>  $ python setup.py install_media --prefix=/var/www
>--with-apps=foo,bar

Note that you're only taking *options* here, not arguments.  So you 
don't need or want the command_consumes_arguments flag set.



More information about the Distutils-SIG mailing list