Skip to content

Commit f43f047

Browse files
authored
fix: timeout checking cmake/ninja (#973)
Protection for #955, though I can't reproduce. Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4fbd3b7 commit f43f047

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/scikit_build_core/_shutil.py

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __dir__() -> list[str]:
2424
class Run:
2525
env: dict[str, str] | None = None
2626
cwd: os.PathLike[str] | None = None
27+
timeout: None | float = None
2728

2829
# Stores last printout, for cleaner debug logging
2930
_prev_env: ClassVar[dict[str, str]] = {}
@@ -75,6 +76,7 @@ def _run(
7576
capture_output=capture,
7677
env=self.env,
7778
cwd=self.cwd,
79+
timeout=self.timeout,
7880
)
7981

8082
def _key_diff(self, k: str) -> str:

src/scikit_build_core/program_search.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_cmake_program(cmake_path: Path) -> Program:
8080
None if it cannot be determined.
8181
"""
8282
try:
83-
result = Run().capture(cmake_path, "-E", "capabilities")
83+
result = Run(timeout=2).capture(cmake_path, "-E", "capabilities")
8484
try:
8585
version = Version(
8686
json.loads(result.stdout)["version"]["string"].split("-")[0]
@@ -91,7 +91,7 @@ def get_cmake_program(cmake_path: Path) -> Program:
9191
logger.warning("Could not determine CMake version, got {!r}", result.stdout)
9292
except subprocess.CalledProcessError:
9393
try:
94-
result = Run().capture(cmake_path, "--version")
94+
result = Run(timeout=2).capture(cmake_path, "--version")
9595
try:
9696
version = Version(
9797
result.stdout.splitlines()[0].split()[-1].split("-")[0]
@@ -111,6 +111,8 @@ def get_cmake_program(cmake_path: Path) -> Program:
111111
)
112112
except PermissionError:
113113
logger.warning("Permissions Error getting CMake's version")
114+
except subprocess.TimeoutExpired:
115+
logger.warning("Accessing CMake timed out, ignoring")
114116

115117
return Program(cmake_path, None)
116118

@@ -133,8 +135,12 @@ def get_ninja_programs(*, module: bool = True) -> Generator[Program, None, None]
133135
"""
134136
for ninja_path in _get_ninja_path(module=module):
135137
try:
136-
result = Run().capture(ninja_path, "--version")
137-
except (subprocess.CalledProcessError, PermissionError):
138+
result = Run(timeout=2).capture(ninja_path, "--version")
139+
except (
140+
subprocess.CalledProcessError,
141+
PermissionError,
142+
subprocess.TimeoutExpired,
143+
):
138144
yield Program(ninja_path, None)
139145
continue
140146

0 commit comments

Comments
 (0)