Skip to content

Commit 3d93274

Browse files
authored
fix(pypi): correctly handle custom names in pipstar platforms (#3054)
Before it seems that we were relying on particular names in the pipstar platforms. This ensures that we rely on this less. Whilst at it fix a few typos and improve the formatting of the code. Work towards #2949 Work towards #2747
1 parent 4143903 commit 3d93274

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ END_UNRELEASED_TEMPLATE
8282
* (toolchains) `local_runtime_repo` now checks if the include directory exists
8383
before attempting to watch it, fixing issues on macOS with system Python
8484
({gh-issue}`3043`).
85+
* (pypi) The pipstar `defaults` configuration now supports any custom platform
86+
name.
8587

8688
{#v0-0-0-added}
8789
### Added

python/private/pypi/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ bzl_library(
252252
bzl_library(
253253
name = "pep508_env_bzl",
254254
srcs = ["pep508_env.bzl"],
255-
deps = [
256-
":pep508_platform_bzl",
257-
"//python/private:version_bzl",
258-
],
259255
)
260256

261257
bzl_library(

python/private/pypi/evaluate_markers.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def evaluate_markers_py(mrctx, *, requirements, python_interpreter, python_inter
5757
5858
Args:
5959
mrctx: repository_ctx or module_ctx.
60-
requirements: list[str] of the requirement file lines to evaluate.
60+
requirements: {type}`dict[str, list[str]]` of the requirement file lines to evaluate.
6161
python_interpreter: str, path to the python_interpreter to use to
6262
evaluate the env markers in the given requirements files. It will
6363
be only called if the requirements files have env markers. This

python/private/pypi/extension.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def _platforms(*, python_version, minor_mapping, config):
7676

7777
for platform, values in config.platforms.items():
7878
key = "{}_{}".format(abi, platform)
79-
platforms[key] = env(key) | values.env
79+
platforms[key] = env(struct(
80+
abi = abi,
81+
os = values.os_name,
82+
arch = values.arch_name,
83+
)) | values.env
8084
return platforms
8185

8286
def _create_whl_repos(
@@ -348,7 +352,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
348352
args["filename"] = src.filename
349353
if not enable_pipstar:
350354
args["experimental_target_platforms"] = [
351-
# Get rid of the version fot the target platforms because we are
355+
# Get rid of the version for the target platforms because we are
352356
# passing the interpreter any way. Ideally we should search of ways
353357
# how to pass the target platforms through the hub repo.
354358
p.partition("_")[2]

python/private/pypi/parse_requirements.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ def _add_dists(*, requirement, index_urls, logger = None):
402402
]))
403403

404404
# Filter out the wheels that are incompatible with the target_platforms.
405-
whls = select_whls(whls = whls, want_platforms = requirement.target_platforms, logger = logger)
405+
whls = select_whls(
406+
whls = whls,
407+
want_platforms = requirement.target_platforms,
408+
logger = logger,
409+
)
406410

407411
return whls, sdist

python/private/pypi/pep508_env.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
"""This module is for implementing PEP508 environment definition.
1616
"""
1717

18-
load(":pep508_platform.bzl", "platform_from_str")
19-
2018
# See https://stackoverflow.com/a/45125525
2119
platform_machine_aliases = {
2220
# These pairs mean the same hardware, but different values may be used
@@ -175,9 +173,6 @@ def env(target_platform, *, extra = None):
175173
if extra != None:
176174
env["extra"] = extra
177175

178-
if type(target_platform) == type(""):
179-
target_platform = platform_from_str(target_platform, python_version = "")
180-
181176
if target_platform.abi:
182177
minor_version, _, micro_version = target_platform.abi[3:].partition(".")
183178
micro_version = micro_version or "0"

tests/pypi/extension/extension_tests.bzl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,9 @@ def _test_pipstar_platforms(env):
10321032
name = "rules_python",
10331033
default = [
10341034
_default(
1035-
platform = "{}_{}".format(os, cpu),
1035+
platform = "my{}_{}".format(os, cpu),
1036+
os_name = os,
1037+
arch_name = cpu,
10361038
config_settings = [
10371039
"@platforms//os:{}".format(os),
10381040
"@platforms//cpu:{}".format(cpu),
@@ -1070,37 +1072,33 @@ optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux'
10701072
pypi.hub_whl_map().contains_exactly({
10711073
"pypi": {
10721074
"optimum": {
1073-
"pypi_315_optimum_linux_x86_64": [
1075+
"pypi_315_optimum_mylinux_x86_64": [
10741076
whl_config_setting(
10751077
version = "3.15",
10761078
target_platforms = [
1077-
"cp315_linux_x86_64",
1079+
"cp315_mylinux_x86_64",
10781080
],
1079-
config_setting = None,
1080-
filename = None,
10811081
),
10821082
],
1083-
"pypi_315_optimum_osx_aarch64": [
1083+
"pypi_315_optimum_myosx_aarch64": [
10841084
whl_config_setting(
10851085
version = "3.15",
10861086
target_platforms = [
1087-
"cp315_osx_aarch64",
1087+
"cp315_myosx_aarch64",
10881088
],
1089-
config_setting = None,
1090-
filename = None,
10911089
),
10921090
],
10931091
},
10941092
},
10951093
})
10961094

10971095
pypi.whl_libraries().contains_exactly({
1098-
"pypi_315_optimum_linux_x86_64": {
1096+
"pypi_315_optimum_mylinux_x86_64": {
10991097
"dep_template": "@pypi//{name}:{target}",
11001098
"python_interpreter_target": "unit_test_interpreter_target",
11011099
"requirement": "optimum[onnxruntime-gpu]==1.17.1",
11021100
},
1103-
"pypi_315_optimum_osx_aarch64": {
1101+
"pypi_315_optimum_myosx_aarch64": {
11041102
"dep_template": "@pypi//{name}:{target}",
11051103
"python_interpreter_target": "unit_test_interpreter_target",
11061104
"requirement": "optimum[onnxruntime]==1.17.1",

tests/pypi/pep508/evaluate_tests.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1717
load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
1818
load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize") # buildifier: disable=bzl-visibility
19+
load("//python/private/pypi:pep508_platform.bzl", "platform_from_str") # buildifier: disable=bzl-visibility
1920

2021
_tests = []
2122

@@ -262,7 +263,7 @@ def _evaluate_with_aliases(env):
262263
},
263264
}.items(): # buildifier: @unsorted-dict-items
264265
for input, want in tests.items():
265-
_check_evaluate(env, input, want, pep508_env(target_platform))
266+
_check_evaluate(env, input, want, pep508_env(platform_from_str(target_platform, "")))
266267

267268
_tests.append(_evaluate_with_aliases)
268269

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy