feat(interpreter): add current_py_toolchain rule for Make variable support#897
feat(interpreter): add current_py_toolchain rule for Make variable support#897ctcjab wants to merge 4 commits intoaspect-build:mainfrom
Conversation
|
|
The pre-commit / conclusion GitHub Actions failures are unrelated to this PR — the workflow's checkout step tries to fetch The Buildkite CI (which does handle fork PRs correctly) is the relevant check here — it passed on the previous push after the bzl_library fix. |
|
https://github.com/bazel-contrib/rules_python/blob/d0b9baadc43eff92b3b9df0a04343e7ca653c44a/python/current_py_toolchain.bzl#L47 Hm. This is how rules_python does it too, which I don't love. I thought there was a way to associate the make vars directly with the toolchain type rather than having to have a wrapper rule which generates the variable info. |
|
There was a fix in Bazel 8.3.0 (bazelbuild/bazel@0e876b1, referenced in bazelbuild/bazel#14009) that allows The wrapper rule pattern (as used by |
|
In light of the above, is it worth merging this, and if Bazel ever provides something better rules_py can take advantage of that then? @arrdem @gregmagolan et al. |
|
cc @xangcastle |
|
Friendly bump (since I opened this a month ago and am hoping to avoid acquiring a merge conflict) - thanks in advance for any attention you can give this🙏 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 691ec6b122
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…pport (aspect-build#896) Provide $(PYTHON3) and $(PYTHON3_ROOTPATH) Make variables via a current_py_toolchain rule, enabling bazel_env and genrule integration without depending on rules_python. The rule is auto-instantiated in the python_interpreters hub repo at @python_interpreters//:current_py_toolchain, and also exported from @aspect_rules_py//py:defs.bzl for standalone use. Closes aspect-build#896 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The starlark_doc_extract rule (auto-generated by bzl_library) needs a bzl_library target for the private .bzl file, and the public bzl_library targets need to declare the dep. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use existing PY_TOOLCHAIN constant from types.bzl instead of
duplicating the toolchain type string
- Add fail() when py3_runtime has neither interpreter nor
interpreter_path
- Fix e2e test runfiles path to use ${TEST_SRCDIR}/_main/cases/...
pattern consistent with other e2e tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
691ec6b to
38e785a
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for the review @jbedard! I've addressed your feedback:
Also rebased on latest |


Summary
Closes #896.
Adds a
current_py_toolchainrule that resolves the active Python toolchain and exposes$(PYTHON3)and$(PYTHON3_ROOTPATH)Make variables viaTemplateVariableInfo. This enablesbazel_envandgenruleintegration without depending onrules_python.python_interpretershub repo at@python_interpreters//:current_py_toolchain@aspect_rules_py//py:defs.bzland@aspect_rules_py//py:current_py_toolchain.bzlfor standalone use$(PYTHON3)expansion viagenruleUsage
Test plan
//e2e/cases/current-py-toolchain-896:testpassesbuildifierandbuildifier-lintpass🤖 Generated with Claude Code