Skip to content
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

feat(toolchains): expose the //python/config_settings:python_version_major_minor #2275

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ A brief description of the categories of changes:
### Added
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
compression to speed up development.
* (toolchains): A public `//python/config_settings:python_version_major_minor` has
been exposed for users to be able to match on the `X.Y` version of a Python
interpreter.

### Removed
* Nothing yet
Expand Down
4 changes: 4 additions & 0 deletions docs/api/rules_python/python/config_settings/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Determines the default hermetic Python toolchain version. This can be set to
one of the values that `rules_python` maintains.
:::

:::{bzl:target} python_version_major_minor
Parses the value of the `python_version` and transforms it into a `X.Y` value.
:::

::::{bzl:flag} exec_tools_toolchain
Determines if the {obj}`exec_tools_toolchain_type` toolchain is enabled.

Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/private/config_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(":semver.bzl", "semver")

_PYTHON_VERSION_FLAG = Label("//python/config_settings:python_version")
_PYTHON_VERSION_MAJOR_MINOR_FLAG = Label("//python/config_settings:_python_version_major_minor")
_PYTHON_VERSION_MAJOR_MINOR_FLAG = Label("//python/config_settings:python_version_major_minor")

def construct_config_settings(*, name, default_version, versions, minor_mapping): # buildifier: disable=function-docstring
"""Create a 'python_version' config flag and construct all config settings used in rules_python.
Expand Down
2 changes: 1 addition & 1 deletion python/private/pypi/config_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def config_settings(
native.config_setting(
name = is_python,
flag_values = {
Label("//python/config_settings:_python_version_major_minor"): python_version,
Label("//python/config_settings:python_version_major_minor"): python_version,
},
visibility = visibility,
)
Expand Down
2 changes: 1 addition & 1 deletion python/private/pypi/generate_whl_library_build_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _render_config_settings(dependencies_by_platform):
config_setting(
name = "is_{name}",
flag_values = {{
"@rules_python//python/config_settings:_python_version_major_minor": "3.{minor_version}",
"@rules_python//python/config_settings:python_version_major_minor": "3.{minor_version}",
}},
constraint_values = {constraint_values},
visibility = ["//visibility:private"],
Expand Down
6 changes: 3 additions & 3 deletions tests/config_settings/construct_config_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
"@platforms//os:" + os,
],
flag_values = {
"//python/config_settings:_python_version_major_minor": "3.11",
"//python/config_settings:python_version_major_minor": "3.11",
},
)

Expand All @@ -178,7 +178,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
"@platforms//cpu:" + cpu,
],
flag_values = {
"//python/config_settings:_python_version_major_minor": "3.11",
"//python/config_settings:python_version_major_minor": "3.11",
},
)

Expand All @@ -198,7 +198,7 @@ def construct_config_settings_test_suite(name): # buildifier: disable=function-
"@platforms//os:" + os,
],
flag_values = {
"//python/config_settings:_python_version_major_minor": "3.11",
"//python/config_settings:python_version_major_minor": "3.11",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ py_library(
config_setting(
name = "is_python_3.10_linux_ppc",
flag_values = {
"@rules_python//python/config_settings:_python_version_major_minor": "3.10",
"@rules_python//python/config_settings:python_version_major_minor": "3.10",
},
constraint_values = [
"@platforms//cpu:ppc",
Expand All @@ -172,7 +172,7 @@ config_setting(
config_setting(
name = "is_python_3.9_anyos_aarch64",
flag_values = {
"@rules_python//python/config_settings:_python_version_major_minor": "3.9",
"@rules_python//python/config_settings:python_version_major_minor": "3.9",
},
constraint_values = ["@platforms//cpu:aarch64"],
visibility = ["//visibility:private"],
Expand All @@ -181,7 +181,7 @@ config_setting(
config_setting(
name = "is_python_3.9_linux_anyarch",
flag_values = {
"@rules_python//python/config_settings:_python_version_major_minor": "3.9",
"@rules_python//python/config_settings:python_version_major_minor": "3.9",
},
constraint_values = ["@platforms//os:linux"],
visibility = ["//visibility:private"],
Expand Down