summaryrefslogtreecommitdiff
path: root/distutils2/command
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2010-11-13 01:29:47 +0100
committerTarek Ziade <tarek@ziade.org>2010-11-13 01:29:47 +0100
commit795e5bf4a7b8adbf356a021a1d5c2c293d221f6b (patch)
treec6ad3ecd157d8e8fc0ce777bb959581a49939c16 /distutils2/command
parent21b0542823fa265c5c09ecff2b1d21c5e85daaa9 (diff)
downloaddisutils2-795e5bf4a7b8adbf356a021a1d5c2c293d221f6b.tar.gz
now distutils2 uses set_command to set its own commands
Diffstat (limited to 'distutils2/command')
-rw-r--r--distutils2/command/__init__.py70
-rw-r--r--distutils2/command/cmd.py9
-rw-r--r--distutils2/command/sdist.py3
3 files changed, 55 insertions, 27 deletions
diff --git a/distutils2/command/__init__.py b/distutils2/command/__init__.py
index cb2fa3f..441f507 100644
--- a/distutils2/command/__init__.py
+++ b/distutils2/command/__init__.py
@@ -2,27 +2,53 @@
Package containing implementation of all the standard Distutils
commands."""
+from distutils2.errors import DistutilsModuleError
+from distutils2.util import resolve_name
+_COMMANDS = {
+ 'check': 'distutils2.command.check.check',
+ 'test': 'distutils2.command.test.test',
+ 'build': 'distutils2.command.build.build',
+ 'build_py': 'distutils2.command.build_py.build_py',
+ 'build_ext': 'distutils2.command.build_ext.build_ext',
+ 'build_clib': 'distutils2.command.build_clib.build_clib',
+ 'build_scripts': 'distutils2.command.build_scripts.build_scripts',
+ 'clean': 'distutils2.command.clean.clean',
+ 'install_dist': 'distutils2.command.install_dist.install_dist',
+ 'install_lib': 'distutils2.command.install_lib.install_lib',
+ 'install_headers': 'distutils2.command.install_headers.install_headers',
+ 'install_scripts': 'distutils2.command.install_scripts.install_scripts',
+ 'install_data': 'distutils2.command.install_data.install_data',
+ 'install_distinfo':
+ 'distutils2.command.install_distinfo.install_distinfo',
+ 'sdist': 'distutils2.command.sdist.sdist',
+ 'bdist': 'distutils2.command.bdist.bdist',
+ 'bdist_dumb': 'distutils2.command.bdist_dumb.bdist_dumb',
+ 'bdist_wininst': 'distutils2.command.bdist_wininst.bdist_wininst',
+ 'register': 'distutils2.command.register.register',
+ 'upload': 'distutils2.command.upload.upload',
+ 'upload_docs': 'distutils2.command.upload_docs.upload_docs'}
-__all__ = ['check',
- 'test',
- 'build',
- 'build_py',
- 'build_ext',
- 'build_clib',
- 'build_scripts',
- 'clean',
- 'install_dist',
- 'install_lib',
- 'install_headers',
- 'install_scripts',
- 'install_data',
- 'install_distinfo',
- 'sdist',
- 'bdist',
- 'bdist_dumb',
- 'bdist_wininst',
- 'register',
- 'upload',
- 'upload_docs'
- ]
+
+def get_command_names():
+ """Returns registered commands"""
+ return sorted(_COMMANDS.keys())
+
+
+def set_command(location):
+ klass = resolve_name(location)
+ # we want to do the duck-type checking here
+ # XXX
+ _COMMANDS[klass.get_command_name()] = klass
+
+
+def get_command_class(name):
+ """Return the registered command"""
+ try:
+ klass = _COMMANDS[name]
+ if isinstance(klass, str):
+ klass = resolve_name(klass)
+ _COMMANDS[name] = klass
+ return klass
+ except KeyError:
+ raise DistutilsModuleError("Invalid command %s" % name)
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
index bff9ac9..e2cfd52 100644
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -296,11 +296,12 @@ class Command(object):
# -- Convenience methods for commands ------------------------------
- def get_command_name(self):
- if hasattr(self, 'command_name'):
- return self.command_name
+ @classmethod
+ def get_command_name(cls):
+ if hasattr(cls, 'command_name'):
+ return cls.command_name
else:
- return self.__class__.__name__
+ return cls.__name__
def set_undefined_options(self, src_cmd, *options):
"""Set values of undefined options from another command.
diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
index ae1315a..0a83030 100644
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -15,6 +15,7 @@ try:
except ImportError:
from distutils2._backport.shutil import get_archive_formats
+from distutils2.command import get_command_names
from distutils2.command.cmd import Command
from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError,
DistutilsTemplateError, DistutilsModuleError)
@@ -250,7 +251,7 @@ class sdist(Command):
if files:
self.filelist.extend(files)
- for cmd_name in self.distribution.get_command_names():
+ for cmd_name in get_command_names():
try:
cmd_obj = self.get_finalized_command(cmd_name)
except DistutilsOptionError: