Skip to content

Commit

Permalink
Fix old pkg_resources egg version normalization.
Browse files Browse the repository at this point in the history
Before recent releases of setuptools, the version numbers in eggs were mangled. `safe_version` handles this correctly in modern `setuptools` and should work on older setuptools as well.

Closes pex-tool#226.
  • Loading branch information
mikekap committed Apr 7, 2016
1 parent cfcfe70 commit 354f943
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pex/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os

from pkg_resources import EGG_NAME, parse_version, safe_name
from pkg_resources import EGG_NAME, parse_version, safe_name, safe_version

from .archiver import Archiver
from .base import maybe_requirement
Expand Down Expand Up @@ -133,7 +133,7 @@ def name(self):

@property
def raw_version(self):
return self._raw_version
return safe_version(self._raw_version)

# SourcePackages are always compatible as they can be translated to a distribution.
def compatible(self, identity, platform=Platform.current()):
Expand Down Expand Up @@ -167,7 +167,7 @@ def name(self):

@property
def raw_version(self):
return self._raw_version
return safe_version(self._raw_version)

@property
def py_version(self):
Expand Down
12 changes: 11 additions & 1 deletion tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_local_specifier():
assert sl.satisfies('a_p_r==3.1.3+pexed.1')



def test_egg_packages():
el = EggPackage('psutil-0.4.1-py2.6-macosx-10.7-intel.egg')
assert el.name == 'psutil'
Expand All @@ -44,9 +45,18 @@ def test_egg_packages():
for req in ('foo', 'bar==0.4.1'):
assert not el.satisfies(req)

# Legacy pkg_resources normalized version numbers.
el = EggPackage('pyfoo-1.0.0_bar-py2.7-linux-x86_64.egg')
assert el.name == 'pyfoo'
assert el.raw_version == '1.0.0-bar'
assert el.py_version == '2.7'
assert el.platform == 'linux-x86_64'
for req in ('pyfoo', 'pyfoo==1.0.0-bar'):
assert el.satisfies(req)

el = EggPackage('pytz-2012b-py2.6.egg')
assert el.name == 'pytz'
assert el.raw_version == '2012b'
assert el.raw_version == '2012b0'
assert el.py_version == '2.6'
assert el.platform is None

Expand Down

0 comments on commit 354f943

Please sign in to comment.