Skip to content

Commit ebe0694

Browse files
committed
ENH: Refactor _which function for improved path handling and candidate generation
- Updated `PATH` and `PATHEXT` processing to use `os.pathsep` and include additional extensions. - Adjusted candidate list generation for better coverage of executable checks.
1 parent e5b703d commit ebe0694

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎scripts/wheel_builder_utils.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ def read_env_file(
149149
return result
150150

151151

152-
def _which(exe_name: str) -> str | Path | None:
152+
def _which(exe_name: str) -> Path | None:
153153
"""Simple PATH-based lookup using pathlib only."""
154-
pathext: list[str] = environ.get("PATHEXT", ".EXE;.BAT;.CMD").split(";")
155-
paths: list[str] = environ.get("PATH", "").split(";")
154+
# shutil.which only works on windows after python 3.12.
155+
pathext: list[str] = environ.get("PATHEXT", ".EXE;.BAT;.CMD;.exe;.bat;.cmd").split(
156+
";"
157+
)
158+
paths: list[str] = environ.get("PATH", "").split(os.pathsep)
156159
exe: Path = Path(exe_name)
157-
candidates = [exe] if exe.suffix else [Path(exe_name + ext) for ext in pathext]
160+
candidates : list[Path]= [exe] if exe.suffix else [Path(exe_name + ext) for ext in pathext]
161+
candidates = [exe] + candidates
158162
for p in paths:
159163
if not p:
160164
continue

0 commit comments

Comments
 (0)