Skip to content

Commit

Permalink
use shutil.which
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed May 6, 2024
1 parent 39428a3 commit eb396b9
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/mx/_impl/mx_proftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb396b9

Please sign in to comment.