Skip to content

feat: make Python version project scoping opt-in - #4377

Open
Spikhalskiy wants to merge 6 commits into
bazel-contrib:mainfrom
Spikhalskiy:codex/python-project-scope
Open

Spikhalskiy wants to merge 6 commits into
bazel-contrib:mainfrom
Spikhalskiy:codex/python-project-scope

Conversation

@Spikhalskiy

@Spikhalskiy Spikhalskiy commented Oct 28, 2026 •

Copy link
Copy Markdown

Python version transitions also reach native dependencies that don't use Python, so a C++ or Rust library under bindings for several Python versions is configured once per version. Add a root-module config.python_version_scope(scope = "project") tag that gives //python/config_settings:python_version Bazel's project scope. Under project scope the public flag label becomes an alias to a flag in the generated config repository, whose PROJECT.scl delegates ownership to the consumer's //:PROJECT.scl through an actual alias. Targets outside it see the command-line version and share one configuration. Bazel reads the project file of every top-level target's package, so only the opt-in ships that alias, and other builds need no root PROJECT.scl. Universal scope stays the default, and tags from dependency modules are ignored.

Project scope requires Bazel 9.2 or later, the first release that keeps project-scoped flags across exec transitions (bazelbuild/bazel#28320). Owned exec tools such as the precompiler keep the selected version, which preserves the requirement behind #4335. Older Bazel versions fail with an explicit error.

aspect_rules_py terminals set this flag as well as their own; the matching opt-in there is aspect-build/rules_py#1650.

An integration test covers target and exec propagation, convergence of the native dependency's configuration, the unchanged default, and ignored dependency-module tags.

Fixes #4375

Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:49

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@aignas aignas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few questions, but in general LGTM.

Comment on lines +45 to +50
"active_directories": {
"default": [
"//bindings",
"@@rules_python+",
],
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about repositories that are created due to the pip.parse tag class? Does the @@rules_python+ means that those will be also included?

@@ -0,0 +1,35 @@
"""Analysis assertions for target and exec configuration propagation."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

probe.bzl is a very abstract name. Is there a way to make it more concrete?

@rickeylev

Copy link
Copy Markdown
Collaborator

Fabian has also brought up a desire to reign in config state explosion. The basic problem with using PROJECTS.scl is it means every end-user bazel project has to configure their own.

Would one of these options work better than this?

  • For the data attribute, reset all the python flags to their default
  • Provide a reset_python_flags() rule you can apply to targets e.g. to wrap around a cc library that is Python-agnostic.

It's somewhat tricky because a handful of flags matter, but not always (e.g. compiling LLVM doesn't care about python, but compiling a python C extension does).

`scope` accepts:

* `"universal"` (the default): the version reaches every target, including exec
tools such as the precompiler.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"such as the precompiler" -- is the precompiler ending up in multiple configs one of the motivations for this PR?

@aignas

aignas commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

The basic problem with using PROJECTS.scl is it means every end-user bazel project has to configure their own.

Good catch, that had not occured to me.

This branch has not been deployed

No deployments
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.

Support consumer-configured project scoping for python_version

4 participants