update to make use of shutil.which for executable searching

This commit is contained in:
Blake Harnden 2020-03-06 16:41:26 -08:00
parent 6b5cd95ac2
commit 0e299d5af4

View file

@ -13,6 +13,7 @@ import logging.config
import os
import random
import shlex
import shutil
import sys
from subprocess import PIPE, STDOUT, Popen
from typing import (
@ -151,16 +152,9 @@ def which(command: str, required: bool) -> str:
:return: command location or None
:raises ValueError: when not found and required
"""
found_path = None
for path in os.environ["PATH"].split(os.pathsep):
command_path = os.path.join(path, command)
if os.path.isfile(command_path) and os.access(command_path, os.X_OK):
found_path = command_path
break
found_path = shutil.which(command)
if found_path is None and required:
raise ValueError(f"failed to find required executable({command}) in path")
return found_path