Last active
September 17, 2020 10:05
-
-
Save simomarsili/46a8d50acd1d019ddbb53ba59a1c8d10 to your computer and use it in GitHub Desktop.
which.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def which(cmd): | |
"""Path to executable `cmd`. | |
Args: | |
cmd (str or list): Name of the executable or list of alternative names. | |
Returns: | |
pathlib.Path: Path to executable (the first recoverable path for a list). | |
""" | |
try: | |
from shutil import which as which # python3 only | |
except ImportError: | |
from distutils.spawn import find_executable as which | |
if isinstance(cmd, str): | |
path = which(cmd) | |
else: | |
for c in cmd: | |
path = which(c) | |
if path is not None: | |
break | |
path = Path(path) if path else None | |
return path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment