Skip to content

Commit 9ba8c12

Browse files
refactor: migrate tests to use hub_builder instead of full integration (#3247)
This PR migrates some of the tests that we had testing the full extension parsing to just test the hub builder. I ran out of time to migrate everything and there is a little bit of copy pasted code. The goal is to make the assertions easier to understand because the nesting of the dictionaries will be not as large. Later we can add tests that are testing individual `hub_builder` methods, which will be needed when we start implementing the `pip.configure` tag class or we implement a `py.lock` parsing. Work towards #2747 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5467ed6 commit 9ba8c12

File tree

7 files changed

+1208
-1060
lines changed

7 files changed

+1208
-1060
lines changed

python/private/pypi/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ bzl_library(
115115
":parse_whl_name_bzl",
116116
":pep508_env_bzl",
117117
":pip_repository_attrs_bzl",
118+
":platform_bzl",
118119
":simpleapi_download_bzl",
119120
":whl_library_bzl",
120121
"//python/private:auth_bzl",
@@ -341,6 +342,11 @@ bzl_library(
341342
],
342343
)
343344

345+
bzl_library(
346+
name = "platform_bzl",
347+
srcs = ["platform.bzl"],
348+
)
349+
344350
bzl_library(
345351
name = "pypi_repo_utils_bzl",
346352
srcs = ["pypi_repo_utils.bzl"],

python/private/pypi/extension.bzl

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ load(":hub_repository.bzl", "hub_repository", "whl_config_settings_to_json")
2727
load(":parse_whl_name.bzl", "parse_whl_name")
2828
load(":pep508_env.bzl", "env")
2929
load(":pip_repository_attrs.bzl", "ATTRS")
30+
load(":platform.bzl", _plat = "platform")
3031
load(":simpleapi_download.bzl", "simpleapi_download")
3132
load(":whl_library.bzl", "whl_library")
3233

@@ -55,31 +56,6 @@ def _whl_mods_impl(whl_mods_dict):
5556
whl_mods = whl_mods,
5657
)
5758

58-
def _plat(*, name, arch_name, os_name, config_settings = [], env = {}, marker = "", whl_abi_tags = [], whl_platform_tags = []):
59-
# NOTE @aignas 2025-07-08: the least preferred is the first item in the list
60-
if "any" not in whl_platform_tags:
61-
# the lowest priority one needs to be the first one
62-
whl_platform_tags = ["any"] + whl_platform_tags
63-
64-
whl_abi_tags = whl_abi_tags or ["abi3", "cp{major}{minor}"]
65-
if "none" not in whl_abi_tags:
66-
# the lowest priority one needs to be the first one
67-
whl_abi_tags = ["none"] + whl_abi_tags
68-
69-
return struct(
70-
name = name,
71-
arch_name = arch_name,
72-
os_name = os_name,
73-
config_settings = config_settings,
74-
env = {
75-
# defaults for env
76-
"implementation_name": "cpython",
77-
} | env,
78-
marker = marker,
79-
whl_abi_tags = whl_abi_tags,
80-
whl_platform_tags = whl_platform_tags,
81-
)
82-
8359
def _configure(config, *, override = False, **kwargs):
8460
"""Set the value in the config if the value is provided"""
8561
env = kwargs.get("env")

python/private/pypi/platform.bzl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""A common platform structure for using internally."""
2+
3+
def platform(*, name, arch_name, os_name, config_settings = [], env = {}, marker = "", whl_abi_tags = [], whl_platform_tags = []):
4+
"""A platform structure for using internally.
5+
6+
Args:
7+
name: {type}`str` the human friendly name of the platform.
8+
arch_name: {type}`str` the @platforms//cpu:<arch_name> value.
9+
os_name: {type}`str` the @platforms//os:<os_name> value.
10+
config_settings: {type}`list[Label|str]` The list of labels for selecting the
11+
platform.
12+
env: {type}`dict[str, str]` the PEP508 environment for marker evaluation.
13+
marker: {type}`str` the env marker expression that is evaluated to determine if we
14+
should use the platform. This is useful to turn on certain platforms for
15+
particular python versions.
16+
whl_abi_tags: {type}`list[str]` A list of values for matching abi tags.
17+
whl_platform_tags: {type}`list[str]` A list of values for matching platform tags.
18+
19+
Returns:
20+
struct with the necessary values for pipstar implementation.
21+
"""
22+
23+
# NOTE @aignas 2025-07-08: the least preferred is the first item in the list
24+
if "any" not in whl_platform_tags:
25+
# the lowest priority one needs to be the first one
26+
whl_platform_tags = ["any"] + whl_platform_tags
27+
28+
whl_abi_tags = whl_abi_tags or ["abi3", "cp{major}{minor}"]
29+
if "none" not in whl_abi_tags:
30+
# the lowest priority one needs to be the first one
31+
whl_abi_tags = ["none"] + whl_abi_tags
32+
33+
return struct(
34+
name = name,
35+
arch_name = arch_name,
36+
os_name = os_name,
37+
config_settings = config_settings,
38+
env = {
39+
# defaults for env
40+
"implementation_name": "cpython",
41+
} | env,
42+
marker = marker,
43+
whl_abi_tags = whl_abi_tags,
44+
whl_platform_tags = whl_platform_tags,
45+
)

0 commit comments

Comments
 (0)