Skip to content

refactor: make python extension generate platform toolchains #2875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rickeylev
Copy link
Collaborator

@rickeylev rickeylev commented May 13, 2025

This makes the python bzlmod extension handle generating the platform-specific toolchain
entries ("python_3_10_{platform}"). This is to eventually allow adding additional
toolchains that aren't part of the PLATFORMS mapping in versions.bzl and have
their own custom constraints.

The main things this refactor does are:

  1. The bzlmod phase passes the full list of implementation toolchains
    to create (previously, it relied on hub_repo to generate the implementation
    names).
  2. The name of a toolchain (the toolchain.name arg) and the repo that implements
    it (the py_toolchain_suite.user_repository_repo arg) are separate. This allows
    future work to mixin toolchains that point to arbitrary repos.
  3. The platform meta data uses a list of target settings instead of dict of
    flag values. This allows more arbitrary target settings. For now, flag values
    on the platform metadata is still looked for because it's known that users
    patch python/versions.bzl.

Along the way:

  • Factor out a platform_info helper in versions.bzl
  • Factor out a NOT_ACTUALLY_PUBLIC constants to better denote things that
    are public visibility, but actually internal.
  • Add some docs to some internals so we don't have to chase down their definitions.

Work towards #2081

@rickeylev rickeylev requested a review from aignas as a code owner May 13, 2025 04:45
@rickeylev rickeylev force-pushed the refactor.python.bzlmod.toolchain.rendering branch 2 times, most recently from 096a3e2 to e2c82f2 Compare May 13, 2025 04:58
@rickeylev rickeylev marked this pull request as draft May 13, 2025 18:47
@rickeylev
Copy link
Collaborator Author

I want to cross check the generated BUILD files for toolchains to make sure they're the same semantically, so moving back to draft until I do so. From a cursory look, they look OK, but I changed the order of args, prefix length, etc, so the diff is pretty big. Gonna back those out to make it easier to compare them.

@rickeylev rickeylev force-pushed the refactor.python.bzlmod.toolchain.rendering branch from e2c82f2 to 52f2b5d Compare May 13, 2025 19:16
@rickeylev
Copy link
Collaborator Author

Manually verified the registrations: they're OK. I tweaked the code a bit so it better matches the original ordering and naming. Ready for review.

@rickeylev rickeylev marked this pull request as ready for review May 13, 2025 19:19
Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Outside the scope of this PR, but I would love at some point to start registering the platform values in bazel-mod in the same way that they are done for uv.

@rickeylev rickeylev added this pull request to the merge queue May 13, 2025
Merged via the queue into bazel-contrib:main with commit 367d09e May 13, 2025
3 checks passed
@rickeylev rickeylev deleted the refactor.python.bzlmod.toolchain.rendering branch May 14, 2025 03:39
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