Skip to content

Commit 0e93efb

Browse files
committed
fix(bzlmod)!: support X.Y or X.Y.Z versions in python.toolchain
Before this PR the `bzlmod` example would only work if the Python interpreter version is specified in the `X.Y` format. However, users may desire to use the full version (`X.Y.Z`) for reproducibility reasons and expect everything to continue to work. This fixes the versions used everywhere by leveraging functionality introduced in #1328 and fixes the `python_versions` to always contain `@python_versions//X.Y:defs.bzl` imports. NOTE, #1328 also fixed the case where the Python-version specific `pip` hub repos would be named `<hub_name>_XYZ` as opposed to the `<hub_name>_XY`, which is expected across the codebase. Breaking for `bzlmod` users who previously used `@python_versions//X.Y.Z:defs.bzl` in their BUILD.bazel files and/or depended on the `@pip_XYZ//:requirements.bzl`. This essentially limits the users of the `@python_versions` to a single `X.Y` toolchain version, whilst the full functionality should still be available by using the `python_version` parameter in the `py_binary` and `py_library` rules. Fixes #1339.
1 parent bb7004b commit 0e93efb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

examples/bzlmod/MODULE.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ python.toolchain(
3232
# work in progress.
3333
python.toolchain(
3434
configure_coverage_tool = True,
35-
python_version = "3.10",
35+
# One can also provide the full Python version.
36+
python_version = "3.10.9",
3637
)
3738

3839
# You only need to load this repositories if you are using multiple Python versions.

python/extensions/python.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("//python:repositories.bzl", "python_register_toolchains")
1818
load("//python/extensions/private:pythons_hub.bzl", "hub_repo")
1919
load("//python/private:toolchains_repo.bzl", "multi_toolchain_aliases")
20+
load("//python/private:version_label.bzl", "version_label")
2021

2122
# This limit can be increased essentially arbitrarily, but doing so will cause a rebuild of all
2223
# targets using any of these toolchains due to the changed repository name.
@@ -75,7 +76,7 @@ def _python_impl(module_ctx):
7576

7677
for toolchain_attr in mod.tags.toolchain:
7778
toolchain_version = toolchain_attr.python_version
78-
toolchain_name = "python_" + toolchain_version.replace(".", "_")
79+
toolchain_name = "python_" + version_label(toolchain_version, sep = "_")
7980

8081
# Duplicate versions within a module indicate a misconfigured module.
8182
if toolchain_version in module_toolchain_versions:
@@ -165,7 +166,9 @@ def _python_impl(module_ctx):
165166
multi_toolchain_aliases(
166167
name = "python_versions",
167168
python_versions = {
168-
version: entry.toolchain_name
169+
# NOTE @aignas 2023-07-24: we are effectively using the
170+
# version_label function to drop the patch version information.
171+
version_label(version, sep = "."): entry.toolchain_name
169172
for version, entry in global_toolchain_versions.items()
170173
},
171174
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy