diff options
author | PJ Eby <distutils-sig@python.org> | 2005-07-17 19:01:15 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-07-17 19:01:15 +0000 |
commit | 63d507adccf8207a40e2b22a8c11f79efb83f56a (patch) | |
tree | 079ea1f80004c18837a93f3bdc66b039d8d5127a | |
parent | 30f1c5ad93e21ec007d371313e2a27e4d0efb661 (diff) | |
download | external_python_setuptools-63d507adccf8207a40e2b22a8c11f79efb83f56a.tar.gz external_python_setuptools-63d507adccf8207a40e2b22a8c11f79efb83f56a.tar.bz2 external_python_setuptools-63d507adccf8207a40e2b22a8c11f79efb83f56a.zip |
``Distribution`` objects now implement the ``IResourceProvider`` and
``IMetadataProvider`` interfaces, so you don't need to reference the (no
longer available) ``metadata`` attribute to get at these interfaces.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041133
-rw-r--r-- | pkg_resources.py | 38 | ||||
-rwxr-xr-x | setuptools.txt | 10 | ||||
-rwxr-xr-x | setuptools/command/easy_install.py | 12 | ||||
-rw-r--r-- | setuptools/tests/test_resources.py | 2 |
4 files changed, 36 insertions, 26 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 81c6314d..8eabdd25 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -23,7 +23,7 @@ __all__ = [ 'get_importer', 'find_distributions', 'find_on_path', 'register_finder', 'split_sections', 'declare_namespace', 'register_namespace_handler', 'safe_name', 'safe_version', 'run_main', 'BINARY_DIST', 'run_script', - 'get_default_cache', + 'get_default_cache', 'EmptyProvider', 'empty_provider', ] import sys, os, zipimport, time, re, imp @@ -108,7 +108,7 @@ def run_script(dist_spec, script_name): name = ns['__name__'] ns.clear() ns['__name__'] = name - require(dist_spec)[0].metadata.run_script(script_name, ns) + require(dist_spec)[0].run_script(script_name, ns) run_main = run_script # backward compatibility @@ -714,18 +714,18 @@ class DefaultProvider(NullProvider): register_loader_type(type(None), DefaultProvider) +class EmptyProvider(NullProvider): + """Provider that returns nothing for all requests""" + _isdir = _has = lambda self,path: False + _get = lambda self,path: '' + _listdir = lambda self,path: [] + module_path = None + def __init__(self): + pass - - - - - - - - - +empty_provider = EmptyProvider() @@ -1325,7 +1325,7 @@ class Distribution(object): self.platform = platform self.path = path_str self.distro_type = distro_type - self.metadata = metadata + self._provider = metadata or empty_provider def installed_on(self,path=None): """Is this distro installed on `path`? (defaults to ``sys.path``)""" @@ -1419,8 +1419,8 @@ class Distribution(object): return deps def _get_metadata(self,name): - if self.metadata is not None and self.metadata.has_metadata(name): - for line in self.metadata.get_metadata_lines(name): + if self.has_metadata(name): + for line in self.get_metadata_lines(name): yield line def install_on(self,path=None): @@ -1452,11 +1452,11 @@ class Distribution(object): version = getattr(self,'version',None) or "[unknown version]" return "%s %s" % (self.project_name,version) - - - - - + def __getattr__(self,attr): + """Delegate all unrecognized public attributes to .metadata provider""" + if attr.startswith('_'): + raise AttributeError,attr + return getattr(self._provider, attr) diff --git a/setuptools.txt b/setuptools.txt index 8a1edcf7..01e8994e 100755 --- a/setuptools.txt +++ b/setuptools.txt @@ -1342,6 +1342,16 @@ Release Notes/Change History * Fixed ``pkg_resources.resource_exists()`` not working correctly. + * Many ``pkg_resources`` API changes: + + * ``Distribution`` objects now implement the ``IResourceProvider`` and + ``IMetadataProvider`` interfaces, so you don't need to reference the (no + longer available) ``metadata`` attribute to get at these interfaces. + + * ``Distribution`` and ``Requirement`` both have a ``project_name`` + attribute for the project name they refer to. (Previously these were + ``name`` and ``distname`` attributes.) + 0.5a13 * Fixed a bug in resource extraction from nested packages in a zipped egg. diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 6d61c951..b096a48e 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -368,22 +368,21 @@ class easy_install(Command): ) def install_egg_scripts(self, dist): - metadata = dist.metadata - if self.exclude_scripts or not metadata.metadata_isdir('scripts'): + if self.exclude_scripts or not dist.metadata_isdir('scripts'): return - for script_name in metadata.metadata_listdir('scripts'): + for script_name in dist.metadata_listdir('scripts'): self.install_script( dist, script_name, - metadata.get_metadata('scripts/'+script_name).replace('\r','\n') + dist.get_metadata('scripts/'+script_name).replace('\r','\n') ) def should_unzip(self, dist): if self.zip_ok is not None: return not self.zip_ok - if dist.metadata.has_metadata('not-zip-safe'): + if dist.has_metadata('not-zip-safe'): return True - if not dist.metadata.has_metadata('zip-safe'): + if not dist.has_metadata('zip-safe'): return True return False @@ -408,6 +407,7 @@ class easy_install(Command): + def install_script(self, dist, script_name, script_text, dev_path=None): log.info("Installing %s script to %s", script_name,self.script_dir) target = os.path.join(self.script_dir, script_name) diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py index 10786144..0a4cb183 100644 --- a/setuptools/tests/test_resources.py +++ b/setuptools/tests/test_resources.py @@ -3,7 +3,7 @@ from pkg_resources import * import pkg_resources, sys from sets import ImmutableSet -class Metadata: +class Metadata(EmptyProvider): """Mock object to return metadata as if from an on-disk distribution""" def __init__(self,*pairs): |