For Python > 2, always use shutil.which instead of custom Windows helper code. (#438)

This is related to
https://github.com/docker/docker-py/commit/42789818bed5d86b487a030e2e60b02bf0cfa284
in the sense that for Python > 2, we also exclusively use shutil.which now,
but we do not remove the helper function since we need it for Python 2 on Windows.

Co-authored-by: Daniel Möller <n1ngu@riseup.net>

Co-authored-by: Daniel Möller <n1ngu@riseup.net>
This commit is contained in:
Felix Fontein
2022-08-08 20:58:12 +02:00
committed by GitHub
parent bc6757d3b8
commit 1e4633a606
2 changed files with 9 additions and 4 deletions
@@ -26,11 +26,14 @@ def find_executable(executable, path=None):
As distutils.spawn.find_executable, but on Windows, look up
every extension declared in PATHEXT instead of just `.exe`
"""
if not PY2:
# shutil.which() already uses PATHEXT on Windows, so on
# Python 3 we can simply use shutil.which() in all cases.
# (https://github.com/docker/docker-py/commit/42789818bed5d86b487a030e2e60b02bf0cfa284)
return which(executable, path=path)
if sys.platform != 'win32':
if PY2:
return which(executable, path)
else:
return which(executable, path=path)
return which(executable, path)
if path is None:
path = os.environ['PATH']