Skip to content

Commit

Permalink
Add support for wheel build tags (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmavirus24 authored and dstufft committed Aug 31, 2017
1 parent c87ea28 commit 283cf2c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/4299.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support build-numbers in wheel versions and support sorting with build-numbers.
7 changes: 6 additions & 1 deletion pip/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def _candidate_sort_key(self, candidate):
with the same version, would have to be considered equal
"""
support_num = len(self.valid_tags)
build_tag = tuple()
if candidate.location.is_wheel:
# can raise InvalidWheelFilename
wheel = Wheel(candidate.location.filename)
Expand All @@ -287,9 +288,13 @@ def _candidate_sort_key(self, candidate):
"can't be sorted." % wheel.filename
)
pri = -(wheel.support_index_min(self.valid_tags))
if wheel.build_tag is not None:
match = re.match('^(\d+)(.*)$', wheel.build_tag)
build_tag_groups = match.groups()
build_tag = (int(build_tag_groups[0]), build_tag_groups[1])
else: # sdist
pri = -(support_num)
return (candidate.version, pri)
return (candidate.version, build_tag, pri)

def _validate_secure_origin(self, logger, location):
# Determine if this url used a secure transport mechanism
Expand Down
3 changes: 2 additions & 1 deletion pip/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class Wheel(object):

wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.whl|\.dist-info)$""",
re.VERBOSE
)
Expand All @@ -501,6 +501,7 @@ def __init__(self, filename):
# we'll assume "_" means "-" due to wheel naming scheme
# (https://github.com/pypa/pip/issues/1150)
self.version = wheel_info.group('ver').replace('_', '-')
self.build_tag = wheel_info.group('build')
self.pyversions = wheel_info.group('pyver').split('.')
self.abis = wheel_info.group('abi').split('.')
self.plats = wheel_info.group('plat').split('.')
Expand Down
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,31 @@ def test_link_sorting(self):

assert links == results == results2, results2

def test_link_sorting_wheels_with_build_tags(self):
"""Verify build tags affect sorting."""
links = [
InstallationCandidate(
"simplewheel",
"2.0",
Link("simplewheel-2.0-1-py2.py3-none-any.whl"),
),
InstallationCandidate(
"simplewheel",
"2.0",
Link("simplewheel-2.0-py2.py3-none-any.whl"),
),
InstallationCandidate(
"simplewheel",
"1.0",
Link("simplewheel-1.0-py2.py3-none-any.whl"),
),
]
finder = PackageFinder([], [], session=PipSession())
results = sorted(links, key=finder._candidate_sort_key, reverse=True)
results2 = sorted(reversed(links), key=finder._candidate_sort_key,
reverse=True)
assert links == results == results2, results2


def test_finder_priority_file_over_page(data):
"""Test PackageFinder prefers file links over equivalent page links"""
Expand Down

0 comments on commit 283cf2c

Please sign in to comment.