Problem adding a new setup command..
Hi there, I'm a new setuptools user. I think setuptools is very good, and I'm currently using it for a personal project. [1] However, I'm experimenting a small issue when trying to use a new setup command like so: $ python setup.py install_media Distribution.parse_config_files(): reading setup.cfg options (after parsing config files): option dict for 'egg_info' command: {'tag_build': ('setup.cfg', 'p1'), 'tag_svn_revision': ('setup.cfg', '0')} options (after parsing command line): option dict for 'aliases' command: {} option dict for 'egg_info' command: {'tag_build': ('setup.cfg', 'p1'), 'tag_svn_revision': ('setup.cfg', '0')} option dict for 'install_media' command: {'args': ('command line', [])} running install_media Distribution.get_command_obj(): creating 'install_media' command object setting options for 'install_media' command: args = [] (from command line) Traceback (most recent call last): File "setup.py", line 143, in <module> zip_safe=(sys.version >= 2.5) File "/opt/python25/lib/python2.5/distutils/core.py", line 151, in setup dist.run_commands() File "/opt/python25/lib/python2.5/distutils/dist.py", line 974, in run_commands self.run_command(cmd) File "/opt/python25/lib/python2.5/distutils/dist.py", line 992, in run_command cmd_obj = self.get_command_obj(command) File "/opt/python25/lib/python2.5/distutils/dist.py", line 879, in get_command_obj self._set_command_options(cmd_obj, options) File "/opt/python25/lib/python2.5/distutils/dist.py", line 919, in _set_command_options % (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 # 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 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 Thanks in advance, Etienne 1. http://tools.assembla.com/notmm/ ---- Etienne Robillard 7680 de jouvence, La Plaine J7M-2K9, Québec Telephone: 450-478-5026 Yahoo Messenger ID: granted14 Skype ID: incidah Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
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.
participants (2)
-
Etienne Robillard
-
Phillip J. Eby