@@ -344,6 +344,28 @@ def do_expand(text: bytes) -> bytes:
344344 else b""
345345 )
346346
347+ def exe_arg (exe_arg : bytes ):
348+ """Find an executable file with the given name.
349+
350+ The input tree is searched first. If no file is found there,
351+ the system path is searched. If the file is still not found,
352+ raise an error.
353+
354+ Args:
355+ exe_arg (bytes): the name to search for.
356+
357+ Returns:
358+ Path
359+ """
360+ exe_name = Path (os .fsdecode (exe_arg ))
361+ exe_path = find_on_path (self .base_file .parent , exe_name )
362+ if exe_path is not None :
363+ return exe_path
364+ exe_path_str = shutil .which (exe_name )
365+ if exe_path_str is not None :
366+ return Path (exe_path_str )
367+ raise ValueError (f"cannot find program '{ exe_name } '" )
368+
347369 def filter_bytes (
348370 input : Optional [bytes ],
349371 external_command : list [bytes ],
@@ -357,13 +379,7 @@ def filter_bytes(
357379 Returns:
358380 bytes: stdout of the command
359381 """
360- exe_name = Path (os .fsdecode (external_command [0 ]))
361- exe_path = find_on_path (self .base_file .parent , exe_name )
362- if exe_path is None :
363- exe_path_str = shutil .which (exe_name )
364- if exe_path_str is None :
365- raise ValueError (f"cannot find program '{ exe_name } '" )
366- exe_path = Path (exe_path_str )
382+ exe_path = exe_arg (external_command [0 ])
367383 exe_args = external_command [1 :]
368384 debug (f"Running { exe_path } { b' ' .join (exe_args )} " )
369385 try :
0 commit comments