Skip to content

Commit 08d7f77

Browse files
committed
fix(pypi): select the lowest available libc version by default
The #3058 PR has subtly changed the default behaviour of `experimental_index_url` code path and I think in order to make things easier by default for our users we should go back to that behaviour. The selection of the wheels happens in two ways: 1. If the user specifies `whl_platform_tags` value like `manylinux_*_x86_64` then we we should just get the lowest available versioned wheel. I.e. if `manylinux_2_28_x86_64` and `manylinux_2_32_x86_64` are available, we should prefer the former. 2. If the user specifies `whl_platform_tags` value like `manylinux_2_32_x86_64` then we we should get the highest version that is lower or equal than the specified one. I.e. if `manylinux_2_21_x86_64`, `manylinux_2_28_x86_64` and `manylinux_2_36_x86_64` are available, we should prefer the `manylinux_2_28_x86_64` one. Fixes #3250
1 parent 9ba8c12 commit 08d7f77

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ END_UNRELEASED_TEMPLATE
7979
length errors due to too long environment variables.
8080
* (bootstrap) {obj}`--bootstrap_impl=script` now supports the `-S` interpreter
8181
setting.
82+
* (pypi) We now by default select the highest closest match wheel version if the user is
83+
specifying a particular version via the `whl_platform_tags` or if any version is matched via
84+
the `*` token, then we select the lowest available version.
85+
Fixes [#3250](https://github.com/bazel-contrib/rules_python/issues/3250).
8286

8387
{#v0-0-0-added}
8488
### Added

python/private/pypi/select_whl.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def _platform_tag_priority(*, tag, values):
4646
arch = tail
4747
version = (int(major), int(minor))
4848

49+
select_highest = True
50+
4951
keys = []
5052
for priority, wp in enumerate(values):
5153
want_os, sep, tail = wp.partition("_")
@@ -65,6 +67,7 @@ def _platform_tag_priority(*, tag, values):
6567
want_major = ""
6668
want_minor = ""
6769
want_arch = tail
70+
select_highest = False
6871
elif os.startswith(_ANDROID):
6972
# we set it to `0` above, so setting the `want_minor` her to `0` will make things
7073
# consistent.
@@ -81,7 +84,7 @@ def _platform_tag_priority(*, tag, values):
8184
# if want_major is defined, then we know that we don't have a `*` in the matcher.
8285
want_version = (int(want_major), int(want_minor)) if want_major else None
8386
if not want_version or version <= want_version:
84-
keys.append((priority, version))
87+
keys.append((priority, version if select_highest else (-version[0], -version[1])))
8588

8689
return max(keys) if keys else None
8790

tests/pypi/select_whl/select_whl_tests.bzl

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,10 @@ def _test_multiple_musllinux(env):
406406
_match(
407407
env,
408408
got,
409-
# select the one with the highest version that is matching
410-
"pkg-0.0.1-py3-none-musllinux_1_1_x86_64.whl",
409+
# select the one with the lowest version that is matching because we want to
410+
# increase the compatibility
411411
"pkg-0.0.1-py3-none-musllinux_1_2_x86_64.whl",
412+
"pkg-0.0.1-py3-none-musllinux_1_1_x86_64.whl",
412413
)
413414

414415
_tests.append(_test_multiple_musllinux)
@@ -434,6 +435,28 @@ def _test_multiple_musllinux_exact_params(env):
434435

435436
_tests.append(_test_multiple_musllinux_exact_params)
436437

438+
def _test_multiple_highest_closest_match(env):
439+
got = _select_whl(
440+
whls = [
441+
"pkg-0.0.1-py3-none-musllinux_1_4_x86_64.whl",
442+
"pkg-0.0.1-py3-none-musllinux_1_2_x86_64.whl",
443+
"pkg-0.0.1-py3-none-musllinux_1_1_x86_64.whl",
444+
],
445+
whl_platform_tags = ["musllinux_1_3_x86_64"],
446+
whl_abi_tags = ["none"],
447+
python_version = "3.12",
448+
limit = 2,
449+
)
450+
_match(
451+
env,
452+
got,
453+
# select the one with the lowest version, because of the input to the function
454+
"pkg-0.0.1-py3-none-musllinux_1_1_x86_64.whl",
455+
"pkg-0.0.1-py3-none-musllinux_1_2_x86_64.whl",
456+
)
457+
458+
_tests.append(_test_multiple_highest_closest_match)
459+
437460
def _test_android(env):
438461
got = _select_whl(
439462
whls = [

0 commit comments

Comments
 (0)