summaryrefslogtreecommitdiff
path: root/pkg_resources.py
diff options
context:
space:
mode:
authorphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2006-02-07 16:40:55 +0000
committerphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2006-02-07 16:40:55 +0000
commited6d3f01eb9411100255d63284a718967be3ee8c (patch)
tree9e257995b44808264550b26fed365b0c23a94cab /pkg_resources.py
parent18e94365ef7f5f0f2e4611fcb0f4037f657cdcb6 (diff)
downloadpython-setuptools-ed6d3f01eb9411100255d63284a718967be3ee8c.tar.gz
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. git-svn-id: http://svn.python.org/projects/sandbox/trunk/setuptools@42259 6015fed2-1504-0410-9fe1-9d1591cc4771
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py61
1 files changed, 51 insertions, 10 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`