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 2 commits intoaspect-build:mainfrom
Conversation
…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>
|
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 |

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