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: support namespaced config settings #556

Merged
merged 2 commits into from
Nov 29, 2023
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
15 changes: 12 additions & 3 deletions src/scikit_build_core/settings/skbuild_read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,16 @@ def __init__(
else:
tool_skb[key] = value

prefixed = {
k: v for k, v in config_settings.items() if k.startswith("skbuild.")
}
remaining = {
k: v for k, v in config_settings.items() if not k.startswith("skbuild.")
}
self.sources = SourceChain(
EnvSource("SKBUILD"),
ConfSource(settings=config_settings, verify=verify_conf),
ConfSource("skbuild", settings=prefixed, verify=verify_conf),
ConfSource(settings=remaining, verify=verify_conf),
TOMLSource("tool", "scikit-build", settings=pyproject),
prefixes=["tool", "scikit-build"],
)
Expand Down Expand Up @@ -240,8 +247,10 @@ def suggestions(self, index: int) -> dict[str, list[str]]:
return result

def print_suggestions(self) -> None:
for index in (1, 2):
name = {1: "config-settings", 2: "pyproject.toml"}[index]
for index in (1, 2, 3):
name = {1: "config-settings", 2: "config-settings", 3: "pyproject.toml"}[
index
]
suggestions_dict = self.suggestions(index)
if suggestions_dict:
rich_print(f"[red][bold]ERROR:[/bold] Unrecognized options in {name}:")
Expand Down
6 changes: 5 additions & 1 deletion tests/test_skbuild_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ def test_skbuild_settings_envvar(tmp_path: Path, monkeypatch: pytest.MonkeyPatch
assert not settings.install.strip


@pytest.mark.parametrize("prefix", [True, False], ids=["skbuild", "noprefix"])
def test_skbuild_settings_config_settings(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, prefix: bool
):
monkeypatch.setattr(
scikit_build_core.settings.skbuild_read_settings, "__version__", "0.1.0"
Expand Down Expand Up @@ -177,6 +178,9 @@ def test_skbuild_settings_config_settings(
"install.strip": "True",
}

if prefix:
config_settings = {f"skbuild.{k}": v for k, v in config_settings.items()}

settings_reader = SettingsReader.from_file(pyproject_toml, config_settings)
settings = settings_reader.settings
assert list(settings_reader.unrecognized_options()) == []
Expand Down
Loading