Skip to content

refactor(toolchains): define the Python toolchain type in rules_python - #4404

Merged
rickeylev merged 5 commits into
bazel-contrib:mainfrom
fmeum:python-toolchain-type
Nov 9, 2026
Merged

rickeylev merged 5 commits into
bazel-contrib:mainfrom
fmeum:python-toolchain-type

Conversation

@fmeum

@fmeum fmeum commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

//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.

Work towards bazelbuild/bazel#32428

`//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.
@fmeum

fmeum commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

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.

Comment thread python/private/internal_config_repo.bzl Resolved
@fmeum
fmeum marked this pull request as ready for review November 9, 2026 16:24
@fmeum

fmeum commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

cc @meteorcloudy

@fmeum

fmeum commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Would it be safe for Bazel to require rules_python 2+ in @bazel_tools? If not, could this be cherry-picked into a 1.X release?

@rickeylev

Copy link
Copy Markdown
Collaborator

Would it be safe for Bazel to require rules_python 2+ in @bazel_tools?

I'd have to go look at the notes. I think the big change in 2 was windows support requiring symlinks

could this be cherry-picked into a 1.X release?

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.
Comment thread MODULE.bazel Resolved
Regenerate tests/integration/bzlmod_lockfile/MODULE.bazel.lock after bumping bazel_features to 1.55.0 and updating the config module extension.
@rickeylev
rickeylev enabled auto-merge November 9, 2026 17:17
@fmeum

fmeum commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

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.

@rickeylev
rickeylev added this pull request to the merge queue Nov 9, 2026
Merged via the queue into bazel-contrib:main with commit 1bf79e9 Nov 9, 2026
11 checks passed
@fmeum
fmeum deleted the python-toolchain-type branch November 17, 2026 11:29
aignas pushed a commit that referenced this pull request Nov 17, 2026
#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>
@rickeylev rickeylev mentioned this pull request Nov 18, 2026
3 tasks
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.

2 participants