@@ -508,21 +508,28 @@ def repair_default(
508
508
new_soname = soname_with_hash (src_path )
509
509
dst_path = libs_dir / new_soname
510
510
shutil .copyfile (src_path , dst_path )
511
-
512
- # If cibuildwheel was called without activating its environment, the `bin`
513
- # directory will not be on the PATH.
514
- cibw_bin = Path (sys .executable ).parent
515
- call (cibw_bin / "patchelf" , "--set-soname" , new_soname , dst_path )
511
+ call (which ("patchelf" ), "--set-soname" , new_soname , dst_path )
516
512
517
513
for path in paths_to_patch :
518
- call (cibw_bin / "patchelf" , "--replace-needed" , old_soname , new_soname , path )
514
+ call (which ( "patchelf" ) , "--replace-needed" , old_soname , new_soname , path )
519
515
call (
520
- cibw_bin / "patchelf" ,
516
+ which ( "patchelf" ) ,
521
517
"--set-rpath" ,
522
518
f"${{ORIGIN}}/{ relpath (libs_dir , path .parent )} " ,
523
519
path ,
524
520
)
525
- call (cibw_bin / "wheel" , "pack" , unpacked_dir , "-d" , repaired_wheel_dir )
521
+ call (which ("wheel" ), "pack" , unpacked_dir , "-d" , repaired_wheel_dir )
522
+
523
+
524
+ # If cibuildwheel was called without activating its environment, the `bin` directory
525
+ # will not be on the PATH.
526
+ def which (cmd : str ) -> str :
527
+ cibw_bin = Path (sys .executable ).parent
528
+ result = shutil .which (cmd , path = f"{ cibw_bin } { os .pathsep } { os .environ ['PATH' ]} " )
529
+ if result is None :
530
+ msg = f"Couldn't find { cmd !r} in { cibw_bin } or on the PATH"
531
+ raise errors .FatalError (msg )
532
+ return result
526
533
527
534
528
535
def elf_file_filter (paths : Iterable [Path ]) -> Iterator [tuple [Path , ELFFile ]]:
0 commit comments