diff options
author | PJ Eby <distutils-sig@python.org> | 2005-07-24 22:47:06 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-07-24 22:47:06 +0000 |
commit | 1c40632b88d76aea178e751483645ec3d32c81d9 (patch) | |
tree | 2cc3fa1af58200d5199b30771053c527ef91bd93 /setuptools/dist.py | |
parent | 8618cfa8ac93431ffcede4f3987b559449bbbcb8 (diff) | |
download | external_python_setuptools-1c40632b88d76aea178e751483645ec3d32c81d9.tar.gz external_python_setuptools-1c40632b88d76aea178e751483645ec3d32c81d9.tar.bz2 external_python_setuptools-1c40632b88d76aea178e751483645ec3d32c81d9.zip |
Implement "entry points" for dynamic discovery of drivers and plugins.
Change setuptools to discover setup commands using an entry point group
called "distutils.commands". Thanks to Ian Bicking for the suggestion that
led to designing this super-cool feature.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041152
Diffstat (limited to 'setuptools/dist.py')
-rw-r--r-- | setuptools/dist.py | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 3c7ff852..a603ade0 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -11,6 +11,32 @@ from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsSetupError import setuptools, pkg_resources +def get_command_class(self, command): + """Pluggable version of get_command_class()""" + if command in self.cmdclass: + return self.cmdclass[command] + + for dist in pkg_resources.working_set: + if dist.get_entry_info('distutils.commands',command): + cmdclass = dist.load_entry_point('distutils.commands',command) + self.cmdclass[command] = cmdclass + return cmdclass + else: + return _old_get_command_class(self, command) + +def print_commands(self): + for dist in pkg_resources.working_set: + for cmd,ep in dist.get_entry_map('distutils.commands').items(): + if cmd not in self.cmdclass: + cmdclass = ep.load() # don't require extras, we're not running + self.cmdclass[cmd] = cmdclass + return _old_print_commands(self) + +for meth in 'print_commands', 'get_command_class': + if getattr(_Distribution,meth).im_func.func_globals is not globals(): + globals()['_old_'+meth] = getattr(_Distribution,meth) + setattr(_Distribution, meth, globals()[meth]) + sequence = tuple, list class Distribution(_Distribution): @@ -80,6 +106,21 @@ class Distribution(_Distribution): distribution for the included and excluded features. """ + + + + + + + + + + + + + + + def __init__ (self, attrs=None): have_package_data = hasattr(self, "package_data") if not have_package_data: @@ -93,15 +134,9 @@ class Distribution(_Distribution): self.zip_safe = None self.namespace_packages = None self.eager_resources = None + self.entry_points = None _Distribution.__init__(self,attrs) - if not have_package_data: - from setuptools.command.build_py import build_py - self.cmdclass.setdefault('build_py',build_py) - self.cmdclass.setdefault('build_ext',build_ext) - self.cmdclass.setdefault('install',install) - self.cmdclass.setdefault('install_lib',install_lib) - self.cmdclass.setdefault('sdist',sdist) def parse_command_line(self): """Process features after parsing command line options""" @@ -121,6 +156,12 @@ class Distribution(_Distribution): + + + + + + def finalize_options(self): _Distribution.finalize_options(self) @@ -171,6 +212,12 @@ class Distribution(_Distribution): "namespace package %r" % nsp ) + if self.entry_points is not None: + try: + pkg_resources.EntryPoint.parse_map(self.entry_points) + except ValueError, e: + raise DistutilsSetupError(e) + def _set_global_opts_from_features(self): """Add --with-X/--without-X options based on optional features""" @@ -197,12 +244,6 @@ class Distribution(_Distribution): - - - - - - def _finalize_features(self): """Add/remove features and resolve dependencies between them""" @@ -420,7 +461,7 @@ class Distribution(_Distribution): src,alias = aliases[command] del aliases[command] # ensure each alias can expand only once! import shlex - args[:1] = shlex.split(alias,True) + args[:1] = shlex.split(alias,True) command = args[0] nargs = _Distribution._parse_command_opts(self, parser, args) |