Skip to content

Commit 2f04951

Browse files
authored
docs: document the is_python config settings (#2336)
This documents the `//python/config_settings:is_python_*` config settings. It adds a disclaimer that the available targets may vary depending on the root module settings, and tells users how to match versions when one isn't available.
1 parent 9340a81 commit 2f04951

File tree

1 file changed

+38
-0
lines changed
  • docs/api/rules_python/python/config_settings

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,44 @@ one of the values that `rules_python` maintains.
3333
Parses the value of the `python_version` and transforms it into a `X.Y` value.
3434
:::
3535

36+
:::{bzl:target} is_python_*
37+
config_settings to match Python versions
38+
39+
The name pattern is `is_python_X.Y` (to match major.minor) and `is_python_X.Y.Z`
40+
(to match major.minor.patch).
41+
42+
Note that the set of available targets depends on the configured
43+
`TOOL_VERSIONS`. Versions may not always be available if the root module has
44+
customized them, or as older Python versions are removed from rules_python's set
45+
of builtin, known versions.
46+
47+
If you need to match a version that isn't present, then you have two options:
48+
1. Manually define a `config_setting` and have it match {obj}`--python_version`
49+
or {ob}`python_version_major_minor`. This works best when you don't control the
50+
root module, or don't want to rely on the MODULE.bazel configuration. Such
51+
a config settings would look like:
52+
```
53+
# Match any 3.5 version
54+
config_setting(
55+
name = "is_python_3.5",
56+
flag_values = {
57+
"@rules_python//python/config_settings:python_version_major_minor": "3.5",
58+
}
59+
)
60+
# Match exactly 3.5.1
61+
config_setting(
62+
name = "is_python_3.5.1",
63+
flag_values = {
64+
"@rules_python//python/config_settings:python_version": "3.5.1",
65+
}
66+
)
67+
```
68+
69+
2. Use {obj}`python.single_override` to re-introduce the desired version so
70+
that the corresponding `//python/config_setting:is_python_XXX` target is
71+
generated.
72+
:::
73+
3674
::::{bzl:flag} exec_tools_toolchain
3775
Determines if the {obj}`exec_tools_toolchain_type` toolchain is enabled.
3876

0 commit comments

Comments
 (0)