Skip to content

refactor: parse the Python versions with pypackaging.bzl - #4563

Open
aignas wants to merge 9 commits into
refactor.aignas.pypackaging-06-markersfrom
refactor.aignas.pypackaging-07-python-versions
Open

aignas wants to merge 9 commits into
refactor.aignas.pypackaging-06-markersfrom
refactor.aignas.pypackaging-07-python-versions

Conversation

@aignas

@aignas aignas commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Use pypackaging.version and pypackaging.specifiers instead of
version.bzl in the toolchain code. Invalid PEP 440 versions are now
errors everywhere, which changes the message of the python_version
validation in the python extension.

py_library and py_runtime are not changed, because they are loaded
by the Bazel 8 autoloads and cannot load from the pypackaging.bzl
repository, see #4569.

The code under python/private/pypi and py_wheel is migrated
separately.

Use `pypackaging.version` and `pypackaging.specifiers` instead of
`version.bzl` in the toolchain and the rule code. Invalid PEP 440
versions are now errors everywhere, which changes the message of the
`python_version` validation in the `python` extension.

The code under `python/private/pypi` and `py_wheel` is migrated
separately.
@aignas

aignas commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

This PR was prepared by an AI agent (Claude Code) on behalf of @aignas. The agent replies to the review comments and pushes the fixes, @aignas supervises it and reviews the changes.

This is an agent-generated comment unreviewed by the user.

They are loaded by the files that Bazel 8 autoloads, which cannot load
from the pypackaging.bzl repository.
@aignas
aignas added this pull request to stack #4570 November 22, 2026 04:18
@aignas
aignas marked this pull request as ready for review November 22, 2026 08:41
@aignas
aignas requested a review from rickeylev as a code owner November 22, 2026 08:41
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Version API migration

Layer / File(s) Summary
Configuration and runtime version parsing
python/private/BUILD.bazel, python/private/config_settings.bzl, python/private/hermetic_runtime_repo_setup.bzl
These modules replace the private version dependency with pypackaging. Configuration version selection and runtime version parsing use pypackaging version APIs.
Toolchain version validation and ordering
python/private/BUILD.bazel, python/private/python.bzl, tests/python/python_tests.bzl, tests/toolchains/defs.bzl, tests/toolchains/multi_platform_resolution/resolution_tests.bzl
Toolchain version parsing, validation, grouping, and sorting use pypackaging. Test helpers and the expected invalid-version message are updated.
Requires-Python parsing
python/private/BUILD.bazel, python/private/pyproject_utils.bzl
Requires-Python parsing uses pypackaging specifiers and requires exactly one non-wildcard equality specifier.

Possibly related PRs

Suggested reviewers: golithe, gfrankliu

Change: Refactor

Merge Risk: Minimal · up to d8016

This change moves Python version parsing in the toolchain code to pypackaging.bzl and changes one validation error message. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to d8016

The change can cause previously tolerated version strings to fail during build configuration. The inspected paths still use the same controls for who can choose the default runtime and which runtime candidates can be selected.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The direct exposure is to Bazel builds using the migrated settings or runtime selectors. Changed parsing can reject configuration input, and changed ordering can affect the preference among registered host-compatible candidates. The ranking step does not make a host-incompatible runtime eligible.

Trust Boundaries and Controls

  • observed — The user-settable flag remains the original string flag. The derived major/minor setting still cannot be set directly from the command line, and the override handler remains root-only.

Hardening Proposals

  • proposed — Check the pinned parser in both Bazel dependency modes, with explicit expected runtime selections for supported noncanonical and prerelease versions. Keep those expectations independent of the production comparison key so a change in ordering can be detected.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e3317785-bac7-4afe-87a5-2b1e64dce562
Commits

Reviewing files that changed from the base of the PR and between c55d291 and d80168b.

Files selected for processing: 8

  • python/private/BUILD.bazel
  • python/private/config_settings.bzl
  • python/private/hermetic_runtime_repo_setup.bzl
  • python/private/pyproject_utils.bzl
  • python/private/python.bzl
  • tests/python/python_tests.bzl
  • tests/toolchains/defs.bzl
  • tests/toolchains/multi_platform_resolution/resolution_tests.bzl

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

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.

2 participants