Skip to content

Commit 8706527

Browse files
committed
Rename toolchain_target_settings to add_target_settings in PR scoped files
1 parent 7613ec7 commit 8706527

5 files changed

Lines changed: 42 additions & 42 deletions

File tree

python/private/python.bzl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def _python_impl(module_ctx):
405405

406406
# Extra target_settings to add to every registered toolchain, e.g. for
407407
# gating the default toolchains behind a custom config_setting.
408-
global_toolchain_target_settings = py.config.toolchain_target_settings
408+
global_add_target_settings = py.config.add_target_settings
409409

410410
# Split the toolchain info into separate objects so they can be passed onto
411411
# the repository rule.
@@ -418,7 +418,7 @@ def _python_impl(module_ctx):
418418

419419
# The target_settings attribute may not be present for users
420420
# patching python/versions.bzl.
421-
toolchain_ts_map[key] = getattr(entry.platform, "target_settings", []) + global_toolchain_target_settings
421+
toolchain_ts_map[key] = getattr(entry.platform, "target_settings", []) + global_add_target_settings
422422
toolchain_platform_keys[key] = entry.platform_name
423423
toolchain_python_versions[key] = entry.full_python_version
424424

@@ -706,8 +706,8 @@ def _process_global_overrides(*, tag, default, _fail = fail):
706706

707707
default["minor_mapping"] = tag.minor_mapping
708708

709-
if tag.toolchain_target_settings:
710-
default["toolchain_target_settings"] = list(tag.toolchain_target_settings)
709+
if tag.add_target_settings:
710+
default["add_target_settings"] = list(tag.add_target_settings)
711711

712712
forwarded_attrs = sorted(AUTH_ATTRS) + [
713713
"base_url",
@@ -816,7 +816,7 @@ def _get_toolchain_config(*, modules, _fail = fail):
816816
)
817817

818818
register_all_versions = default.pop("register_all_versions", False)
819-
toolchain_target_settings = default.pop("toolchain_target_settings", [])
819+
add_target_settings = default.pop("add_target_settings", [])
820820
kwargs = default.pop("kwargs", {})
821821

822822
versions = {}
@@ -842,7 +842,7 @@ def _get_toolchain_config(*, modules, _fail = fail):
842842
minor_mapping = minor_mapping,
843843
default = default,
844844
register_all_versions = register_all_versions,
845-
toolchain_target_settings = toolchain_target_settings,
845+
add_target_settings = add_target_settings,
846846
)
847847

848848
def _compute_default_python_version(mctx):
@@ -1108,6 +1108,30 @@ _override = tag_class(
11081108
:::
11091109
""",
11101110
attrs = {
1111+
"add_target_settings": attr.string_list(
1112+
mandatory = False,
1113+
doc = """\
1114+
A list of `config_setting` labels to add to the `target_settings` of every
1115+
toolchain registered by this module extension. This is useful for creating
1116+
separate "families" of toolchains gated behind custom build settings.
1117+
1118+
For example, to ensure the default prebuilt toolchains are only resolved when
1119+
a `prebuilt` config setting is active:
1120+
1121+
```starlark
1122+
python.override(
1123+
add_target_settings = ["@@//:python_toolchain_family_prebuilt"],
1124+
)
1125+
```
1126+
1127+
These settings are appended to the `target_settings` of all toolchains
1128+
registered by the extension, including any that already have settings
1129+
from `python.single_version_platform_override`.
1130+
1131+
:::{versionadded} VERSION_NEXT_FEATURE
1132+
:::
1133+
""",
1134+
),
11111135
"available_python_versions": attr.string_list(
11121136
mandatory = False,
11131137
doc = """\
@@ -1153,30 +1177,6 @@ The values in this mapping override the default values and do not replace them.
11531177
default = {},
11541178
),
11551179
"register_all_versions": attr.bool(default = False, doc = "Add all versions"),
1156-
"toolchain_target_settings": attr.string_list(
1157-
mandatory = False,
1158-
doc = """\
1159-
A list of `config_setting` labels to add to the `target_settings` of every
1160-
toolchain registered by this module extension. This is useful for creating
1161-
separate "families" of toolchains gated behind custom build settings.
1162-
1163-
For example, to ensure the default prebuilt toolchains are only resolved when
1164-
a `prebuilt` config setting is active:
1165-
1166-
```starlark
1167-
python.override(
1168-
toolchain_target_settings = ["@@//:python_toolchain_family_prebuilt"],
1169-
)
1170-
```
1171-
1172-
These settings are appended to the `target_settings` of all toolchains
1173-
registered by the extension, including any that already have settings
1174-
from `python.single_version_platform_override`.
1175-
1176-
:::{versionadded} VERSION_NEXT_FEATURE
1177-
:::
1178-
""",
1179-
),
11801180
} | AUTH_ATTRS,
11811181
)
11821182

tests/integration/toolchain_target_settings/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ string_flag(
1212
)
1313

1414
# Matches when the "prebuilt" family is selected.
15-
# This is referenced in MODULE.bazel's python.override(toolchain_target_settings=...).
15+
# This is referenced in MODULE.bazel's python.override(add_target_settings=...).
1616
config_setting(
1717
name = "is_prebuilt",
1818
flag_values = {
@@ -30,7 +30,7 @@ config_setting(
3030
)
3131

3232
# This target selects the "prebuilt" family via config_settings transition.
33-
# Since python.override(toolchain_target_settings = ["@@//:is_prebuilt"]) gates
33+
# Since python.override(add_target_settings = ["@@//:is_prebuilt"]) gates
3434
# the default toolchains, this should succeed: the flag matches, the config_setting
3535
# is satisfied, and the default 3.13 toolchain resolves.
3636
py_test(

tests/integration/toolchain_target_settings/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ python.toolchain(python_version = "3.13")
1515
# This prevents them from being a silent fallback when a different toolchain
1616
# family is requested.
1717
python.override(
18-
toolchain_target_settings = ["@@//:is_prebuilt"],
18+
add_target_settings = ["@@//:is_prebuilt"],
1919
)
2020

2121
# Register //:family as a transition setting so py_binary/py_test

tests/integration/toolchain_target_settings_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Integration test for python.override(toolchain_target_settings=...).
1+
"""Integration test for python.override(add_target_settings=...).
22
33
Verifies that when all default toolchains are gated behind a config_setting,
44
requesting a different (unregistered) toolchain family produces a toolchain
@@ -10,7 +10,7 @@
1010
from tests.integration import runner
1111

1212

13-
class ToolchainTargetSettingsTest(runner.TestCase):
13+
class AddTargetSettingsTest(runner.TestCase):
1414
def test_prebuilt_family_resolves(self):
1515
"""Building with the 'prebuilt' family should succeed.
1616
@@ -24,7 +24,7 @@ def test_custom_family_without_toolchain_fails(self):
2424
"""Building with the 'custom' family should fail.
2525
2626
No toolchains have target_settings = [":is_custom"], and the default
27-
toolchains are gated behind ":is_prebuilt" (via toolchain_target_settings),
27+
toolchains are gated behind ":is_prebuilt" (via add_target_settings),
2828
so toolchain resolution should fail with no matching toolchain.
2929
"""
3030
result = self.run_bazel("build", "//:custom_no_toolchain_test", check=False)

tests/python/python_tests.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def _override(
5454
minor_mapping = {},
5555
netrc = "",
5656
register_all_versions = False,
57-
toolchain_target_settings = []):
57+
add_target_settings = []):
5858
return struct(
5959
auth_patterns = auth_patterns,
6060
available_python_versions = available_python_versions,
6161
base_url = base_url,
6262
minor_mapping = minor_mapping,
6363
netrc = netrc,
6464
register_all_versions = register_all_versions,
65-
toolchain_target_settings = toolchain_target_settings,
65+
add_target_settings = add_target_settings,
6666
)
6767

6868
def _rules_python_module(is_root = False):
@@ -467,15 +467,15 @@ def _test_auth_overrides(env):
467467

468468
_tests.append(_test_auth_overrides)
469469

470-
def _test_toolchain_target_settings(env):
470+
def _test_add_target_settings(env):
471471
py = parse_modules(
472472
module_ctx = mocks.mctx(
473473
_mod(
474474
name = "my_module",
475475
toolchain = [_toolchain("3.12")],
476476
override = [
477477
_override(
478-
toolchain_target_settings = [
478+
add_target_settings = [
479479
"@@//my:custom_setting",
480480
],
481481
),
@@ -488,10 +488,10 @@ def _test_toolchain_target_settings(env):
488488
)
489489

490490
env.expect.that_collection(
491-
py.config.toolchain_target_settings,
491+
py.config.add_target_settings,
492492
).contains_exactly(["@@//my:custom_setting"])
493493

494-
_tests.append(_test_toolchain_target_settings)
494+
_tests.append(_test_add_target_settings)
495495

496496
def _test_add_new_version(env):
497497
py = parse_modules(

0 commit comments

Comments
 (0)