update to make use of shutil.which for executable searching
This commit is contained in:
parent
6b5cd95ac2
commit
0e299d5af4
1 changed files with 2 additions and 8 deletions
|
@ -13,6 +13,7 @@ import logging.config
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shlex
|
import shlex
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from subprocess import PIPE, STDOUT, Popen
|
from subprocess import PIPE, STDOUT, Popen
|
||||||
from typing import (
|
from typing import (
|
||||||
|
@ -151,16 +152,9 @@ def which(command: str, required: bool) -> str:
|
||||||
:return: command location or None
|
:return: command location or None
|
||||||
:raises ValueError: when not found and required
|
:raises ValueError: when not found and required
|
||||||
"""
|
"""
|
||||||
found_path = None
|
found_path = shutil.which(command)
|
||||||
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
|
|
||||||
|
|
||||||
if found_path is None and required:
|
if found_path is None and required:
|
||||||
raise ValueError(f"failed to find required executable({command}) in path")
|
raise ValueError(f"failed to find required executable({command}) in path")
|
||||||
|
|
||||||
return found_path
|
return found_path
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue