Skip to content

Commit 283cf2c

Browse files
sigmavirus24dstufft
authored andcommitted
Add support for wheel build tags (#4299)
1 parent c87ea28 commit 283cf2c

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

news/4299.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support build-numbers in wheel versions and support sorting with build-numbers.

pip/index.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def _candidate_sort_key(self, candidate):
278278
with the same version, would have to be considered equal
279279
"""
280280
support_num = len(self.valid_tags)
281+
build_tag = tuple()
281282
if candidate.location.is_wheel:
282283
# can raise InvalidWheelFilename
283284
wheel = Wheel(candidate.location.filename)
@@ -287,9 +288,13 @@ def _candidate_sort_key(self, candidate):
287288
"can't be sorted." % wheel.filename
288289
)
289290
pri = -(wheel.support_index_min(self.valid_tags))
291+
if wheel.build_tag is not None:
292+
match = re.match('^(\d+)(.*)$', wheel.build_tag)
293+
build_tag_groups = match.groups()
294+
build_tag = (int(build_tag_groups[0]), build_tag_groups[1])
290295
else: # sdist
291296
pri = -(support_num)
292-
return (candidate.version, pri)
297+
return (candidate.version, build_tag, pri)
293298

294299
def _validate_secure_origin(self, logger, location):
295300
# Determine if this url used a secure transport mechanism

pip/wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class Wheel(object):
482482

483483
wheel_file_re = re.compile(
484484
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
485-
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
485+
((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
486486
\.whl|\.dist-info)$""",
487487
re.VERBOSE
488488
)
@@ -501,6 +501,7 @@ def __init__(self, filename):
501501
# we'll assume "_" means "-" due to wheel naming scheme
502502
# (https://github.com/pypa/pip/issues/1150)
503503
self.version = wheel_info.group('ver').replace('_', '-')
504+
self.build_tag = wheel_info.group('build')
504505
self.pyversions = wheel_info.group('pyver').split('.')
505506
self.abis = wheel_info.group('abi').split('.')
506507
self.plats = wheel_info.group('plat').split('.')
Binary file not shown.

tests/unit/test_finder.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ def test_link_sorting(self):
251251

252252
assert links == results == results2, results2
253253

254+
def test_link_sorting_wheels_with_build_tags(self):
255+
"""Verify build tags affect sorting."""
256+
links = [
257+
InstallationCandidate(
258+
"simplewheel",
259+
"2.0",
260+
Link("simplewheel-2.0-1-py2.py3-none-any.whl"),
261+
),
262+
InstallationCandidate(
263+
"simplewheel",
264+
"2.0",
265+
Link("simplewheel-2.0-py2.py3-none-any.whl"),
266+
),
267+
InstallationCandidate(
268+
"simplewheel",
269+
"1.0",
270+
Link("simplewheel-1.0-py2.py3-none-any.whl"),
271+
),
272+
]
273+
finder = PackageFinder([], [], session=PipSession())
274+
results = sorted(links, key=finder._candidate_sort_key, reverse=True)
275+
results2 = sorted(reversed(links), key=finder._candidate_sort_key,
276+
reverse=True)
277+
assert links == results == results2, results2
278+
254279

255280
def test_finder_priority_file_over_page(data):
256281
"""Test PackageFinder prefers file links over equivalent page links"""

0 commit comments

Comments
 (0)