Skip to content

Commit 2ee80c3

Browse files
committed
fix(bzlmod): generate config_setting values for all python toolchains (#2350)
PR #2253 broke how the config settings are generated and only generated the config setting values for the python version values that we would have the registered toolchains for. This PR restores the previous behaviour. However, if the root module uses `python.override` to remove the allowed toolchains, then `config_settings` will be also affected. (cherry picked from commit 9340a81) Conflicts: - CHANGELOG.md
1 parent 8c3acea commit 2ee80c3

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ A brief description of the categories of changes:
2020
* Particular sub-systems are identified using parentheses, e.g. `(bzlmod)` or
2121
`(docs)`.
2222

23+
{#v0-0-0}
2324
## Unreleased
2425

26+
[0.0.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.0.0
27+
2528
### Changed
2629
- Nothing yet
2730

@@ -34,6 +37,17 @@ A brief description of the categories of changes:
3437
### Removed
3538
- Nothing yet
3639

40+
{#v0-37-2}
41+
## [0.37.2] - 2024-10-27
42+
43+
[0.37.2]: https://github.com/bazelbuild/rules_python/releases/tag/0.37.2
44+
45+
{#v0-37-2-fixed}
46+
### Fixed
47+
* (bzlmod) Generate `config_setting` values for all available toolchains instead
48+
of only the registered toolchains, which restores the previous behaviour that
49+
`bzlmod` users would have observed.
50+
3751
{#v0-37-1}
3852
## [0.37.1] - 2024-10-22
3953

examples/multi_python_versions/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ python.toolchain(
3030
)
3131
use_repo(
3232
python,
33+
"pythons_hub",
3334
python = "python_versions",
3435
)
3536

examples/multi_python_versions/tests/BUILD.bazel

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
2+
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
3+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
24
load("@python//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test")
35
load("@python//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test")
46
load("@python//3.8:defs.bzl", py_binary_3_8 = "py_binary", py_test_3_8 = "py_test")
57
load("@python//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
8+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
69
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
10+
load("@rules_python//python:versions.bzl", DEFAULT_MINOR_MAPPING = "MINOR_MAPPING", DEFAULT_TOOL_VERSIONS = "TOOL_VERSIONS")
11+
load("@rules_python//python/private:text_util.bzl", "render") # buildifier: disable=bzl-visibility
712
load("@rules_shell//shell:sh_test.bzl", "sh_test")
813

914
copy_file(
@@ -183,3 +188,37 @@ sh_test(
183188
"VERSION_PY_BINARY": "$(rootpath :version_3_10)",
184189
},
185190
)
191+
192+
# The following test ensures that default toolchain versions are the same as in
193+
# the TOOL_VERSIONS array.
194+
195+
# NOTE @aignas 2024-10-26: This test here is to do a sanity check and not
196+
# include extra dependencies - if rules_testing is included here, we can
197+
# potentially uses `rules_testing` for a more lightweight test.
198+
write_file(
199+
name = "default_python_versions",
200+
out = "default_python_versions.txt",
201+
content = [
202+
"MINOR_MAPPING:",
203+
render.dict(dict(sorted(DEFAULT_MINOR_MAPPING.items()))),
204+
"PYTHON_VERSIONS:",
205+
render.list(sorted(DEFAULT_TOOL_VERSIONS)),
206+
],
207+
)
208+
209+
write_file(
210+
name = "pythons_hub_versions",
211+
out = "pythons_hub_versions.txt",
212+
content = [
213+
"MINOR_MAPPING:",
214+
render.dict(dict(sorted(MINOR_MAPPING.items()))),
215+
"PYTHON_VERSIONS:",
216+
render.list(sorted(PYTHON_VERSIONS)),
217+
],
218+
)
219+
220+
diff_test(
221+
name = "test_versions",
222+
file1 = "default_python_versions",
223+
file2 = "pythons_hub_versions",
224+
)

python/private/python.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def _python_impl(module_ctx):
241241
# Last toolchain is default
242242
default_python_version = py.default_python_version,
243243
minor_mapping = py.config.minor_mapping,
244+
python_versions = list(py.config.default["tool_versions"].keys()),
244245
toolchain_prefixes = [
245246
render.toolchain_prefix(index, toolchain.name, _TOOLCHAIN_INDEX_PAD_LENGTH)
246247
for index, toolchain in enumerate(py.toolchains)

0 commit comments

Comments
 (0)