Repository: scikit-build/scikit-build-core
Pull request #700 (2024-04-12 04:44:21)

refactor: make from_file a little more powerful
A little bit of optimization for plugin use, such as #637.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/700?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 86.23%. Comparing base [(`503c88d`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/503c88d02f11489782e41c8ea95ad02117619566?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) to head [(`6c9c37b`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/700?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #700   +/-   ##
=======================================
  Coverage   86.23%   86.23%           
=======================================
  Files          64       64           
  Lines        3321     3321           
=======================================
  Hits         2864     2864           
  Misses        457      457           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/700?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).


Patch:
diff --git a/src/scikit_build_core/settings/skbuild_read_settings.py b/src/scikit_build_core/settings/skbuild_read_settings.py
index 6c8700c..f0f4752 100644
--- a/src/scikit_build_core/settings/skbuild_read_settings.py
+++ b/src/scikit_build_core/settings/skbuild_read_settings.py
@@ -403,16 +403,23 @@ class SettingsReader:
     def from_file(
         cls,
         pyproject_path: os.PathLike[str] | str,
-        config_settings: Mapping[str, str | list[str]] | None,
+        config_settings: Mapping[str, str | list[str]] | None = None,
         *,
         state: Literal[
             "sdist", "wheel", "editable", "metadata_wheel", "metadata_editable"
         ] = "sdist",
         verify_conf: bool = True,
+        extra_settings: Mapping[str, Any] | None = None,
+        env: Mapping[str, str] | None = None,
     ) -> SettingsReader:
         with Path(pyproject_path).open("rb") as f:
             pyproject = tomllib.load(f)
 
         return cls(
-            pyproject, config_settings or {}, verify_conf=verify_conf, state=state
+            pyproject,
+            config_settings or {},
+            verify_conf=verify_conf,
+            state=state,
+            extra_settings=extra_settings,
+            env=env,
         )
diff --git a/src/scikit_build_core/setuptools/build_cmake.py b/src/scikit_build_core/setuptools/build_cmake.py
index 90efe44..00d22ab 100644
--- a/src/scikit_build_core/setuptools/build_cmake.py
+++ b/src/scikit_build_core/setuptools/build_cmake.py
@@ -27,7 +27,7 @@ def __dir__() -> list[str]:
 
 
 def _validate_settings() -> None:
-    settings = SettingsReader.from_file("pyproject.toml", {}).settings
+    settings = SettingsReader.from_file("pyproject.toml").settings
 
     assert (
         not settings.wheel.expand_macos_universal_tags
@@ -112,7 +112,7 @@ class BuildCMake(setuptools.Command):
         if build_temp.exists():
             shutil.rmtree(build_temp)
 
-        settings = SettingsReader.from_file("pyproject.toml", {}).settings
+        settings = SettingsReader.from_file("pyproject.toml").settings
 
         cmake = CMake.default_search(version=settings.cmake.version)
 


Test patch:
diff --git a/tests/test_settings_overrides.py b/tests/test_settings_overrides.py
index ea19216..d17ef22 100644
--- a/tests/test_settings_overrides.py
+++ b/tests/test_settings_overrides.py
@@ -31,7 +31,7 @@ def test_skbuild_overrides_pyver(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if python_version == "3.10":
@@ -77,7 +77,7 @@ def test_skbuild_overrides_dual(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if implementation_name == "pypy" and platform_system == "darwin":
@@ -122,7 +122,7 @@ def test_skbuild_overrides_any(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if implementation_name == "cpython" or platform_system == "darwin":
@@ -168,7 +168,7 @@ def test_skbuild_overrides_any_mixed(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if python_version == "3.10" and (
@@ -198,7 +198,7 @@ def test_skbuild_overrides_platnode(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if platform_node == "matchthat":
@@ -234,7 +234,7 @@ def test_skbuild_overrides_regex(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if platform_machine == "x86_64":
@@ -260,7 +260,7 @@ def test_skbuild_overrides_no_if(
     )
 
     with pytest.raises(KeyError, match="At least one 'if' override must be provided"):
-        SettingsReader.from_file(pyproject_toml, {})
+        SettingsReader.from_file(pyproject_toml)
 
 
 def test_skbuild_overrides_empty_if(
@@ -279,7 +279,7 @@ def test_skbuild_overrides_empty_if(
     )
 
     with pytest.raises(KeyError, match="At least one 'if' override must be provided"):
-        SettingsReader.from_file(pyproject_toml, {})
+        SettingsReader.from_file(pyproject_toml)
 
 
 def test_skbuild_overrides_invalid_key(
@@ -297,7 +297,7 @@ def test_skbuild_overrides_invalid_key(
         encoding="utf-8",
     )
 
-    settings = SettingsReader.from_file(pyproject_toml, {})
+    settings = SettingsReader.from_file(pyproject_toml)
     with pytest.raises(SystemExit):
         settings.validate_may_exit()
 
@@ -333,7 +333,7 @@ def test_skbuild_env(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if envvar == "BAR":
@@ -363,7 +363,7 @@ def test_skbuild_env_bool(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if envvar in {"tRUE", "3"}:
@@ -395,7 +395,7 @@ def test_skbuild_env_bool_all_any(
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings_reader = SettingsReader.from_file(pyproject_toml)
     settings = settings_reader.settings
 
     if (foo == "true" and bar == "true") or (any and (foo == "true" or bar == "true")):
@@ -418,7 +418,7 @@ def test_skbuild_overrides_state(state: str, tmp_path: Path):
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {}, state="wheel")
+    settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
     settings = settings_reader.settings
 
     if state == "wheel":
@@ -463,7 +463,7 @@ def test_skbuild_overrides_inherit(inherit: str, tmp_path: Path):
         encoding="utf-8",
     )
 
-    settings_reader = SettingsReader.from_file(pyproject_toml, {}, state="wheel")
+    settings_reader = SettingsReader.from_file(pyproject_toml, state="wheel")
     settings = settings_reader.settings
 
     if inherit == "none":
diff --git a/tests/test_skbuild_settings.py b/tests/test_skbuild_settings.py
index 2ad4a41..30f0111 100644
--- a/tests/test_skbuild_settings.py
+++ b/tests/test_skbuild_settings.py
@@ -458,7 +458,7 @@ def test_skbuild_settings_version_too_old(
         "tool.scikit-build.cmake.version = '>=3.21'", encoding="utf-8"
     )
 
-    SettingsReader.from_file(pyproject_toml, {})
+    SettingsReader.from_file(pyproject_toml)
 
     with pytest.raises(SystemExit):
         SettingsReader.from_file(pyproject_toml, {"minimum-version": "0.7"})