From 1f8e9a8af25130c4efeba902a6ed11cb85148354 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:57:40 +0900 Subject: [PATCH 1/6] feat(pypi): support target_platforms = ["*"] in pip.parse Allow selecting all of the platforms configured with `pip.default` without listing them one by one. This is useful for hubs that need to support cross-building for any of the configured platforms, e.g. a hub that provides a tool for every toolchain. --- news/pip-target-platforms-all.added.md | 2 + python/private/pypi/extension.bzl | 7 ++++ python/private/pypi/hub_builder.bzl | 4 ++ tests/pypi/hub_builder/hub_builder_tests.bzl | 40 ++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 news/pip-target-platforms-all.added.md diff --git a/news/pip-target-platforms-all.added.md b/news/pip-target-platforms-all.added.md new file mode 100644 index 0000000000..cb690ce07b --- /dev/null +++ b/news/pip-target-platforms-all.added.md @@ -0,0 +1,2 @@ +(pypi) {attr}`pip.parse.target_platforms` accepts `"*"` to evaluate the +requirements for all of the platforms configured with {obj}`pip.default`. diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index 71423e4e8b..908a40b90d 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 of the 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..0a5c319311 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -176,6 +176,46 @@ 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": """{"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_simple_multiple_requirements(env): sub_tests = { ("osx", "aarch64"): "simple==0.0.2 --hash=sha256:deadb00f", From 5149b91edef1df7d213e8e46382b3f36d9032ea2 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:11:49 +0900 Subject: [PATCH 2/6] feat(pypi): use the none-any wheel as a fallback with target_platforms = ["*"] When `target_platforms = ["*"]` is used with a `uv.lock` file, add the platform independent wheel of a package, if there is one, as a fallback for the Python version. The platforms that are not configured with `pip.default` can then still use the package, whilst the configured platforms keep using the more specific wheels. --- news/pip-target-platforms-all.added.md | 4 +- python/private/pypi/extension.bzl | 4 +- python/private/pypi/hub_builder.bzl | 24 ++++++++++ python/private/pypi/parse_requirements.bzl | 49 ++++++++++++++++++-- tests/pypi/hub_builder/hub_builder_tests.bzl | 47 +++++++++++++++++-- 5 files changed, 118 insertions(+), 10 deletions(-) diff --git a/news/pip-target-platforms-all.added.md b/news/pip-target-platforms-all.added.md index cb690ce07b..374a45f061 100644 --- a/news/pip-target-platforms-all.added.md +++ b/news/pip-target-platforms-all.added.md @@ -1,2 +1,4 @@ (pypi) {attr}`pip.parse.target_platforms` accepts `"*"` to evaluate the -requirements for all of the platforms configured with {obj}`pip.default`. +requirements for all of the platforms configured with {obj}`pip.default`. With +{attr}`pip.parse.uv_lock`, the `none-any` wheel of a package is also used for +the platforms that are not configured. diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index 908a40b90d..fa328d6556 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -907,7 +907,9 @@ If you only care for the host platform and do not have a usecase to cross-build, a string `"{os}_{arch}"` as the value here. You could also use `"{os}_{arch}_freethreaded"` as well. Use `"*"` to evaluate the requirements for all of the platforms configured with -{obj}`pip.default`. +{obj}`pip.default`. When used together with {attr}`uv_lock`, the platform +independent (`none-any`) wheel of a package, if present, is also used for the +platforms that are not configured with {obj}`pip.default`. :::{include} /_includes/experimental_api.md ::: diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl index df0c48794e..1f61a5e332 100644 --- a/python/private/pypi/hub_builder.bzl +++ b/python/private/pypi/hub_builder.bzl @@ -577,6 +577,7 @@ def _create_whl_repos( extra_pip_args = pip_attr.extra_pip_args, get_index_urls = self._get_index_urls.get(python_version), toml_decode = getattr(self._config, "toml_decode", None), + any_src = "*" in pip_attr.target_platforms, logger = logger, ) @@ -631,6 +632,29 @@ def _create_whl_repos( repo = repo, ) + if getattr(whl, "any_src", None): + # Use the platform independent wheel for the platforms that are + # not configured, so it has no target platforms and the more + # specific config settings take precedence. + _add_whl_library( + self, + python_version = python_version, + whl = whl, + repo = _whl_repo( + src = whl.any_src, + index_url = whl.index_url, + whl_library_args = whl_library_args, + download_only = pip_attr.download_only, + netrc = self._config.netrc or pip_attr.netrc, + use_downloader = True, + auth_patterns = self._config.auth_patterns or pip_attr.auth_patterns, + python_version = _major_minor_version(python_version), + is_multiple_versions = whl.is_multiple_versions, + interpreter = interpreter, + enable_pipstar_extract = enable_pipstar_extract, + ), + ) + def _common_args(self, module_ctx, *, pip_attr): # Construct args separately so that the lock file can be smaller and does not include unused # attrs. diff --git a/python/private/pypi/parse_requirements.bzl b/python/private/pypi/parse_requirements.bzl index 2d8c4b4774..7913602d44 100644 --- a/python/private/pypi/parse_requirements.bzl +++ b/python/private/pypi/parse_requirements.bzl @@ -47,6 +47,7 @@ def parse_requirements( extract_url_srcs = True, uv_lock = None, toml_decode = None, + any_src = False, logger): """Get the requirements with platforms that the requirements apply to. @@ -71,6 +72,9 @@ def parse_requirements( requirements files if both are provided. toml_decode: {type}`callable | None` A function to decode TOML content (e.g. `toml.decode`). Required when `uv_lock` is provided. + any_src: {type}`bool` whether to add the `any_src` field to each + returned struct, which is the platform independent wheel of the + package or `None`. Only supported with `uv_lock`. logger: repo_utils.logger, a simple struct to log diagnostic messages. Returns: @@ -96,6 +100,7 @@ def parse_requirements( get_index_urls = get_index_urls, extract_url_srcs = extract_url_srcs, uv_lock = uv_lock, + any_src = any_src, logger = logger, ) @@ -126,11 +131,13 @@ def _parse_requirements_with_uv_lock( get_index_urls, extract_url_srcs, uv_lock, + any_src, logger): """Parse requirements using uv.lock as the primary source.""" if uv_lock: return _parse_uv_lock_json( uv_lock = uv_lock, + any_src = any_src, all_platforms = _get_all_platforms(requirements_by_platform) if requirements_by_platform else sorted(platforms.keys()), platforms = platforms, extra_pip_args = extra_pip_args, @@ -220,7 +227,7 @@ def _uv_lock_package_platforms(packages, all_platforms, platforms): queue.append(target) return result -def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, platforms = {}): +def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, platforms = {}, any_src = False): """Parse uv.lock JSON and build the same return structs as parse_requirements. Args: @@ -230,6 +237,8 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p extra_pip_args: {type}`list[str] | None` Extra pip arguments to pass through. platforms: {type}`dict[str, struct]` A dict of platform name to platform info (containing `.env` with PEP 508 marker environment). + any_src: {type}`bool` whether to add the `any_src` field with the platform + independent wheel of each package. Returns: {type}`list[struct]` The same format as {func}`parse_requirements`. @@ -247,6 +256,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p version = pkg["version"] norm_name = normalize_name(name) entry = uv_packages.setdefault(norm_name, { + "any_srcs": {}, "distribution": name, "resolved_srcs": [], "versions": {}, @@ -303,6 +313,35 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p requirement = _uv_lock_git_requirement(pkg["source"]["git"]), ) + # The platform independent wheel, if there is one, which can be used + # as a fallback for the platforms that are not configured. + if any_src and candidates and pkg_platforms and platforms.get(pkg_platforms[0]): + platform = platforms[pkg_platforms[0]] + any_whl = select_whl( + whls = candidates, + python_version = platform.env.get("python_full_version", "3"), + whl_platform_tags = ["any"], + whl_abi_tags = ["none"], + implementation_name = platform.env.get("implementation_name", "cpython"), + limit = 1, + logger = logger, + ) + if any_whl: + entry["any_srcs"][any_whl.filename + any_whl.digest] = struct( + distribution = name, + extra_pip_args = extra_pip_args or [], + requirement_line = "{name}{extras}=={version}".format( + name = name, + extras = extra_str, + version = version, + ), + target_platforms = [], + filename = any_whl.filename, + digest = any_whl.digest, + url = any_whl.url, + yanked = None, + ) + plat_to_src = {} for p in pkg_platforms: platform = platforms.get(p) @@ -368,7 +407,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p for src in info["resolved_srcs"]: for p in src.target_platforms: resolved_platforms[p] = None - item = struct( + item = dict( name = norm_name, # Only expose packages that resolved on all configured platforms. # Workspace/root members (e.g. `source = { virtual = "." }` or @@ -384,7 +423,11 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p index_url = info["index_url"], srcs = info["resolved_srcs"], ) - ret.append(item) + if any_src: + # The platform independent wheel, if there is exactly one. + any_srcs = info["any_srcs"].values() + item["any_src"] = any_srcs[0] if len(any_srcs) == 1 else None + ret.append(struct(**item)) logger.debug(lambda: "Parsed {} packages from uv.lock".format(len(ret))) return ret diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index 0a5c319311..2470cf79e1 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -183,7 +183,25 @@ def _test_target_platforms_all(env): os_name = "osx", arch_name = "aarch64", mock_files = { - "uv.lock": """{"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"}]}]}""", + "uv.lock": json.encode({"package": [ + { + "name": "plat", + "source": {"registry": "https://pypi.org/simple"}, + "version": "0.0.1", + "wheels": [ + {"hash": "sha256:deadb00f", "url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-manylinux_2_17_x86_64.whl"}, + {"hash": "sha256:deadbeef", "url": "https://files.pythonhosted.org/packages/plat-0.0.1-py3-none-any.whl"}, + ], + }, + { + "name": "platonly", + "source": {"registry": "https://pypi.org/simple"}, + "version": "0.0.1", + "wheels": [ + {"hash": "sha256:deadbaaf", "url": "https://files.pythonhosted.org/packages/platonly-0.0.1-cp315-cp315-manylinux_2_17_x86_64.whl"}, + ], + }, + ]}), }, ), _parse( @@ -196,20 +214,39 @@ def _test_target_platforms_all(env): ) pypi = builder.build() - pypi.exposed_packages().contains_exactly(["simple"]) + # Only the packages that are available on all of the platforms are exposed. + pypi.exposed_packages().contains_exactly(["plat"]) pypi.whl_map().contains_exactly({ - "simple": { - "pypi_315_simple_py3_none_any_deadbeef": [ + "plat": { + "pypi_315_plat_cp315_cp315_manylinux_2_17_x86_64_deadb00f": [ + whl_config_setting( + target_platforms = ("cp315_linux_x86_64",), + version = "3.15", + ), + ], + "pypi_315_plat_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", ), + # The fallback for the platforms that are not configured. + whl_config_setting( + version = "3.15", + ), + ], + }, + # There is no platform independent wheel, so there is no fallback. + "platonly": { + "pypi_315_platonly_cp315_cp315_manylinux_2_17_x86_64_deadbaaf": [ + whl_config_setting( + target_platforms = ("cp315_linux_x86_64",), + version = "3.15", + ), ], }, }) From 6073cd04754502af2dd08a9667aca46e345fc2ba Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:22:12 +0900 Subject: [PATCH 3/6] Revert "feat(pypi): use the none-any wheel as a fallback with target_platforms = ["*"]" This reverts commit 5149b91edef1df7d213e8e46382b3f36d9032ea2. --- news/pip-target-platforms-all.added.md | 4 +- python/private/pypi/extension.bzl | 4 +- python/private/pypi/hub_builder.bzl | 24 ---------- python/private/pypi/parse_requirements.bzl | 49 ++------------------ tests/pypi/hub_builder/hub_builder_tests.bzl | 47 ++----------------- 5 files changed, 10 insertions(+), 118 deletions(-) diff --git a/news/pip-target-platforms-all.added.md b/news/pip-target-platforms-all.added.md index 374a45f061..cb690ce07b 100644 --- a/news/pip-target-platforms-all.added.md +++ b/news/pip-target-platforms-all.added.md @@ -1,4 +1,2 @@ (pypi) {attr}`pip.parse.target_platforms` accepts `"*"` to evaluate the -requirements for all of the platforms configured with {obj}`pip.default`. With -{attr}`pip.parse.uv_lock`, the `none-any` wheel of a package is also used for -the platforms that are not configured. +requirements for all of the platforms configured with {obj}`pip.default`. diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index fa328d6556..908a40b90d 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -907,9 +907,7 @@ If you only care for the host platform and do not have a usecase to cross-build, a string `"{os}_{arch}"` as the value here. You could also use `"{os}_{arch}_freethreaded"` as well. Use `"*"` to evaluate the requirements for all of the platforms configured with -{obj}`pip.default`. When used together with {attr}`uv_lock`, the platform -independent (`none-any`) wheel of a package, if present, is also used for the -platforms that are not configured with {obj}`pip.default`. +{obj}`pip.default`. :::{include} /_includes/experimental_api.md ::: diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl index 1f61a5e332..df0c48794e 100644 --- a/python/private/pypi/hub_builder.bzl +++ b/python/private/pypi/hub_builder.bzl @@ -577,7 +577,6 @@ def _create_whl_repos( extra_pip_args = pip_attr.extra_pip_args, get_index_urls = self._get_index_urls.get(python_version), toml_decode = getattr(self._config, "toml_decode", None), - any_src = "*" in pip_attr.target_platforms, logger = logger, ) @@ -632,29 +631,6 @@ def _create_whl_repos( repo = repo, ) - if getattr(whl, "any_src", None): - # Use the platform independent wheel for the platforms that are - # not configured, so it has no target platforms and the more - # specific config settings take precedence. - _add_whl_library( - self, - python_version = python_version, - whl = whl, - repo = _whl_repo( - src = whl.any_src, - index_url = whl.index_url, - whl_library_args = whl_library_args, - download_only = pip_attr.download_only, - netrc = self._config.netrc or pip_attr.netrc, - use_downloader = True, - auth_patterns = self._config.auth_patterns or pip_attr.auth_patterns, - python_version = _major_minor_version(python_version), - is_multiple_versions = whl.is_multiple_versions, - interpreter = interpreter, - enable_pipstar_extract = enable_pipstar_extract, - ), - ) - def _common_args(self, module_ctx, *, pip_attr): # Construct args separately so that the lock file can be smaller and does not include unused # attrs. diff --git a/python/private/pypi/parse_requirements.bzl b/python/private/pypi/parse_requirements.bzl index 7913602d44..2d8c4b4774 100644 --- a/python/private/pypi/parse_requirements.bzl +++ b/python/private/pypi/parse_requirements.bzl @@ -47,7 +47,6 @@ def parse_requirements( extract_url_srcs = True, uv_lock = None, toml_decode = None, - any_src = False, logger): """Get the requirements with platforms that the requirements apply to. @@ -72,9 +71,6 @@ def parse_requirements( requirements files if both are provided. toml_decode: {type}`callable | None` A function to decode TOML content (e.g. `toml.decode`). Required when `uv_lock` is provided. - any_src: {type}`bool` whether to add the `any_src` field to each - returned struct, which is the platform independent wheel of the - package or `None`. Only supported with `uv_lock`. logger: repo_utils.logger, a simple struct to log diagnostic messages. Returns: @@ -100,7 +96,6 @@ def parse_requirements( get_index_urls = get_index_urls, extract_url_srcs = extract_url_srcs, uv_lock = uv_lock, - any_src = any_src, logger = logger, ) @@ -131,13 +126,11 @@ def _parse_requirements_with_uv_lock( get_index_urls, extract_url_srcs, uv_lock, - any_src, logger): """Parse requirements using uv.lock as the primary source.""" if uv_lock: return _parse_uv_lock_json( uv_lock = uv_lock, - any_src = any_src, all_platforms = _get_all_platforms(requirements_by_platform) if requirements_by_platform else sorted(platforms.keys()), platforms = platforms, extra_pip_args = extra_pip_args, @@ -227,7 +220,7 @@ def _uv_lock_package_platforms(packages, all_platforms, platforms): queue.append(target) return result -def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, platforms = {}, any_src = False): +def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, platforms = {}): """Parse uv.lock JSON and build the same return structs as parse_requirements. Args: @@ -237,8 +230,6 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p extra_pip_args: {type}`list[str] | None` Extra pip arguments to pass through. platforms: {type}`dict[str, struct]` A dict of platform name to platform info (containing `.env` with PEP 508 marker environment). - any_src: {type}`bool` whether to add the `any_src` field with the platform - independent wheel of each package. Returns: {type}`list[struct]` The same format as {func}`parse_requirements`. @@ -256,7 +247,6 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p version = pkg["version"] norm_name = normalize_name(name) entry = uv_packages.setdefault(norm_name, { - "any_srcs": {}, "distribution": name, "resolved_srcs": [], "versions": {}, @@ -313,35 +303,6 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p requirement = _uv_lock_git_requirement(pkg["source"]["git"]), ) - # The platform independent wheel, if there is one, which can be used - # as a fallback for the platforms that are not configured. - if any_src and candidates and pkg_platforms and platforms.get(pkg_platforms[0]): - platform = platforms[pkg_platforms[0]] - any_whl = select_whl( - whls = candidates, - python_version = platform.env.get("python_full_version", "3"), - whl_platform_tags = ["any"], - whl_abi_tags = ["none"], - implementation_name = platform.env.get("implementation_name", "cpython"), - limit = 1, - logger = logger, - ) - if any_whl: - entry["any_srcs"][any_whl.filename + any_whl.digest] = struct( - distribution = name, - extra_pip_args = extra_pip_args or [], - requirement_line = "{name}{extras}=={version}".format( - name = name, - extras = extra_str, - version = version, - ), - target_platforms = [], - filename = any_whl.filename, - digest = any_whl.digest, - url = any_whl.url, - yanked = None, - ) - plat_to_src = {} for p in pkg_platforms: platform = platforms.get(p) @@ -407,7 +368,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p for src in info["resolved_srcs"]: for p in src.target_platforms: resolved_platforms[p] = None - item = dict( + item = struct( name = norm_name, # Only expose packages that resolved on all configured platforms. # Workspace/root members (e.g. `source = { virtual = "." }` or @@ -423,11 +384,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p index_url = info["index_url"], srcs = info["resolved_srcs"], ) - if any_src: - # The platform independent wheel, if there is exactly one. - any_srcs = info["any_srcs"].values() - item["any_src"] = any_srcs[0] if len(any_srcs) == 1 else None - ret.append(struct(**item)) + ret.append(item) logger.debug(lambda: "Parsed {} packages from uv.lock".format(len(ret))) return ret diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index 2470cf79e1..0a5c319311 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -183,25 +183,7 @@ def _test_target_platforms_all(env): 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:deadb00f", "url": "https://files.pythonhosted.org/packages/plat-0.0.1-cp315-cp315-manylinux_2_17_x86_64.whl"}, - {"hash": "sha256:deadbeef", "url": "https://files.pythonhosted.org/packages/plat-0.0.1-py3-none-any.whl"}, - ], - }, - { - "name": "platonly", - "source": {"registry": "https://pypi.org/simple"}, - "version": "0.0.1", - "wheels": [ - {"hash": "sha256:deadbaaf", "url": "https://files.pythonhosted.org/packages/platonly-0.0.1-cp315-cp315-manylinux_2_17_x86_64.whl"}, - ], - }, - ]}), + "uv.lock": """{"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( @@ -214,39 +196,20 @@ def _test_target_platforms_all(env): ) pypi = builder.build() - # Only the packages that are available on all of the platforms are exposed. - pypi.exposed_packages().contains_exactly(["plat"]) + pypi.exposed_packages().contains_exactly(["simple"]) pypi.whl_map().contains_exactly({ - "plat": { - "pypi_315_plat_cp315_cp315_manylinux_2_17_x86_64_deadb00f": [ - whl_config_setting( - target_platforms = ("cp315_linux_x86_64",), - version = "3.15", - ), - ], - "pypi_315_plat_py3_none_any_deadbeef": [ + "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", ), - # The fallback for the platforms that are not configured. - whl_config_setting( - version = "3.15", - ), - ], - }, - # There is no platform independent wheel, so there is no fallback. - "platonly": { - "pypi_315_platonly_cp315_cp315_manylinux_2_17_x86_64_deadbaaf": [ - whl_config_setting( - target_platforms = ("cp315_linux_x86_64",), - version = "3.15", - ), ], }, }) From d499b587154d4e352a326a1a7268f90554afa92c Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:26:39 +0900 Subject: [PATCH 4/6] chore: rename the news entry to use the PR number --- news/{pip-target-platforms-all.added.md => 4455.added.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename news/{pip-target-platforms-all.added.md => 4455.added.md} (100%) diff --git a/news/pip-target-platforms-all.added.md b/news/4455.added.md similarity index 100% rename from news/pip-target-platforms-all.added.md rename to news/4455.added.md From f61d79070beebc6b6483ceadba227e66d141e518 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:43:07 +0900 Subject: [PATCH 5/6] test(pypi): select platform specific wheels with target_platforms = ["*"] --- tests/pypi/hub_builder/hub_builder_tests.bzl | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index 0a5c319311..c6c4f66ee9 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -216,6 +216,80 @@ def _test_target_platforms_all(env): _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", From b6a028060d91f1340cd697c7751695e9cfc2bd99 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 14 Nov 2026 16:00:07 -0800 Subject: [PATCH 6/6] docs(pypi): clarify default platforms and wrap test fixtures Clarify in docs and news that `target_platforms = ["*"]` selects all built-in default platforms in addition to custom `pip.default` platforms, and wrap `uv.lock` test fixtures within line-length limits. --- news/4455.added.md | 3 +- python/private/pypi/extension.bzl | 4 +- tests/pypi/hub_builder/hub_builder_tests.bzl | 66 +++++++++++++++----- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/news/4455.added.md b/news/4455.added.md index cb690ce07b..3af2fc29cb 100644 --- a/news/4455.added.md +++ b/news/4455.added.md @@ -1,2 +1,3 @@ (pypi) {attr}`pip.parse.target_platforms` accepts `"*"` to evaluate the -requirements for all of the platforms configured with {obj}`pip.default`. +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 908a40b90d..4e5863532a 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -906,8 +906,8 @@ 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 of the platforms configured with -{obj}`pip.default`. +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 ::: diff --git a/tests/pypi/hub_builder/hub_builder_tests.bzl b/tests/pypi/hub_builder/hub_builder_tests.bzl index c6c4f66ee9..fca32c5384 100644 --- a/tests/pypi/hub_builder/hub_builder_tests.bzl +++ b/tests/pypi/hub_builder/hub_builder_tests.bzl @@ -183,7 +183,21 @@ def _test_target_platforms_all(env): os_name = "osx", arch_name = "aarch64", mock_files = { - "uv.lock": """{"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"}]}]}""", + "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( @@ -223,21 +237,41 @@ def _test_target_platforms_all_platform_wheels(env): 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"}, - ], - }, - ]}), + "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(