Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/4455.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(pypi) {attr}`pip.parse.target_platforms` accepts `"*"` to evaluate the
requirements for all built-in default platforms and any custom platforms
configured with {obj}`pip.default`.
7 changes: 7 additions & 0 deletions python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,18 @@ function in general are the same as used in the {obj}`pip.default.platform` attr
If you only care for the host platform and do not have a usecase to cross-build, then you can put in
a string `"{os}_{arch}"` as the value here. You could also use `"{os}_{arch}_freethreaded"` as well.

Use `"*"` to evaluate the requirements for all built-in default platforms and
any custom platforms configured with {obj}`pip.default`.

:::{include} /_includes/experimental_api.md
:::

:::{versionadded} 1.8.0
:::

:::{versionchanged} VERSION_NEXT_FEATURE
Added support for `"*"` to select all of the configured platforms.
:::
""",
),
"uv_lock": attr.label(
Expand Down
4 changes: 4 additions & 0 deletions python/private/pypi/hub_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ def _platforms(module_ctx, *, python_version, config, target_platforms):
strict = True,
)

if "*" in target_platforms:
# All of the configured platforms.
target_platforms = []

target_platforms = sorted({
p.format(
os = repo_utils.get_platforms_os_name(module_ctx),
Expand Down
148 changes: 148 additions & 0 deletions tests/pypi/hub_builder/hub_builder_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,154 @@ def _test_uv_lock_only(env):

_tests.append(_test_uv_lock_only)

def _test_target_platforms_all(env):
builder = hub_builder(env)
builder.pip_parse(
_mock_mctx(
os_name = "osx",
arch_name = "aarch64",
mock_files = {
"uv.lock": json.encode({
"package": [
{
"name": "simple",
"source": {"registry": "https://pypi.org/simple"},
"version": "0.0.1",
"wheels": [
{
"hash": "sha256:deadbeef",
"url": "https://files.pythonhosted.org/packages/simple-0.0.1-py3-none-any.whl",
},
],
},
],
}),
},
),
_parse(
hub_name = "pypi",
python_version = "3.15",
requirements_lock = None,
target_platforms = ["*"],
uv_lock = "uv.lock",
),
)
pypi = builder.build()

pypi.exposed_packages().contains_exactly(["simple"])
pypi.whl_map().contains_exactly({
"simple": {
"pypi_315_simple_py3_none_any_deadbeef": [
whl_config_setting(
target_platforms = (
"cp315_linux_aarch64",
"cp315_linux_x86_64",
"cp315_linux_x86_64_freethreaded",
"cp315_osx_aarch64",
"cp315_windows_aarch64",
),
version = "3.15",
),
],
},
})

_tests.append(_test_target_platforms_all)

def _test_target_platforms_all_platform_wheels(env):
builder = hub_builder(env)
builder.pip_parse(
_mock_mctx(
os_name = "osx",
arch_name = "aarch64",
mock_files = {
"uv.lock": json.encode({
"package": [
{
"name": "plat",
"source": {"registry": "https://pypi.org/simple"},
"version": "0.0.1",
"wheels": [
{
"hash": "sha256:deadb001",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-manylinux_2_17_x86_64.whl",
},
{
"hash": "sha256:deadb002",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315t-manylinux_2_17_x86_64.whl",
},
{
"hash": "sha256:deadb003",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-manylinux_2_17_aarch64.whl",
},
{
"hash": "sha256:deadb004",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-macosx_11_0_arm64.whl",
},
{
"hash": "sha256:deadb005",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-win_arm64.whl",
},
{
"hash": "sha256:deadb006",
"url": "https://files.pythonhosted.org/packages/plat-0.0.1-py3-none-any.whl",
},
],
},
],
}),
},
),
_parse(
hub_name = "pypi",
python_version = "3.15",
requirements_lock = None,
target_platforms = ["*"],
uv_lock = "uv.lock",
),
)
pypi = builder.build()

pypi.exposed_packages().contains_exactly(["plat"])

# Each of the platforms selects its own platform specific wheel.
pypi.whl_map().contains_exactly({
"plat": {
"pypi_315_plat_cp315_cp315_macosx_11_0_arm64_deadb004": [
whl_config_setting(
target_platforms = ("cp315_osx_aarch64",),
version = "3.15",
),
],
"pypi_315_plat_cp315_cp315_manylinux_2_17_aarch64_deadb003": [
whl_config_setting(
target_platforms = ("cp315_linux_aarch64",),
version = "3.15",
),
],
"pypi_315_plat_cp315_cp315_manylinux_2_17_x86_64_deadb001": [
whl_config_setting(
target_platforms = ("cp315_linux_x86_64",),
version = "3.15",
),
],
"pypi_315_plat_cp315_cp315_win_arm64_deadb005": [
whl_config_setting(
target_platforms = ("cp315_windows_aarch64",),
version = "3.15",
),
],
"pypi_315_plat_cp315_cp315t_manylinux_2_17_x86_64_deadb002": [
whl_config_setting(
target_platforms = ("cp315_linux_x86_64_freethreaded",),
version = "3.15",
),
],
},
})

_tests.append(_test_target_platforms_all_platform_wheels)

def _test_simple_multiple_requirements(env):
sub_tests = {
("osx", "aarch64"): "simple==0.0.2 --hash=sha256:deadb00f",
Expand Down
Loading