Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report cmake/ninja requried if already present #462

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading