setup: skip a cmake/ninja on PATH that does not run, for the one next to this Python

A pip launcher whose Python was removed stays on PATH ('ninja --version'
fails) and stopped every build there, though setup had just installed a
working copy in .venv.
This commit is contained in:
Destrayon authored and Niko1221 committed 2026-10-09 03:06:34 +02:00
1 parent 573642fc4c
commit 1decc04efe
1 file changed
+7 -2
+7 -2
View File
@@ -1285,10 +1285,15 @@ def find_vcvars(cuda_v=None):
def find_tool(name):
"""A tool on PATH, or the one pip installed next to this Python (cmake, ninja)."""
"""A tool on PATH, or the one pip installed next to this Python (cmake, ninja). A PATH copy that does not run
(a pip launcher whose Python is gone) is skipped for the one next to this Python."""
p = shutil.which(name)
if p:
return p
try:
if subprocess.run([p, "--version"], capture_output=True, timeout=30).returncode == 0:
return p
except (OSError, subprocess.SubprocessError):
pass
for d in (Path(sys.executable).parent / "Scripts", Path(sys.executable).parent,
Path.home() / ".local" / "bin"):
c = d / (name + (".exe" if WIN else ""))