From eb396b9e9a4a1be84b3d605ca53fa6011cdd03c2 Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Mon, 6 May 2024 14:48:42 +0200 Subject: [PATCH] use shutil.which --- src/mx/_impl/mx_proftool.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/mx/_impl/mx_proftool.py b/src/mx/_impl/mx_proftool.py index f4047105..bcaf0199 100644 --- a/src/mx/_impl/mx_proftool.py +++ b/src/mx/_impl/mx_proftool.py @@ -920,17 +920,6 @@ def demangled_name(self, short_class_names: bool = False): return self.symbol -def _which(executable): - if 'PATH' not in os.environ: - return None - - for path in os.environ['PATH'].split(os.pathsep): - f = os.path.join(path.strip('"'), executable) - if os.path.isfile(f) and os.access(f, os.X_OK): - return f - return None - - class CppDemangler: """An interface for the binutils c++filt demangler, which can demangle C++ symbols.""" @@ -948,7 +937,7 @@ def warn_if_unsupported(cls): def is_supported(cls) -> bool: """Lazily checks whether c++filt is supported.""" if cls._cppfilt_available is None: - cls._cppfilt_available = _which(cls.CPPFILT) is not None + cls._cppfilt_available = shutil.which(cls.CPPFILT) is not None return cls._cppfilt_available @classmethod @@ -1147,7 +1136,7 @@ def __init__(self, files): @staticmethod def is_supported(): if PerfOutput._perf_available is None: - PerfOutput._perf_available = _which('perf') is not None + PerfOutput._perf_available = shutil.which('perf') is not None return PerfOutput._perf_available @staticmethod