Skip to content

Commit fb51937

Browse files
authored
feat: support namespaced config settings (#556)
Support namespaced config settings, `skbuild.X` now also works instead of just `X`. --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3a06901 commit fb51937

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/scikit_build_core/settings/skbuild_read_settings.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,16 @@ def __init__(
179179
else:
180180
tool_skb[key] = value
181181

182+
prefixed = {
183+
k: v for k, v in config_settings.items() if k.startswith("skbuild.")
184+
}
185+
remaining = {
186+
k: v for k, v in config_settings.items() if not k.startswith("skbuild.")
187+
}
182188
self.sources = SourceChain(
183189
EnvSource("SKBUILD"),
184-
ConfSource(settings=config_settings, verify=verify_conf),
190+
ConfSource("skbuild", settings=prefixed, verify=verify_conf),
191+
ConfSource(settings=remaining, verify=verify_conf),
185192
TOMLSource("tool", "scikit-build", settings=pyproject),
186193
prefixes=["tool", "scikit-build"],
187194
)
@@ -240,8 +247,10 @@ def suggestions(self, index: int) -> dict[str, list[str]]:
240247
return result
241248

242249
def print_suggestions(self) -> None:
243-
for index in (1, 2):
244-
name = {1: "config-settings", 2: "pyproject.toml"}[index]
250+
for index in (1, 2, 3):
251+
name = {1: "config-settings", 2: "config-settings", 3: "pyproject.toml"}[
252+
index
253+
]
245254
suggestions_dict = self.suggestions(index)
246255
if suggestions_dict:
247256
rich_print(f"[red][bold]ERROR:[/bold] Unrecognized options in {name}:")

tests/test_skbuild_settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ def test_skbuild_settings_envvar(tmp_path: Path, monkeypatch: pytest.MonkeyPatch
135135
assert not settings.install.strip
136136

137137

138+
@pytest.mark.parametrize("prefix", [True, False], ids=["skbuild", "noprefix"])
138139
def test_skbuild_settings_config_settings(
139-
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
140+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, prefix: bool
140141
):
141142
monkeypatch.setattr(
142143
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.1.0"
@@ -177,6 +178,9 @@ def test_skbuild_settings_config_settings(
177178
"install.strip": "True",
178179
}
179180

181+
if prefix:
182+
config_settings = {f"skbuild.{k}": v for k, v in config_settings.items()}
183+
180184
settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
181185
settings = settings_reader.settings
182186
assert list(settings_reader.unrecognized_options()) == []

0 commit comments

Comments
 (0)