Skip to content

Commit

Permalink
Win32: distutils: Also look for executable.bat
Browse files Browse the repository at this point in the history
This patch should probably not exist, or at least be
rewritten. See the comments.
  • Loading branch information
mingwandroid committed Apr 24, 2019
1 parent 7576f1c commit 054eb34
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Lib/distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,33 @@ def find_executable(executable, path=None):
path = os.environ.get('PATH', os.defpath)

paths = path.split(os.pathsep)
base, ext = os.path.splitext(executable)

if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'
# base, ext = os.path.splitext(executable)

if sys.platform == 'win32':
# This should probably be:
# try:
# exts = os.environ['PATHEXT'].lower().split(';')+['']
# except:
# exts = ['.exe.', '.bat', '']
# but IMHO:
# 1. The original `ext` should appear as the first entry.
# 2. We should be adding `exts` to `base`, not `executable`
# 3. Why even bother? We do not add '.sh' for Unix.
exts = ['.exe', '.bat', '']
else:
exts = ['']

if not os.path.isfile(executable):
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
for ext in exts:
newexe = executable + ext
if os.path.isfile(newexe):
return newexe
else:
for p in paths:
f = os.path.join(p, newexe)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
return None
else:
return executable

0 comments on commit 054eb34

Please sign in to comment.