Skip to content

Commit 2d3028c

Browse files
committed
ENH: Better emulate Python 3.3+ shutil.which
1 parent d491c8b commit 2d3028c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

nipype/utils/filemanip.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,20 @@ def which(cmd, env=None, pathext=None):
774774
return filename
775775
return None
776776

777+
def isexec(path):
778+
return os.path.isfile(path) and os.access(path, os.X_OK)
779+
777780
for ext in pathext:
778781
extcmd = cmd + ext
779-
for directory in path.split(os.pathsep):
780-
filename = op.join(directory, extcmd)
781-
if op.exists(filename):
782-
return filename
782+
fpath, fname = os.path.split(extcmd)
783+
if fpath:
784+
if isexec(fpath):
785+
return extcmd
786+
else:
787+
for directory in path.split(os.pathsep):
788+
filename = op.join(directory, extcmd)
789+
if isexec(filename):
790+
return filename
783791
return None
784792

785793

0 commit comments

Comments
 (0)