Skip to content

Commit 417a6e7

Browse files
committed
Make fail a disallow_hard_code
Add `test_disallow_hardcoded` to cover these type of settings Signed-off-by: Cristian Le <[email protected]>
1 parent 55908d9 commit 417a6e7

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ minimum-version = "0.11" # current version
335335
build-dir = ""
336336

337337
# Immediately fail the build. This is only useful in overrides.
338-
fail = false
338+
fail = ""
339339

340340
```
341341

docs/reference/configs.md

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ print(mk_skbuild_docs())
7676
```{eval-rst}
7777
.. confval:: fail
7878
:type: ``bool``
79-
:default: false
8079
8180
Immediately fail the build. This is only useful in overrides.
8281
```

src/scikit_build_core/resources/scikit-build.schema.json

-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@
491491
},
492492
"fail": {
493493
"type": "boolean",
494-
"default": false,
495494
"description": "Immediately fail the build. This is only useful in overrides."
496495
},
497496
"overrides": {

src/scikit_build_core/settings/skbuild_model.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,12 @@ class ScikitBuildSettings:
416416
The build directory. Defaults to a temporary directory, but can be set.
417417
"""
418418

419-
fail: bool = False
419+
fail: Optional[bool] = dataclasses.field(
420+
default=None,
421+
metadata=SettingsFieldMetadata(
422+
disallow_hard_code=True,
423+
),
424+
)
420425
"""
421426
Immediately fail the build. This is only useful in overrides.
422427
"""

tests/test_settings_docs.py

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def test_skbuild_docs() -> None:
1212
in docs
1313
)
1414
assert "DEPRECATED in 0.10, use build.verbose instead." in docs
15-
assert "fail = false" in docs
1615

1716

1817
def test_mk_docs() -> None:

tests/test_settings_overrides.py

+48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
import sysconfig
45
import typing
56
from pathlib import Path
@@ -22,6 +23,53 @@ class VersionInfo(typing.NamedTuple):
2223
releaselevel: str = "final"
2324

2425

26+
def test_disallow_hardcoded(
27+
tmp_path: Path,
28+
caplog: pytest.LogCaptureFixture,
29+
capsys: pytest.CaptureFixture[str],
30+
):
31+
caplog.set_level(logging.WARNING)
32+
pyproject_toml = tmp_path / "pyproject.toml"
33+
template = dedent(
34+
"""\
35+
[tool.scikit-build]
36+
strict-config = {strict_config}
37+
fail = false
38+
"""
39+
)
40+
41+
# First check without strict-config to make sure all fields are disallowed
42+
strict_config = "false"
43+
pyproject_toml.write_text(
44+
template.format(strict_config=strict_config),
45+
encoding="utf-8",
46+
)
47+
48+
settings_reader = SettingsReader.from_file(pyproject_toml)
49+
settings_reader.validate_may_exit()
50+
assert caplog.records
51+
for idx, key in enumerate(["fail"]):
52+
assert (
53+
f"{key} is not allowed to be hard-coded in the pyproject.toml file"
54+
in str(caplog.records[idx].msg)
55+
)
56+
57+
# Next check that this exits if string-config is set
58+
strict_config = "true"
59+
pyproject_toml.write_text(
60+
template.format(strict_config=strict_config),
61+
encoding="utf-8",
62+
)
63+
# Flush the capsys just in case
64+
capsys.readouterr()
65+
settings_reader = SettingsReader.from_file(pyproject_toml)
66+
with pytest.raises(SystemExit) as exc:
67+
settings_reader.validate_may_exit()
68+
assert exc.value.code == 7
69+
out, _ = capsys.readouterr()
70+
assert "is not allowed to be hard-coded in the pyproject.toml file" in out
71+
72+
2573
@pytest.mark.parametrize("python_version", ["3.9", "3.10"])
2674
def test_skbuild_overrides_pyver(
2775
python_version: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch

0 commit comments

Comments
 (0)