diff options
-rw-r--r-- | pkg_resources.py | 61 | ||||
-rwxr-xr-x | pkg_resources.txt | 32 |
2 files changed, 75 insertions, 18 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index dc0942a..efda22c 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -67,7 +67,7 @@ __all__ = [ 'ensure_directory', 'normalize_path', # Distribution "precedence" constants - 'EGG_DIST', 'BINARY_DIST', 'SOURCE_DIST', 'CHECKOUT_DIST', + 'EGG_DIST', 'BINARY_DIST', 'SOURCE_DIST', 'CHECKOUT_DIST', 'DEVELOP_DIST', # "Provider" interfaces, implementations, and registration/lookup APIs 'IMetadataProvider', 'IResourceProvider', 'FileMetadata', @@ -94,11 +94,11 @@ class UnknownExtra(ResolutionError): _provider_factories = {} PY_MAJOR = sys.version[:3] - EGG_DIST = 3 BINARY_DIST = 2 SOURCE_DIST = 1 CHECKOUT_DIST = 0 +DEVELOP_DIST = -1 def register_loader_type(loader_type, provider_factory): """Register `provider_factory` to make providers for `loader_type` @@ -1378,8 +1378,9 @@ def find_on_path(importer, path_item, only=False): metadata = PathMetadata(path_item, fullpath) else: metadata = FileMetadata(fullpath) - yield Distribution.from_location(path_item,entry,metadata) - + yield Distribution.from_location( + path_item,entry,metadata,precedence=DEVELOP_DIST + ) elif not only and lower.endswith('.egg'): for dist in find_distributions(os.path.join(path_item, entry)): yield dist @@ -1391,7 +1392,6 @@ def find_on_path(importer, path_item, only=False): register_finder(ImpWrapper,find_on_path) - _namespace_handlers = {} _namespace_packages = {} @@ -1736,7 +1736,7 @@ class Distribution(object): self._provider = metadata or empty_provider #@classmethod - def from_location(cls,location,basename,metadata=None): + def from_location(cls,location,basename,metadata=None,**kw): project_name, version, py_version, platform = [None]*4 basename, ext = os.path.splitext(basename) if ext.lower() in (".egg",".egg-info"): @@ -1747,7 +1747,7 @@ class Distribution(object): ) return cls( location, metadata, project_name=project_name, version=version, - py_version=py_version, platform=platform + py_version=py_version, platform=platform, **kw ) from_location = classmethod(from_location) @@ -1852,7 +1852,6 @@ class Distribution(object): if self.platform: filename += '-'+self.platform - return filename def __repr__(self): @@ -1874,9 +1873,10 @@ class Distribution(object): return getattr(self._provider, attr) #@classmethod - def from_filename(cls,filename,metadata=None): + def from_filename(cls,filename,metadata=None, **kw): return cls.from_location( - _normalize_cached(filename), os.path.basename(filename), metadata + _normalize_cached(filename), os.path.basename(filename), metadata, + **kw ) from_filename = classmethod(from_filename) @@ -1953,6 +1953,19 @@ class Distribution(object): return False return True + def clone(self,**kw): + """Copy this distribution, substituting in any changed keyword args""" + for attr in ( + 'project_name', 'version', 'py_version', 'platform', 'location', + 'precedence' + ): + kw.setdefault(attr, getattr(self,attr,None)) + kw.setdefault('metadata', self._provider) + return self.__class__(**kw) + + + + def issue_warning(*args,**kw): level = 1 g = globals() @@ -1966,6 +1979,34 @@ def issue_warning(*args,**kw): from warnings import warn warn(stacklevel = level+1, *args, **kw) + + + + + + + + + + + + + + + + + + + + + + + + + + + + def parse_requirements(strs): """Yield ``Requirement`` objects for each specification in `strs` diff --git a/pkg_resources.txt b/pkg_resources.txt index 851a3cf..6fd1af8 100755 --- a/pkg_resources.txt +++ b/pkg_resources.txt @@ -754,20 +754,23 @@ If it is None, an ``EmptyProvider`` is used instead. ``Distribution`` objects implement both the `IResourceProvider`_ and `IMetadataProvider Methods`_ by delegating them to the `metadata` object. -``Distribution.from_location(location, basename, metadata=None)`` (classmethod) +``Distribution.from_location(location, basename, metadata=None, **kw)`` (classmethod) Create a distribution for `location`, which must be a string such as a URL, filename, or other string that might be used on ``sys.path``. `basename` is a string naming the distribution, like ``Foo-1.2-py2.4.egg``. If `basename` ends with ``.egg``, then the project's name, version, python version and platform are extracted from the filename and used to set those - properties of the created distribution. + properties of the created distribution. Any additional keyword arguments + are forwarded to the ``Distribution()`` constructor. -``Distribution.from_filename(filename, metadata=None)`` (classmethod) +``Distribution.from_filename(filename, metadata=None**kw)`` (classmethod) Create a distribution by parsing a local filename. This is a shorter way of saying ``Distribution.from_location(normalize_path(filename), os.path.basename(filename), metadata)``. In other words, it creates a distribution whose location is the normalize form of the filename, parsing - name and version information from the base portion of the filename. + name and version information from the base portion of the filename. Any + additional keyword arguments are forwarded to the ``Distribution()`` + constructor. ``Distribution(location,metadata,project_name,version,py_version,platform,precedence)`` Create a distribution by setting its properties. All arguments are @@ -834,10 +837,12 @@ precedence ``parsed_version``. The default precedence is ``pkg_resources.EGG_DIST``, which is the highest (i.e. most preferred) precedence. The full list of predefined precedences, from most preferred to least preferred, is: - ``EGG_DIST``, ``BINARY_DIST``, ``SOURCE_DIST``, and ``CHECKOUT_DIST``. - Normally, precedences other than ``EGG_DIST`` are used only by the - ``setuptools.package_index`` module, when sorting distributions found in a - package index to determine their suitability for installation. + ``EGG_DIST``, ``BINARY_DIST``, ``SOURCE_DIST``, ``CHECKOUT_DIST``, and + ``DEVELOP_DIST``. Normally, precedences other than ``EGG_DIST`` are used + only by the ``setuptools.package_index`` module, when sorting distributions + found in a package index to determine their suitability for installation. + "System" and "Development" eggs (i.e., ones that use the ``.egg-info`` + format), however, are automatically given a precedence of ``DEVELOP_DIST``. @@ -871,6 +876,11 @@ precedence of "extras" defined by the distribution, and the list returned will then include any dependencies needed to support the named "extras". +``clone(**kw)`` + Create a copy of the distribution. Any supplied keyword arguments override + the corresponding argument to the ``Distribution()`` constructor, allowing + you to change some of the copied distribution's attributes. + ``egg_name()`` Return what this distribution's standard filename should be, not including the ".egg" extension. For example, a distribution for project "Foo" @@ -1524,6 +1534,12 @@ Release Notes/Change History versions for safe use in constructing egg filenames from a Distribution object's metadata. + * Added ``Distribution.clone()`` method, and keyword argument support to other + ``Distribution`` constructors. + + * Added the ``DEVELOP_DIST`` precedence, and automatically assign it to + eggs using ``.egg-info`` format. + 0.6a9 * Don't raise an error when an invalid (unfinished) distribution is found unless absolutely necessary. Warn about skipping invalid/unfinished eggs |