Skip to content

Commit

Permalink
fix: min version logic issue (#853)
Browse files Browse the repository at this point in the history
Fixing an issue using `cmake.minimum-version`.

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Aug 7, 2024
1 parent c8cb8b6 commit 0a28489
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/scikit_build_core/settings/skbuild_read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
):
Expand All @@ -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,
Expand Down Expand Up @@ -226,16 +230,15 @@ def __init__(
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:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_skbuild_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 0a28489

Please sign in to comment.