Repository: scikit-build/scikit-build-core
Pull request #853 (2024-08-06 22:50:58)

fix: min version logic issue
Fixing an issue using `cmake.minimum-version`.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/853?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 83.83%. Comparing base [(`9d3737f`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/9d3737fdb325580b7bb4fb544f7b48caf03fce13?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) to head [(`846e718`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/846e7186c14f2c0effcb9e3fc2393e7f57bb6d78?dropdown=coverage&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     #853      +/-   ##
==========================================
- Coverage   83.87%   83.83%   -0.05%     
==========================================
  Files          74       74              
  Lines        4361     4361              
==========================================
- Hits         3658     3656       -2     
- Misses        703      705       +2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/853?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/build/_file_processor.py b/src/scikit_build_core/build/_file_processor.py
index c396718..457f91c 100644
--- a/src/scikit_build_core/build/_file_processor.py
+++ b/src/scikit_build_core/build/_file_processor.py
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
 __all__ = ["each_unignored_file"]
 
 EXCLUDE_LINES = [
-    ".git/",
+    ".git",
     ".tox/",
     ".nox/",
     ".egg-info/",
@@ -39,7 +39,8 @@ def each_unignored_file(
     exclude_lines = EXCLUDE_LINES + list(exclude)
 
     for gi in [Path(".git/info/exclude"), Path(".gitignore")]:
-        with contextlib.suppress(FileNotFoundError), gi.open(encoding="utf-8") as f:
+        ignore_errs = [FileNotFoundError, NotADirectoryError]
+        with contextlib.suppress(*ignore_errs), gi.open(encoding="utf-8") as f:
             exclude_lines += f.readlines()
 
     nested_excludes = {
diff --git a/src/scikit_build_core/settings/skbuild_read_settings.py b/src/scikit_build_core/settings/skbuild_read_settings.py
index 4f9880b..6e3033a 100644
--- a/src/scikit_build_core/settings/skbuild_read_settings.py
+++ b/src/scikit_build_core/settings/skbuild_read_settings.py
@@ -58,7 +58,8 @@ def _handle_minimum_version(
 
     # Check for minimum_version < 0.8 and the modern version setting
     if (
-        dc.version != version_default
+        dc.version is not None
+        and dc.version != version_default
         and minimum_version is not None
         and minimum_version < Version("0.8")
     ):
@@ -74,13 +75,16 @@ def _handle_minimum_version(
         elif minimum_version >= Version("0.8"):
             rich_error(msg)
 
-        if dc.version != version_default:
+        if dc.version is not None and dc.version != version_default:
             rich_error(
                 f"Cannot set both {name}.minimum_version and {name}.version; use version only for scikit-build-core >= 0.8."
             )
 
         dc.version = SpecifierSet(f">={dc.minimum_version}")
 
+    if dc.version is None:
+        dc.version = SpecifierSet(f">={default}")
+
 
 def _handle_move(
     before_name: str,
@@ -226,16 +230,15 @@ class SettingsReader:
         if self.settings.install.strip is None:
             self.settings.install.strip = install_policy
 
-        # Before 0.10, we hard-coded 3.15+ as the minimum CMake version
+        # If we noted earlier that auto-cmake was requested, handle it now
         if (
             self.settings.cmake.version is None
-            and self.settings.minimum_version is not None
-            and self.settings.minimum_version < Version("0.10")
+            and self.settings.cmake.minimum_version is None
+            and (
+                self.settings.minimum_version is None
+                or self.settings.minimum_version >= Version("0.10")
+            )
         ):
-            self.settings.cmake.version = SpecifierSet(">=3.15")
-
-        # If we noted earlier that auto-cmake was requested, handle it now
-        if self.settings.cmake.version is None:
             cmake_path = self.settings.cmake.source_dir / "CMakeLists.txt"
             try:
                 with cmake_path.open(encoding="utf-8-sig") as f:


Test patch:
diff --git a/tests/test_file_processor.py b/tests/test_file_processor.py
index f1f993e..1ce36f2 100644
--- a/tests/test_file_processor.py
+++ b/tests/test_file_processor.py
@@ -65,3 +65,16 @@ def test_on_each_with_symlink(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -
         nested_dir / "not_ignored.txt",
         nested_dir / ".gitignore",
     }
+
+
+def test_dot_git_is_a_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+    """
+    Test that each_unignored_file() does not crash when .git is a file (e.g.,
+    if the build is being run in a submodule)
+    """
+    monkeypatch.chdir(tmp_path)
+    # Create a file named .git
+    git = Path(".git")
+    git.write_text("gitdir: ../../.git/modules/foo")
+    # If this throws an exception, the test will fail
+    assert list(each_unignored_file(Path())) == []
diff --git a/tests/test_skbuild_settings.py b/tests/test_skbuild_settings.py
index b7bda68..442eaa8 100644
--- a/tests/test_skbuild_settings.py
+++ b/tests/test_skbuild_settings.py
@@ -472,13 +472,19 @@ def test_skbuild_settings_min_version_versions(
     tmp_path: Path, monkeypatch: pytest.MonkeyPatch
 ):
     monkeypatch.setattr(
-        scikit_build_core.settings.skbuild_read_settings, "__version__", "0.8.0"
+        scikit_build_core.settings.skbuild_read_settings, "__version__", "0.10.0"
     )
 
     pyproject_toml = tmp_path / "pyproject.toml"
     pyproject_toml.write_text(
         "tool.scikit-build.cmake.minimum-version = '3.21'", encoding="utf-8"
     )
+    cmakelists = tmp_path / "CMakeLists.txt"
+    cmakelists.write_text("cmake_minimum_required(VERSION 3.20)", encoding="utf-8")
+
+    settings_reader = SettingsReader.from_file(pyproject_toml, {})
+    settings = settings_reader.settings
+    assert settings.cmake.version == SpecifierSet(">=3.21")
 
     settings_reader = SettingsReader.from_file(
         pyproject_toml, {"minimum-version": "0.7"}