summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-11-28 14:00:30 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-11-28 14:00:30 -0500
commitb4faffd44bab7b03b189c7923d37af80c1538de7 (patch)
treeb24912c4f963b0cd84c2ff247c0d5013589b3163 /pkg_resources
parent7f9936d9387d6322131e5e77145c51e12ee86379 (diff)
downloadpython-setuptools-bitbucket-b4faffd44bab7b03b189c7923d37af80c1538de7.tar.gz
Encapsulate egg-info special behavior in EggInfoDistribution class.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 3090dd81..631c8547 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2516,25 +2516,7 @@ class Distribution(object):
@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
+ pass
@property
def hashcmp(self):
@@ -2830,6 +2812,30 @@ class Distribution(object):
return [dep for dep in self._dep_map if dep]
+class EggInfoDistribution(Distribution):
+
+ @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.
+ """
+ if not os.path.isfile(dist_path):
+ return
+ try:
+ with open(dist_path) as strm:
+ return _version_from_file(strm)
+ except IOError:
+ pass
+
+
class DistInfoDistribution(Distribution):
"""Wrap an actual or potential sys.path entry w/metadata, .dist-info style"""
PKG_INFO = 'METADATA'
@@ -2895,7 +2901,7 @@ class DistInfoDistribution(Distribution):
_distributionImpl = {
'.egg': Distribution,
- '.egg-info': Distribution,
+ '.egg-info': EggInfoDistribution,
'.dist-info': DistInfoDistribution,
}