Skip to content

Commit 30fc3f9

Browse files
authored
feat(toolchains): expose the //python/config_settings:python_version_major_minor (bazel-contrib#2275)
With this change the users can simply reuse our internal flag that will correctly report the `X.Y` version in `select` statements. If users previously depended on now removed `is_python_config_setting` now they have an alternative. Followup to bazel-contrib#2253
1 parent 33fa845 commit 30fc3f9

File tree

8 files changed

+18
-11
lines changed

8 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ A brief description of the categories of changes:
4444
### Added
4545
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
4646
compression to speed up development.
47+
* (toolchains): A public `//python/config_settings:python_version_major_minor` has
48+
been exposed for users to be able to match on the `X.Y` version of a Python
49+
interpreter.
4750

4851
### Removed
4952
* Nothing yet

docs/api/rules_python/python/config_settings/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Determines the default hermetic Python toolchain version. This can be set to
1010
one of the values that `rules_python` maintains.
1111
:::
1212

13+
:::{bzl:target} python_version_major_minor
14+
Parses the value of the `python_version` and transforms it into a `X.Y` value.
15+
:::
16+
1317
::::{bzl:flag} exec_tools_toolchain
1418
Determines if the {obj}`exec_tools_toolchain_type` toolchain is enabled.
1519

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/config_settings.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
2020
load(":semver.bzl", "semver")
2121

2222
_PYTHON_VERSION_FLAG = Label("//python/config_settings:python_version")
23-
_PYTHON_VERSION_MAJOR_MINOR_FLAG = Label("//python/config_settings:_python_version_major_minor")
23+
_PYTHON_VERSION_MAJOR_MINOR_FLAG = Label("//python/config_settings:python_version_major_minor")
2424

2525
def construct_config_settings(*, name, default_version, versions, minor_mapping): # buildifier: disable=function-docstring
2626
"""Create a 'python_version' config flag and construct all config settings used in rules_python.

python/private/pypi/config_settings.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def config_settings(
116116
native.config_setting(
117117
name = is_python,
118118
flag_values = {
119-
Label("//python/config_settings:_python_version_major_minor"): python_version,
119+
Label("//python/config_settings:python_version_major_minor"): python_version,
120120
},
121121
visibility = visibility,
122122
)

python/private/pypi/generate_whl_library_build_bazel.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _render_config_settings(dependencies_by_platform):
162162
config_setting(
163163
name = "is_{name}",
164164
flag_values = {{
165-
"@rules_python//python/config_settings:_python_version_major_minor": "3.{minor_version}",
165+
"@rules_python//python/config_settings:python_version_major_minor": "3.{minor_version}",
166166
}},
167167
constraint_values = {constraint_values},
168168
visibility = ["//visibility:private"],

tests/config_settings/construct_config_settings_tests.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
167167
"@platforms//os:" + os,
168168
],
169169
flag_values = {
170-
"//python/config_settings:_python_version_major_minor": "3.11",
170+
"//python/config_settings:python_version_major_minor": "3.11",
171171
},
172172
)
173173

@@ -178,7 +178,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
178178
"@platforms//cpu:" + cpu,
179179
],
180180
flag_values = {
181-
"//python/config_settings:_python_version_major_minor": "3.11",
181+
"//python/config_settings:python_version_major_minor": "3.11",
182182
},
183183
)
184184

@@ -198,7 +198,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
198198
"@platforms//os:" + os,
199199
],
200200
flag_values = {
201-
"//python/config_settings:_python_version_major_minor": "3.11",
201+
"//python/config_settings:python_version_major_minor": "3.11",
202202
},
203203
)
204204

tests/pypi/generate_whl_library_build_bazel/generate_whl_library_build_bazel_tests.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ py_library(
160160
config_setting(
161161
name = "is_python_3.10_linux_ppc",
162162
flag_values = {
163-
"@rules_python//python/config_settings:_python_version_major_minor": "3.10",
163+
"@rules_python//python/config_settings:python_version_major_minor": "3.10",
164164
},
165165
constraint_values = [
166166
"@platforms//cpu:ppc",
@@ -172,7 +172,7 @@ config_setting(
172172
config_setting(
173173
name = "is_python_3.9_anyos_aarch64",
174174
flag_values = {
175-
"@rules_python//python/config_settings:_python_version_major_minor": "3.9",
175+
"@rules_python//python/config_settings:python_version_major_minor": "3.9",
176176
},
177177
constraint_values = ["@platforms//cpu:aarch64"],
178178
visibility = ["//visibility:private"],
@@ -181,7 +181,7 @@ config_setting(
181181
config_setting(
182182
name = "is_python_3.9_linux_anyarch",
183183
flag_values = {
184-
"@rules_python//python/config_settings:_python_version_major_minor": "3.9",
184+
"@rules_python//python/config_settings:python_version_major_minor": "3.9",
185185
},
186186
constraint_values = ["@platforms//os:linux"],
187187
visibility = ["//visibility:private"],

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