fix(pypi): only expose uv.lock packages present on all platforms (#4444) Previously, `_parse_uv_lock_json` in `python/private/pypi/parse_requirements.bzl` set `is_exposed = bool(info["resolved_srcs"])`, which exposed any package that resolved on at least one configured platform in `all_requirements` / `all_whl_requirements`. When a `uv.lock` file included platform-specific dependencies (such as `pywin32-ctypes` on Windows), targets depending on `all_requirements` failed to build on other platforms with a `_no_matching_repository` error. Update `_parse_uv_lock_json` to compute `is_exposed` using `bool(all_platforms) and len(resolved_platforms) == len(all_platforms)`, matching the multi-platform exposure behavior of `_parse_requirements_from_req_files` when `requirements_by_platform` is used.
diff --git a/news/uv-lock-expose-all-platforms.fixed.md b/news/uv-lock-expose-all-platforms.fixed.md new file mode 100644 index 0000000..b4ae0a2 --- /dev/null +++ b/news/uv-lock-expose-all-platforms.fixed.md
@@ -0,0 +1,3 @@ +(pypi) Only include `uv.lock` packages in `all_requirements`, +`all_whl_requirements`, and `all_data_requirements` when they resolve across +all configured target platforms in {obj}`pip.parse`.
diff --git a/python/private/pypi/parse_requirements.bzl b/python/private/pypi/parse_requirements.bzl index 9782494..2d8c4b4 100644 --- a/python/private/pypi/parse_requirements.bzl +++ b/python/private/pypi/parse_requirements.bzl
@@ -364,16 +364,22 @@ ret = [] for norm_name, info in sorted(uv_packages.items()): versions = sorted(info["versions"].keys()) + resolved_platforms = {} + for src in info["resolved_srcs"]: + for p in src.target_platforms: + resolved_platforms[p] = None item = struct( name = norm_name, - # Only expose packages that resolved to at least one source. uv - # workspace/root members (e.g. `source = { virtual = "." }` or - # editable installs) resolve to no wheel/sdist, so exposing them - # would add a dangling entry to the hub's `all_requirements` / - # `all_whl_requirements` and create an alias to a subpackage that - # doesn't exist. This mirrors the requirements path, which also - # gates `is_exposed`. - is_exposed = bool(info["resolved_srcs"]), + # Only expose packages that resolved on all configured platforms. + # Workspace/root members (e.g. `source = { virtual = "." }` or + # editable installs) resolve to no wheel/sdist, and + # platform-specific packages only resolve on a subset of platforms; + # exposing either in `all_requirements` / `all_whl_requirements` + # would break builds on platforms where the package has no matching + # wheel/sdist. This mirrors the requirements file path. + is_exposed = bool(all_platforms) and ( + len(resolved_platforms) == len(all_platforms) + ), is_multiple_versions = len(versions) > 1, index_url = info["index_url"], srcs = info["resolved_srcs"],
diff --git a/tests/pypi/parse_requirements/parse_requirements_tests.bzl b/tests/pypi/parse_requirements/parse_requirements_tests.bzl index 148a51a..3838ad4 100644 --- a/tests/pypi/parse_requirements/parse_requirements_tests.bzl +++ b/tests/pypi/parse_requirements/parse_requirements_tests.bzl
@@ -1783,6 +1783,7 @@ ]), _uv_graph_package("uvloop", wheels = wheels, sdist = {"url": "https://example.org/uvloop-0.0.1.tar.gz"}), ]) + env.expect.that_bool(got["uvloop"].is_exposed).equals(False) env.expect.that_collection(got["uvloop"].srcs).has_size(1) env.expect.that_collection(got["uvloop"].srcs[0].target_platforms).contains_exactly(["linux_x86_64"]) @@ -1828,7 +1829,9 @@ # uv_lock_extras_map enables all extras, even when the edge requesting an # extra is limited to one platform. Optional edges still honor markers. for name in ["parent", "child", "leaf", "optional"]: + env.expect.that_bool(got[name].is_exposed).equals(True) env.expect.that_collection(got[name].srcs[0].target_platforms).contains_exactly(["linux_x86_64", "osx_aarch64"]) + env.expect.that_bool(got["linux_only"].is_exposed).equals(False) env.expect.that_collection(got["linux_only"].srcs[0].target_platforms).contains_exactly(["linux_x86_64"]) _tests.append(_test_uv_lock_all_extras)