Commits (2)
......@@ -29,9 +29,6 @@ except ImportError:
from .profiling import profile
from .external_tools import EXTERNAL_TOOLS, REMAPPED_TOOL_NAMES, GNU_TOOL_NAMES
# Memoize calls to ``which`` to avoid excessive stat calls
find_executable = functools.lru_cache()(shutil.which)
# The output of --help and --list-tools will use the order of this dict.
# Please keep it alphabetized.
OS_NAMES = collections.OrderedDict(
......@@ -44,6 +41,24 @@ OS_NAMES = collections.OrderedDict(
)
@functools.lru_cache()
def find_executable(cmd):
"""
Given a command name (eg. `dumppdf`), return the absolute path to that
command. Will also try the command with some common suffixes (eg.
`dumppdf.py`) to support distributions that strip or retain them.
Returns an empy string (``) if no command is found.
"""
for suffix in ("", ".py"):
val = shutil.which(f"{cmd}{suffix}")
if val:
return val
return ""
def get_tools(only_missing=False):
"""Return the tool configuration in a dict"""
......