Skip to content

Commit 3943a32

Browse files
committed
finish some extra refactoring to make things more robust
1 parent b1ae72e commit 3943a32

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

python/private/pypi/extension.bzl

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -492,40 +492,36 @@ preference.
492492
Will always include `"any"` even if it is not specified.
493493
494494
The items in this list can contain a single `*` character that is equivalent to matching the
495-
lowest available version component in the platform_tag. Note, if the wheel platform tag does not
495+
lowest available version component in the platform_tag. If the wheel platform tag does not
496496
have a version component, e.g. `linux_x86_64` or `win_amd64`, then `*` will act as a regular character.
497497
498498
:::{note}
499-
We select a single wheel and the last match will take precedence, if the platform_tag that we
500-
match has a version component (e.g. `android_x_arch`, then the version `x` will be used in the
501-
matching algorithm).
502-
503499
Normally, the `*` in the matcher means that we will target the lowest platform version that we can
504500
and will give preference to whls built targeting the older versions of the platform. If you
505501
specify the version, then we will use the MVS (Minimal Version Selection) algorithm to select the
506502
compatible wheel. As such, you need to keep in mind how to configure the target platforms to
507-
select a particular wheel of your preference. To sum up:
508-
* To select any wheel, use `*`.
509-
* To exclude versions up to `X.Y` - submit a PR supporting this feature.
510-
* To exclude versions above `X.Y`, provide the full platform tag specifier, e.g. `musllinux_1_2_x86_64`, which will ensure that no wheels with `musllinux_1_3_x86_64` or higher are selected.
511-
:::
503+
select a particular wheel of your preference.
512504
513-
:::{note}
514-
The following tag prefixes should be used instead of the legacy equivalents:
515-
* `manylinux_2_5` instead of `manylinux1`
516-
* `manylinux_2_12` instead of `manylinux2010`
517-
* `manylinux_2_17` instead of `manylinux2014`
518-
519-
When parsing the whl filenames `rules_python` will automatically transform wheel filenames to the
520-
latest format.
505+
We select a single wheel and the last match will take precedence, if the platform_tag that we
506+
match has a version component (e.g. `android_x_arch`, then the version `x` will be used in the
507+
MVS matching algorithm).
508+
509+
Common patterns:
510+
* To select any versioned wheel for an `<os>`, `<arch>`, use `<os>_*_<arch>`, e.g.
511+
`manylinux_2_17_x86_64`.
512+
* To exclude versions up to `X.Y` - **submit a PR supporting this feature**.
513+
* To exclude versions above `X.Y`, provide the full platform tag specifier, e.g.
514+
`musllinux_1_2_x86_64`, which will ensure that no wheels with `musllinux_1_3_x86_64` or higher
515+
are selected.
521516
:::
522517
523518
:::{seealso}
524519
See official [docs](https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#platform-tag) for more information.
525520
:::
526521
:::{versionchanged} VERSION_NEXT_FEATURE
527522
The matching of versioned platforms have been switched to MVS (Minimal Version Selection)
528-
algorithm for easier evaluation logic and fewer surprises.
523+
algorithm for easier evaluation logic and fewer surprises. The legacy platform tags are
524+
supported from this version without extra handling from the user.
529525
:::
530526
""",
531527
),

python/private/pypi/select_whl.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ _MANYLINUX = "manylinux"
1010
_MACOSX = "macosx"
1111
_MUSLLINUX = "musllinux"
1212

13+
# Taken from https://peps.python.org/pep-0600/
14+
_LEGACY_ALIASES = {
15+
"manylinux1_i686": "manylinux_2_5_i686",
16+
"manylinux1_x86_64": "manylinux_2_5_x86_64",
17+
"manylinux2010_i686": "manylinux_2_12_i686",
18+
"manylinux2010_x86_64": "manylinux_2_12_x86_64",
19+
"manylinux2014_aarch64": "manylinux_2_17_aarch64",
20+
"manylinux2014_armv7l": "manylinux_2_17_armv7l",
21+
"manylinux2014_i686": "manylinux_2_17_i686",
22+
"manylinux2014_ppc64": "manylinux_2_17_ppc64",
23+
"manylinux2014_ppc64le": "manylinux_2_17_ppc64le",
24+
"manylinux2014_s390x": "manylinux_2_17_s390x",
25+
"manylinux2014_x86_64": "manylinux_2_17_x86_64",
26+
}
27+
1328
def _value_priority(*, tag, values):
1429
keys = []
1530
for priority, wp in enumerate(values):
@@ -36,6 +51,8 @@ def _parse_platform_tags(tags):
3651
ret = []
3752
replacements = {}
3853
for tag in tags:
54+
tag = _LEGACY_ALIASES.get(tag, tag)
55+
3956
if not _is_platform_tag_versioned(tag):
4057
ret.append(tag)
4158
continue

tests/pypi/select_whl/select_whl_tests.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,34 @@ def _test_select_by_supported_cp_version(env):
231231

232232
_tests.append(_test_select_by_supported_cp_version)
233233

234+
def _test_legacy_manylinux(env):
235+
for legacy, replacement in {
236+
"manylinux1": "manylinux_2_5",
237+
"manylinux2010": "manylinux_2_12",
238+
"manylinux2014": "manylinux_2_17",
239+
}.items():
240+
for plat in [legacy, replacement]:
241+
whls = [
242+
"pkg-0.0.1-py3-none-{}_x86_64.whl".format(plat),
243+
"pkg-0.0.1-py3-none-any.whl",
244+
]
245+
246+
got = _select_whl(
247+
whls = whls,
248+
whl_platform_tags = ["{}_x86_64".format(legacy)],
249+
whl_abi_tags = ["none"],
250+
python_version = "3.10",
251+
)
252+
want = _select_whl(
253+
whls = whls,
254+
whl_platform_tags = ["{}_x86_64".format(replacement)],
255+
whl_abi_tags = ["none"],
256+
python_version = "3.10",
257+
)
258+
_match(env, [got], want.filename)
259+
260+
_tests.append(_test_legacy_manylinux)
261+
234262
def _test_supported_cp_version_manylinux(env):
235263
whls = [
236264
"pkg-0.0.1-py2.py3-none-manylinux_1_1_x86_64.whl",

0 commit comments

Comments
 (0)