Skip to content

Commit 9d15522

Browse files
committed
fix(pypi): correctly handle custom names in pipstar platforms
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 d2c7ba2 commit 9d15522

File tree

8 files changed

+31
-25
lines changed

8 files changed

+31
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ END_UNRELEASED_TEMPLATE
7272
* (runfiles) The pypi runfiles package now includes `py.typed` to indicate it
7373
supports type checking
7474
([#2503](https://github.com/bazel-contrib/rules_python/issues/2503)).
75+
* (pypi) The pipstar `defaults` configuration now supports any custom platform
76+
name.
7577

7678
{#v0-0-0-added}
7779
### 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: 12 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]
@@ -383,6 +387,12 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
383387
if key not in _SUPPORTED_PEP508_KEYS:
384388
fail("Unsupported key in the PEP508 environment: {}".format(key))
385389

390+
if not os_name:
391+
fail("'os_name' is required")
392+
393+
if not arch_name:
394+
fail("'arch_name' is required")
395+
386396
config["platforms"][platform] = struct(
387397
name = platform.replace("-", "_").lower(),
388398
os_name = os_name,

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
@@ -1048,7 +1048,9 @@ def _test_pipstar_platforms(env):
10481048
name = "rules_python",
10491049
default = [
10501050
_default(
1051-
platform = "{}_{}".format(os, cpu),
1051+
platform = "my{}_{}".format(os, cpu),
1052+
os_name = os,
1053+
arch_name = cpu,
10521054
config_settings = [
10531055
"@platforms//os:{}".format(os),
10541056
"@platforms//cpu:{}".format(cpu),
@@ -1086,37 +1088,33 @@ optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux'
10861088
pypi.hub_whl_map().contains_exactly({
10871089
"pypi": {
10881090
"optimum": {
1089-
"pypi_315_optimum_linux_x86_64": [
1091+
"pypi_315_optimum_mylinux_x86_64": [
10901092
whl_config_setting(
10911093
version = "3.15",
10921094
target_platforms = [
1093-
"cp315_linux_x86_64",
1095+
"cp315_mylinux_x86_64",
10941096
],
1095-
config_setting = None,
1096-
filename = None,
10971097
),
10981098
],
1099-
"pypi_315_optimum_osx_aarch64": [
1099+
"pypi_315_optimum_myosx_aarch64": [
11001100
whl_config_setting(
11011101
version = "3.15",
11021102
target_platforms = [
1103-
"cp315_osx_aarch64",
1103+
"cp315_myosx_aarch64",
11041104
],
1105-
config_setting = None,
1106-
filename = None,
11071105
),
11081106
],
11091107
},
11101108
},
11111109
})
11121110

11131111
pypi.whl_libraries().contains_exactly({
1114-
"pypi_315_optimum_linux_x86_64": {
1112+
"pypi_315_optimum_mylinux_x86_64": {
11151113
"dep_template": "@pypi//{name}:{target}",
11161114
"python_interpreter_target": "unit_test_interpreter_target",
11171115
"requirement": "optimum[onnxruntime-gpu]==1.17.1",
11181116
},
1119-
"pypi_315_optimum_osx_aarch64": {
1117+
"pypi_315_optimum_myosx_aarch64": {
11201118
"dep_template": "@pypi//{name}:{target}",
11211119
"python_interpreter_target": "unit_test_interpreter_target",
11221120
"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