Repository navigation
refactor(toolchains): define the Python toolchain type in rules_python - #4404
Conversation
`//python:toolchain_type` is an alias of the type in `@bazel_tools`. To move the type out of `@bazel_tools`, Bazel will forward `@bazel_tools//tools/python:toolchain_type` to this target (bazelbuild/bazel#32412), which requires it to be the actual type on those Bazel versions. `//python:toolchain_type` is now a `toolchain_type` if a new value in the `@rules_python_internal` config is set and remains an alias otherwise, so both labels always refer to the same type. The `config` extension sets the value from a `bazel_features` flag, which is `False` for now, so nothing changes yet. WORKSPACE builds leave it unset, as Bazel versions that forward the type no longer support WORKSPACE. This also avoids requiring `bazel_features` in WORKSPACE builds. Depends on bazel-contrib/bazel_features#165.
|
This PR was prepared with an AI coding agent (Claude Code) at the author's request. No agent monitors this PR: the author handles review comments directly. This is an automatically generated agent comment. |
|
Would it be safe for Bazel to require rules_python 2+ in |
I'd have to go look at the notes. I think the big change in 2 was windows support requiring symlinks
SGTM; send a pr to the https://github.com/bazel-contrib/rules_python/tree/release/1.9 branch once this is merged |
Avoid inline conditional expressions and buildifier suppressions in python/BUILD.bazel by factoring the toolchain_type() vs alias() selection into a python_toolchain_type() helper macro.
Regenerate tests/integration/bzlmod_lockfile/MODULE.bazel.lock after bumping bazel_features to 1.55.0 and updating the config module extension.
|
By semver semantics this should probably be a 1.10.0 release rather than a 1.9.3, but if that would require more setup, it's probably fine as a patch release too. |
#4404) (#4521) Backports #4404 to `release/1.9`, as discussed on that PR, so that Bazel's `@bazel_tools` can depend on a 1.x release of rules_python. `//python:toolchain_type` is an alias of the type in `@bazel_tools`. To move the type out of `@bazel_tools`, Bazel will forward `@bazel_tools//tools/python:toolchain_type` to this target (bazelbuild/bazel#32412), which requires it to be the actual type on those Bazel versions. `//python:toolchain_type` is now a `toolchain_type` if a new value in the `@rules_python_internal` config is set and remains an alias otherwise, so both labels always refer to the same type. The `config` extension sets the value from a `bazel_features` flag, which is `False` for now, so nothing changes yet. WORKSPACE builds leave it unset, as Bazel versions that forward the type no longer support WORKSPACE. Differences from the commit on `main`: * The new `bzl_library` is named `python_toolchain_type_bzl` to follow this branch's naming convention. * The `tests/integration/bzlmod_lockfile` lockfile update is dropped, since that test does not exist on this branch. Work towards bazelbuild/bazel#32428 Co-authored-by: Richard Levasseur <richardlev@gmail.com>
//python:toolchain_typeis an alias of the type in@bazel_tools. To move the type out of@bazel_tools, Bazel will forward@bazel_tools//tools/python:toolchain_typeto this target (bazelbuild/bazel#32412), which requires it to be the actual type on those Bazel versions.//python:toolchain_typeis now atoolchain_typeif a new value in the@rules_python_internalconfig is set and remains an alias otherwise, so both labels always refer to the same type. Theconfigextension sets the value from abazel_featuresflag, which isFalsefor now, so nothing changes yet. WORKSPACE builds leave it unset, as Bazel versions that forward the type no longer support WORKSPACE. This also avoids requiringbazel_featuresin WORKSPACE builds.Work towards bazelbuild/bazel#32428