Skip to content

Commit

Permalink
fix: report cmake/ninja requried if already present
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Aug 14, 2023
1 parent 0cd69e1 commit 526a36c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/scikit_build_core/builder/get_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import functools
import importlib.util
import os
import sysconfig
from collections.abc import Generator, Mapping
Expand Down Expand Up @@ -55,6 +56,13 @@ def settings(self) -> ScikitBuildSettings:

def cmake(self) -> Generator[str, None, None]:
cmake_min = self.settings.cmake.minimum_version

# If the module is already installed (via caching the build
# environment, for example), we will use that
if importlib.util.find_spec("cmake") is not None:
yield f"cmake>={cmake_min}"
return

cmake = best_program(
get_cmake_programs(module=False), minimum_version=cmake_min
)
Expand All @@ -79,6 +87,13 @@ def ninja(self) -> Generator[str, None, None]:
return

ninja_min = self.settings.ninja.minimum_version

# If the module is already installed (via caching the build
# environment, for example), we will use that
if importlib.util.find_spec("ninja") is not None:
yield f"ninja>={ninja_min}"
return

ninja = best_program(
get_ninja_programs(module=False), minimum_version=ninja_min
)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_get_requires.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import importlib.util
import shutil
import sys
import sysconfig
from pathlib import Path
from typing import Any

import pytest

Expand Down Expand Up @@ -35,6 +37,15 @@ def protect_get_requires(fp, monkeypatch):
monkeypatch.setattr(shutil, "which", which_mock)
monkeypatch.delenv("CMAKE_GENERATOR", raising=False)

orig_find_spec = importlib.util.find_spec

def find_spec(name: str, package: str | None = None) -> Any:
if name in {"cmake", "ninja"}:
return None
return orig_find_spec(name, package)

monkeypatch.setattr(importlib.util, "find_spec", find_spec)


def test_get_requires_parts(fp):
fp.register([Path("cmake/path"), "--version"], stdout="3.14.0")
Expand Down

0 comments on commit 526a36c

Please sign in to comment.