diff --git a/news/4455.added.md b/news/4455.added.md new file mode 100644 index 0000000000..3af2fc29cb --- /dev/null +++ b/news/4455.added.md @@ -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`. diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index 71423e4e8b..4e5863532a 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -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( diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl index ef6a7247c1..df0c48794e 100644 --- a/python/private/pypi/hub_builder.bzl +++ b/python/private/pypi/hub_builder.bzl @@ -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), diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index 073ccc0f58..fca32c5384 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -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",