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 /setuptools/command/alias.py | |
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
Diffstat (limited to 'setuptools/command/alias.py')
-rwxr-xr-x | setuptools/command/alias.py | 39 |
1 files changed, 39 insertions, 0 deletions
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 + ) + |