tools: Fix error in is_tool_available.

- Happened with bandit, but not pycodestyle. Not sure why.
This commit is contained in:
Andrew Hamilton 2021-12-09 17:37:13 +10:00
parent 5f45485479
commit 2dba7a6920

View file

@ -657,7 +657,10 @@ def splitext(path):
@functools.lru_cache() @functools.lru_cache()
def is_tool_available(tool): def is_tool_available(tool):
if (hasattr(tool, "command") and tool.command.startswith(f"{PYTHON_EXECUTABLE} -m ")): if (hasattr(tool, "command") and tool.command.startswith(f"{PYTHON_EXECUTABLE} -m ")):
return importlib.util.find_spec(tool.command.split()[2]) is not None try:
return importlib.util.find_spec(tool.command.split()[2]) is not None
except ModuleNotFoundError:
return False
try: try:
return all(shutil.which(executable) for executable in tool.executables) return all(shutil.which(executable) for executable in tool.executables)
except AttributeError: except AttributeError: