Skip to content

Add support for wheel build tags #4299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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