Skip to content

Commit 032192a

Browse files
committed
WIP: Add support for wheel build tags
At the moment, pip doesn't support ordering candidate installations while considering build tags. This is meant to start adding that support. According to the PEP, the first contiguous set of integers in the build tag should be sorted numerically. After that, they should be sorted alphabetically.
1 parent 5b7060a commit 032192a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pip/index.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def _candidate_sort_key(self, candidate):
266266
with the same version, would have to be considered equal
267267
"""
268268
support_num = len(self.valid_tags)
269+
build_tag = tuple()
269270
if candidate.location.is_wheel:
270271
# can raise InvalidWheelFilename
271272
wheel = Wheel(candidate.location.filename)
@@ -275,9 +276,13 @@ def _candidate_sort_key(self, candidate):
275276
"can't be sorted." % wheel.filename
276277
)
277278
pri = -(wheel.support_index_min(self.valid_tags))
279+
if wheel.build_tag is not None:
280+
match = re.match('^(\d+)(.*)$', wheel.build_tag)
281+
build_tag_groups = match.groups()
282+
build_tag = (int(build_tag_groups[0]), build_tag_groups[1])
278283
else: # sdist
279284
pri = -(support_num)
280-
return (candidate.version, pri)
285+
return (candidate.version, build_tag, pri)
281286

282287
def _validate_secure_origin(self, logger, location):
283288
# 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
@@ -583,7 +583,7 @@ class Wheel(object):
583583

584584
wheel_file_re = re.compile(
585585
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
586-
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
586+
((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
587587
\.whl|\.dist-info)$""",
588588
re.VERBOSE
589589
)
@@ -602,6 +602,7 @@ def __init__(self, filename):
602602
# we'll assume "_" means "-" due to wheel naming scheme
603603
# (https://github.com/pypa/pip/issues/1150)
604604
self.version = wheel_info.group('ver').replace('_', '-')
605+
self.build_tag = wheel_info.group('build')
605606
self.pyversions = wheel_info.group('pyver').split('.')
606607
self.abis = wheel_info.group('abi').split('.')
607608
self.plats = wheel_info.group('plat').split('.')

0 commit comments

Comments
 (0)