From 50704bced3775e9bc5b34f4295e282bfac7253f0 Mon Sep 17 00:00:00 2001 From: Mads Andreasen Date: Sun, 7 Apr 2024 16:12:50 +0200 Subject: Replace exe_exists function with shutil.which() The documentation for subprocess.run at https://docs.python.org/3/library/subprocess.html#popen-constructor has a warning, pointing to using shutil.which() instead of subprocess.run for detecting if exe files exists on the path. shutil.which() is used in many places already. --- mesonbuild/utils/universal.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'mesonbuild/utils') diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 4f18ec11b..21173f5df 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -98,7 +98,6 @@ __all__ = [ 'do_conf_file', 'do_conf_str', 'do_replacement', - 'exe_exists', 'expand_arguments', 'extract_as_list', 'first', @@ -683,14 +682,8 @@ def is_qnx() -> bool: def is_aix() -> bool: return platform.system().lower() == 'aix' -def exe_exists(arglist: T.List[str]) -> bool: - try: - if subprocess.run(arglist, timeout=10).returncode == 0: - return True - except (FileNotFoundError, subprocess.TimeoutExpired): - pass - return False - +def exe_exists(exe: str) -> bool: + return shutil.which(exe) is not None @lru_cache(maxsize=None) def darwin_get_object_archs(objpath: str) -> 'ImmutableListProtocol[str]': -- cgit v1.2.3