Skip to content

fix(bazel): run gen_builds on the pinned Python toolchain - #4579

Closed
ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/gen-builds-hermetic-python
Closed

ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/gen-builds-hermetic-python

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Problem

bazel run //scripts:bazel/gen_builds.py runs an exported source file through its shebang, so it uses the host python3. The generator needs Python 3.11+ (tomllib). On macOS's system 3.9 the documented command fails with ModuleNotFoundError: No module named 'tomllib'. A contributor who can't run it ends up with a Cargo.toml change and stale BUILD.bazel files (e.g. #4574).

Fix

  • Add py_binary(name = "gen_builds") so the generator runs on the rules_python toolchain (3.14 here).
  • Use BUILD_WORKSPACE_DIRECTORY for the repo root under bazel run, and fall back to the old __file__ resolution otherwise.
  • Point CI, AGENTS.md, CONTRIBUTING.md, the release lockfile script, and the generated BUILD headers at //scripts:gen_builds.

Verification

  • bazel run //scripts:gen_builds -- --check → all 60 generated BUILD.bazel files are current on a machine with only system Python 3.9.
  • scripts/test-neutralize-release-pr-closing-keywords.py passes.
  • scripts/test-gen-builds-default-alias.py passes under the toolchain Python. CI runs it with the runner's python3, unchanged.

🤖 Generated with Claude Code


Devin Review

`bazel run //scripts:bazel/gen_builds.py` executed an exported source
file through its `#!/usr/bin/env python3` shebang, so the generator ran
on whatever host python3 came first on PATH. The script needs 3.11+
(tomllib), and macOS ships 3.9, so the documented regeneration command
failed for anyone without a newer Python installed.

Wrap the generator in a `py_binary` like the other scripts so it runs on
the rules_python toolchain, root it at BUILD_WORKSPACE_DIRECTORY when
`bazel run` sets it, and point CI, docs, and the generated headers at
`//scripts:gen_builds`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d1c0917

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) October 27, 2026 02:50
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Superseded by #4543, which landed the same fix more completely: //scripts:gen_builds is now a py_binary on the pinned Python toolchain, with its Cargo inputs bundled and BUILD_WORKSPACE_DIRECTORY validated. bazel run //scripts:gen_builds -- --check passes on master.

auto-merge was automatically disabled October 27, 2026 08:28

Pull request was closed

@ScriptedAlchemy
ScriptedAlchemy deleted the fix/gen-builds-hermetic-python branch October 27, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant