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

This is related to
42789818be
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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- "modules and plugins communicating directly with the Docker daemon - simplify use of helper function that was removed in Docker SDK for Python to find executables (https://github.com/ansible-collections/community.docker/pull/438)."

View File

@ -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']