-
-
Notifications
You must be signed in to change notification settings - Fork 98
feat(uv): parameterize the platform parent in gazelle_python_manifest #1470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff60856
feat(uv): parameterize the platform parent in gazelle_python_manifest
sallustfire cb106fd
refactor(uv): move gazelle manifest tooling into a tools/ subpackage
xangcastle 7414b58
refactor(uv): make gazelle_python_manifest platform_parent a single l…
xangcastle 201d27a
test(uv): pin wheel selection under the cross-compiled platform_parent
xangcastle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| load("@aspect_rules_py//uv:defs.bzl", "gazelle_python_manifest") | ||
| load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") | ||
| load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
| load(":wheel_selection_probe.bzl", "wheel_selection_probe") | ||
|
|
||
| # Regression test for `gazelle_python_manifest(platform_parent = ...)` | ||
| # (issue #1416: the macro's synthetic per-venv platforms were pinned to | ||
| # `@platforms//host`, breaking cross-compilation and custom host platforms). | ||
| # Reads from the //uv-deps-650 hub, which already declares an `extras` venv. | ||
| # | ||
| # Documented exception to per-case isolation: this test applies Gazelle to a | ||
| # venv from another case (//uv-deps-650), so the cross-case reference is by | ||
| # design. | ||
| package(default_visibility = ["//:__pkg__"]) | ||
|
|
||
| # A case-local constraint that only `:parent_platform` carries: observing it | ||
| # downstream proves the macro-generated platform inherited from | ||
| # `:parent_platform`. | ||
| constraint_setting(name = "parentage") | ||
|
|
||
| constraint_value( | ||
| name = "custom_parent", | ||
| constraint_setting = ":parentage", | ||
| ) | ||
|
|
||
| # Stands in for a cross-compilation target platform (issue #1416's scenario): | ||
| # fully specified rather than parented on `@platforms//host`, so wheel | ||
| # selection under the macro's synthetic platform resolves identically on | ||
| # every host and the goldens below are host-invariant. The libc flags ride on | ||
| # the platform because their defaults are detected from the host: without | ||
| # them, manylinux config_settings never match on a non-linux host and every | ||
| # native package silently degrades to its sdist fallback — the same config | ||
| # chimera the issue describes. This doubles as the documented recipe for | ||
| # real cross-compilation parents. | ||
| platform( | ||
| name = "parent_platform", | ||
| constraint_values = [ | ||
| ":custom_parent", | ||
| "@platforms//cpu:x86_64", | ||
| "@platforms//os:linux", | ||
| ], | ||
| flags = [ | ||
| "--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc", | ||
| "--@aspect_rules_py//uv/private/constraints/platform:platform_version=2.28", | ||
| ], | ||
| ) | ||
|
|
||
| gazelle_python_manifest( | ||
| name = "gazelle_python_manifest", | ||
| hub = "pypi_uv_deps_650", | ||
| platform_parent = ":parent_platform", | ||
| venvs = ["extras"], | ||
| ) | ||
|
|
||
| # The manifest YAML content itself is platform-independent (same module | ||
| # mapping regardless of which wheel variant was indexed), so a golden on it | ||
| # would only re-pin the hub's dependency set. Building it end-to-end is the | ||
| # signal: the generator action consumes wheels selected for the linux parent | ||
| # on whatever host runs the test. | ||
| build_test( | ||
| name = "manifest_build_test", | ||
| targets = [":gazelle_python_manifest"], | ||
| ) | ||
|
|
||
| # The macro generates a synthetic platform named `_{name}_{hub}_{venv}` in | ||
| # this package; `:probe` depends on that naming scheme, so a rename inside the | ||
| # macro breaks this target with a missing-target analysis error. | ||
| # | ||
| # The snapshot pins "custom-parent": if the macro ignores `platform_parent`, | ||
| # the generated platform loses `:custom_parent`, the select falls through to | ||
| # "default-parent", and the snapshot diff test fails. | ||
| config_setting( | ||
| name = "under_custom_parent", | ||
| constraint_values = [":custom_parent"], | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "probe_src", | ||
| outs = ["probe_out.txt"], | ||
| cmd = select({ | ||
| ":under_custom_parent": "echo custom-parent > $@", | ||
| "//conditions:default": "echo default-parent > $@", | ||
| }), | ||
| ) | ||
|
|
||
| platform_transition_filegroup( | ||
| name = "probe", | ||
| srcs = [":probe_src"], | ||
| target_platform = ":_gazelle_python_manifest_pypi_uv_deps_650_extras", | ||
| ) | ||
|
|
||
| # Second probe, at the level the bug actually manifested (#1416): pins that | ||
| # wheel *selection* follows the parent. Transitions the hub's index filegroup | ||
| # through the same macro-generated platform and snapshots which wheel variant | ||
| # each dependency resolved to — native packages must come out `linux_x86_64`, | ||
| # never the host's, and never an sdist fallback. The constraint probe above | ||
| # discriminates on any host; this one additionally fails if selection snaps | ||
| # back to the host on non-linux-x86_64 hosts, or if a lock change quietly | ||
| # drops a dependency to an sdist fallback for the cross-compiled platform. | ||
| platform_transition_filegroup( | ||
| name = "selected_whls", | ||
| srcs = ["@pypi_uv_deps_650//:gazelle_index_whls"], | ||
| target_platform = ":_gazelle_python_manifest_pypi_uv_deps_650_extras", | ||
| ) | ||
|
|
||
| wheel_selection_probe( | ||
| name = "wheel_selection", | ||
| src = ":selected_whls", | ||
| ) |
48 changes: 48 additions & 0 deletions
48
e2e/cases/gazelle-platform-parents-1416/wheel_selection_probe.bzl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Analysis-time probe over a hub's `gazelle_index_whls` filegroup. | ||
|
|
||
| Writes one `distribution: platform-class` line per resolved wheel, so a | ||
| snapshot can pin *which kind* of wheel the configuration selected (e.g. | ||
| `cffi: linux_x86_64`) without materializing the wheels and without coupling | ||
| the golden to exact versions or manylinux tag spellings, both of which churn | ||
| on lock updates. Classification happens at analysis time from basenames, so | ||
| the probe never triggers sdist builds for the transitioned platform. | ||
| """ | ||
|
|
||
| def _classify_platform_tag(basename): | ||
| tag = basename[:-len(".whl")].split("-")[-1] | ||
| if tag == "any": | ||
| return "any" | ||
| os = "unknown-os" | ||
| if "linux" in tag: | ||
| os = "linux" | ||
| elif "macosx" in tag: | ||
| os = "macosx" | ||
| elif "win" in tag: | ||
| os = "windows" | ||
| cpu = "unknown-cpu" | ||
| if "universal2" in tag: | ||
| cpu = "universal2" | ||
| elif "x86_64" in tag or "amd64" in tag: | ||
| cpu = "x86_64" | ||
| elif "aarch64" in tag or "arm64" in tag: | ||
| cpu = "aarch64" | ||
| return "{}_{}".format(os, cpu) | ||
|
|
||
| def _wheel_selection_probe_impl(ctx): | ||
| out = ctx.actions.declare_file(ctx.label.name + ".txt") | ||
| lines = [] | ||
| for f in ctx.attr.src[DefaultInfo].files.to_list(): | ||
| if f.basename.endswith(".whl"): | ||
| dist = f.basename.split("-")[0].lower() | ||
| lines.append("{}: {}".format(dist, _classify_platform_tag(f.basename))) | ||
| elif f.basename == "whl": | ||
| lines.append("{}: sdist-fallback".format(f.owner.repo_name)) | ||
| ctx.actions.write(out, "\n".join(sorted(lines)) + "\n") | ||
| return [DefaultInfo(files = depset([out]))] | ||
|
|
||
| wheel_selection_probe = rule( | ||
| implementation = _wheel_selection_probe_impl, | ||
| attrs = { | ||
| "src": attr.label(providers = [DefaultInfo]), | ||
| }, | ||
| ) | ||
1 change: 1 addition & 0 deletions
1
e2e/cases/snapshots/gazelle_platform_parents_1416.probe_out.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
e2e/cases/snapshots/gazelle_platform_parents_1416.wheel_selection.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| load("//py:defs.bzl", "py_binary") | ||
|
|
||
| exports_files(["update.sh"]) | ||
|
|
||
| exports_files( | ||
| ["generate.py"], | ||
| visibility = ["//uv/private/gazelle_manifest/tests:__pkg__"], | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "generator", | ||
| srcs = [ | ||
| "generate.py", | ||
| ], | ||
| main = "generate.py", | ||
| visibility = ["//uv/private/gazelle_manifest:__pkg__"], | ||
| ) |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.