From f6b56e5e9b3b42e324c541043ecb5428f4489246 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 22 Feb 2017 06:48:23 -0600 Subject: [PATCH 1/2] 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. --- pip/index.py | 7 ++++- pip/wheel.py | 3 ++- .../simplewheel-2.0-1-py2.py3-none-any.whl | Bin 0 -> 1754 bytes tests/unit/test_finder.py | 25 ++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/data/packages/simplewheel-2.0-1-py2.py3-none-any.whl diff --git a/pip/index.py b/pip/index.py index 5808b921a88..46f97e8e39a 100644 --- a/pip/index.py +++ b/pip/index.py @@ -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) @@ -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 diff --git a/pip/wheel.py b/pip/wheel.py index 31cceed19ef..3727522cd43 100644 --- a/pip/wheel.py +++ b/pip/wheel.py @@ -482,7 +482,7 @@ class Wheel(object): wheel_file_re = re.compile( r"""^(?P(?P.+?)-(?P.*?)) - ((-(?P\d.*?))?-(?P.+?)-(?P.+?)-(?P.+?) + ((-(?P\d[^-]*?))?-(?P.+?)-(?P.+?)-(?P.+?) \.whl|\.dist-info)$""", re.VERBOSE ) @@ -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('.') diff --git a/tests/data/packages/simplewheel-2.0-1-py2.py3-none-any.whl b/tests/data/packages/simplewheel-2.0-1-py2.py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..acf0c56cfd9a7258f4aa0ff3fec937ee26447f91 GIT binary patch literal 1754 zcmWIWW@Zs#U|`^2(62IZY-nN);{@{9fmjHLi!*Zza#Ho<<1_OzOXB183MzyBG|!%0 z`-F)h0IpGU?^c&M-TF&BKn+|#tO?gxo{^fGqidvRpqG+aT%wzqmzJ;Z;u`E6F=jkR9wRS_4BvS{NEoxdW3FdwzSgbUZ7E1fmj`{k-4cQi7AOCiF#SZ`FXKDzTAfl z1YG`m-JIOi5|kfz)miY;BX&9O95G%K&y#tgnt$Jy9i4o<@^hNohK;f|Y798PD#&nbkV4iz73qb|glnDr_owQgi>|>&6=gdu%stZ1eqm#AScw!lIS$ zBn%|`Ja3$}di2ctwAfCqYg+MLF3sQ7_PXwT(Y$V5)QkH!zc8W(Qj?6t9a!k%_fbiH zL3~bXS!#}6NkxhFxih*aJfEV6Pfz{MniycXfUrE?@Co;Db@kys@8Ns)BCofu*10q1 zHwPJ9F@8|wf7V;qOXsBirXUZmlRA2x`s^zMFBn`fHo9hf;R)BN^ZFOR>RjX1(Dgcd z(q~hUhNhP9Q!Y=R?LitVOfH>0ect=3@0rz4Fe0v3-~CfA&_Qc~SP8Ggd|g8vT^vIk zKl|!>`grPiUO_nTlJSF2-e-Kb25EqOuM2YhL#K&+dS}o2>a5xl!~sn=pH7_jy{hZs z=OI(-TW8-ua$;*uA!5bE?Vf5vuo4;4&RnH)4S$>xRhBM z-J#AWYFn_fn7_L?Y<6AQ^JyPXieBG*SY<+W;&Q!>>LN_cEe}-h??3GSBYAy>&liz* z?gc$fQ9Q0!9@WY-t2hnB^3* zeryF4L^lJ&mPSjsejRj7DpK73d~2iT?otY=;op4LWFsr@R|q7lL6kWY#<%%K&S&$KZ6Ct F0{}u2WP$(y literal 0 HcmV?d00001 diff --git a/tests/unit/test_finder.py b/tests/unit/test_finder.py index 638d1f9cdd1..7cfb6d48019 100644 --- a/tests/unit/test_finder.py +++ b/tests/unit/test_finder.py @@ -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""" From 5749dd1513519c2feda8c8140b101068d08cb845 Mon Sep 17 00:00:00 2001 From: Ian Stapleton Cordasco Date: Tue, 22 Aug 2017 05:56:36 -0500 Subject: [PATCH 2/2] Add news entry for PR 4299 --- news/4299.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/4299.feature diff --git a/news/4299.feature b/news/4299.feature new file mode 100644 index 00000000000..0f9f3c618b4 --- /dev/null +++ b/news/4299.feature @@ -0,0 +1 @@ +Support build-numbers in wheel versions and support sorting with build-numbers.