diff options
author | PJ Eby <distutils-sig@python.org> | 2005-07-08 05:09:23 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-07-08 05:09:23 +0000 |
commit | 6050f5361738831a12debd373b9016a077e930df (patch) | |
tree | 25e82b1ab87651a118c178191776e19575dd4bab | |
parent | 592269afeaa4f96bddbaa8b6fbe8dddcea2445a4 (diff) | |
download | external_python_setuptools-6050f5361738831a12debd373b9016a077e930df.tar.gz external_python_setuptools-6050f5361738831a12debd373b9016a077e930df.tar.bz2 external_python_setuptools-6050f5361738831a12debd373b9016a077e930df.zip |
Added support for defining command aliases in distutils configuration
files, under the "[aliases]" section. To prevent recursion and to allow
aliases to call the command of the same name, a given alias can be expanded
only once per command-line invocation. You can define new aliases with the
"alias" command, either for the local, global, or per-user configuration.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041094
-rwxr-xr-x | EasyInstall.txt | 8 | ||||
-rw-r--r-- | setuptools/command/__init__.py | 4 | ||||
-rwxr-xr-x | setuptools/command/alias.py | 39 | ||||
-rwxr-xr-x | setuptools/command/saveopts.py | 12 | ||||
-rwxr-xr-x | setuptools/command/sdist.py | 2 | ||||
-rwxr-xr-x | setuptools/command/setopt.py | 10 | ||||
-rw-r--r-- | setuptools/dist.py | 43 |
7 files changed, 102 insertions, 16 deletions
diff --git a/EasyInstall.txt b/EasyInstall.txt index dccdf957..db128f8b 100755 --- a/EasyInstall.txt +++ b/EasyInstall.txt @@ -495,7 +495,13 @@ Known Issues name or version). Also, this means that if you use the various ``--tag`` options of "egg_info", any distributions generated will use the tags in the version, not just egg distributions. - + + * Added support for defining command aliases in distutils configuration files, + under the "[aliases]" section. To prevent recursion and to allow aliases to + call the command of the same name, a given alias can be expanded only once + per command-line invocation. You can define new aliases with the "alias" + command, either for the local, global, or per-user configuration. + * Added "rotate" command to delete old distribution files, given a set of patterns to match and the number of files to keep. (Keeps the most recently-modified distribution files matching each pattern.) diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py index 0606ef9c..29f3000d 100644 --- a/setuptools/command/__init__.py +++ b/setuptools/command/__init__.py @@ -1,6 +1,8 @@ import distutils.command -__all__ = ['test', 'develop', 'bdist_egg', 'saveopts', 'setopt', 'rotate'] +__all__ = [ + 'test', 'develop', 'bdist_egg', 'saveopts', 'setopt', 'rotate', 'alias' +] # Make our commands available as though they were part of the distutils diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py new file mode 100755 index 00000000..42d6b2fc --- /dev/null +++ b/setuptools/command/alias.py @@ -0,0 +1,39 @@ +import distutils, os +from setuptools import Command +from distutils.util import convert_path +from distutils import log +from distutils.errors import * +from setuptools.command.setopt import edit_config, option_base + +class alias(option_base): + """Abstract base class for commands that mess with config files""" + + description = "set an option in setup.cfg or another config file" + + user_options = [ + ('alias=', 'a', 'the name of the new pseudo-command'), + ('command=', 'c', 'command(s) and options to invoke when used'), + ('remove', 'r', 'remove (unset) the alias'), + ] + option_base.user_options + + boolean_options = option_base.boolean_options + ['remove'] + + def initialize_options(self): + option_base.initialize_options(self) + self.alias = None + self.command = None + self.remove = None + + def finalize_options(self): + option_base.finalize_options(self) + if self.alias is None: + raise DistutilsOptionError("Must specify name (--alias/-a)") + if self.command is None and not self.remove: + raise DistutilsOptionError("Must specify --command or --remove") + + def run(self): + edit_config( + self.filename, {'aliases': {self.alias:self.command}}, + self.dry_run + ) + diff --git a/setuptools/command/saveopts.py b/setuptools/command/saveopts.py index ad3cf193..1180a440 100755 --- a/setuptools/command/saveopts.py +++ b/setuptools/command/saveopts.py @@ -7,21 +7,19 @@ class saveopts(option_base): description = "save supplied options to setup.cfg or other config file" - user_options = option_base.user_options + [ - ] - - boolean_options = option_base.boolean_options + [ - ] - def run(self): dist = self.distribution commands = dist.command_options.keys() settings = {} + for cmd in commands: + if cmd=='saveopts': - continue + continue # don't save our own options! + for opt,(src,val) in dist.get_option_dict(cmd).items(): if src=="command line": settings.setdefault(cmd,{})[opt] = val + edit_config(self.filename, settings, self.dry_run) diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 3891526d..673255bb 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -84,6 +84,7 @@ class sdist(_sdist): """Smart sdist that finds anything supported by revision control""" def run(self): + self.run_command('egg_info') _sdist.run(self) dist_files = getattr(self.distribution,'dist_files',[]) for file in self.archive_files: @@ -120,4 +121,3 @@ class sdist(_sdist): - diff --git a/setuptools/command/setopt.py b/setuptools/command/setopt.py index b5d9d307..3af0753f 100755 --- a/setuptools/command/setopt.py +++ b/setuptools/command/setopt.py @@ -84,12 +84,12 @@ class option_base(Command): """Abstract base class for commands that mess with config files""" user_options = [ - ('filename=', 'f', - "set the file to use (default=setup.cfg)"), ('global-config', 'g', "save options to the site-wide distutils.cfg file"), ('user-config', 'u', "save options to the current user's pydistutils.cfg file"), + ('filename=', 'f', + "configuration file to use (default=setup.cfg)"), ] boolean_options = [ @@ -126,12 +126,12 @@ class setopt(option_base): description = "set an option in setup.cfg or another config file" - user_options = option_base.user_options + [ + user_options = [ ('command=', 'c', 'command to set an option for'), ('option=', 'o', 'option to set'), ('set-value=', 's', 'value of the option'), - ('remove', 'r', 'unset the value'), - ] + ('remove', 'r', 'remove (unset) the value'), + ] + option_base.user_options boolean_options = option_base.boolean_options + ['remove'] diff --git a/setuptools/dist.py b/setuptools/dist.py index fc0f3eba..8fcd19ea 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -372,10 +372,19 @@ class Distribution(_Distribution): self.global_options = self.__class__.global_options self.negative_opt = self.__class__.negative_opt - # Handle commands that want to consume all remaining arguments + # First, expand any aliases command = args[0] + aliases = self.get_option_dict('aliases') + while command in aliases: + src,alias = aliases[command] + del aliases[command] # ensure each alias can expand only once! + import shlex + args[:1] = shlex.split(alias,True) + command = args[0] + nargs = _Distribution._parse_command_opts(self, parser, args) + # Handle commands that want to consume all remaining arguments cmd_class = self.get_command_class(command) if getattr(cmd_class,'command_consumes_arguments',None): self.get_option_dict(command)['args'] = ("command line", nargs) @@ -384,6 +393,21 @@ class Distribution(_Distribution): return nargs + + + + + + + + + + + + + + + def has_dependencies(self): return not not self.requires @@ -408,6 +432,23 @@ class Distribution(_Distribution): self.have_run['install'] = 1 setuptools.bootstrap_install_from = None + + + + + + + + + + + + + + + + + def get_cmdline_options(self): """Return a '{cmd: {opt:val}}' map of all command-line options |