summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-11-28 13:46:53 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-11-28 13:46:53 -0500
commit7f9936d9387d6322131e5e77145c51e12ee86379 (patch)
tree128b9be5ac85f3c652e9e8289f7b483dbf759a0f /pkg_resources
parentb062cf374956302edf12fa2ac4407af90b06bc19 (diff)
downloadpython-setuptools-bitbucket-7f9936d9387d6322131e5e77145c51e12ee86379.tar.gz
Extract method for _version_from_egg_info.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index e4decac3..3090dd81 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2497,6 +2497,7 @@ class Distribution(object):
@classmethod
def from_location(cls, location, basename, metadata=None, **kw):
project_name, version, py_version, platform = [None]*4
+ dist_path = os.path.join(location, basename)
basename, ext = os.path.splitext(basename)
if ext.lower() in _distributionImpl:
# .dist-info gets much metadata differently
@@ -2507,26 +2508,34 @@ class Distribution(object):
)
cls = _distributionImpl[ext.lower()]
- # Some packages e.g. numpy and scipy use distutils instead of
- # setuptools, and their version numbers can get mangled when
- # converted to filenames (e.g., 1.11.0.dev0+2329eae to
- # 1.11.0.dev0_2329eae). These will not be parsed properly
- # downstream by Distribution and safe_version, so we need to
- # take an extra step and try to get the version number from
- # the file itself instead of the filename.
- if ext == '.egg-info':
- full_name = os.path.join(location, basename + ext)
- try:
- with open(full_name, 'r') as fid:
- version_ = _version_from_file(fid)
- version = version_ if version_ is not None else version
- except IOError:
- pass
+ version = cls._version_from_egg_info(dist_path) or version
return cls(
location, metadata, project_name=project_name, version=version,
py_version=py_version, platform=platform, **kw
)
+ @staticmethod
+ def _version_from_egg_info(dist_path):
+ """
+ Packages installed by distutils (e.g. numpy or scipy),
+ which uses an old safe_version, and so
+ their version numbers can get mangled when
+ converted to filenames (e.g., 1.11.0.dev0+2329eae to
+ 1.11.0.dev0_2329eae). These distributions will not be
+ parsed properly
+ downstream by Distribution and safe_version, so
+ take an extra step and try to get the version number from
+ the metadata file itself instead of the filename.
+ """
+ _, ext = os.path.splitext(dist_path)
+ if ext != '.egg-info' or not os.path.isfile(dist_path):
+ return
+ try:
+ with open(dist_path) as strm:
+ return _version_from_file(strm)
+ except IOError:
+ pass
+
@property
def hashcmp(self):
return (