Skip to content

Commit

Permalink
Merge pull request #531 from arosen93/patch-1
Browse files Browse the repository at this point in the history
Remove deprecated `which` function
  • Loading branch information
shyuep committed Aug 7, 2023
2 parents eb4ffbd + 37ba656 commit dc9abbe
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions monty/os/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,11 @@
Path based methods, e.g., which, zpath, etc.
"""
import os
import shutil

from monty.dev import deprecated
from monty.fnmatch import WildCard
from monty.string import list_strings


@deprecated(shutil.which, message="shutil.which has been available since Python 3.3. This will be removed in v2023.")
def which(cmd):
"""
Returns full path to a executable.
Args:
cmd (str): Executable command to search for.
Returns:
(str) Full path to command. None if it is not found.
Example::
full_path_to_python = which("python")
"""

def is_exe(fp):
return os.path.isfile(fp) and os.access(fp, os.X_OK)

fpath, fname = os.path.split(cmd)
if fpath:
if is_exe(cmd):
return cmd
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, cmd)
if is_exe(exe_file):
return exe_file
return None


def zpath(filename):
"""
Returns an existing (zipped or unzipped) file path given the unzipped
Expand Down

0 comments on commit dc9abbe

Please sign in to comment.