From 1e4633a60614b44145043d4aa70afd31146919c4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 8 Aug 2022 20:58:12 +0200 Subject: [PATCH] For Python > 2, always use shutil.which instead of custom Windows helper code. (#438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Daniel Möller --- changelogs/fragments/438-docker-py.yml | 2 ++ plugins/module_utils/_api/credentials/utils.py | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/438-docker-py.yml diff --git a/changelogs/fragments/438-docker-py.yml b/changelogs/fragments/438-docker-py.yml new file mode 100644 index 00000000..4b0aa4ef --- /dev/null +++ b/changelogs/fragments/438-docker-py.yml @@ -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)." diff --git a/plugins/module_utils/_api/credentials/utils.py b/plugins/module_utils/_api/credentials/utils.py index 08699efb..1ab84fe5 100644 --- a/plugins/module_utils/_api/credentials/utils.py +++ b/plugins/module_utils/_api/credentials/utils.py @@ -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']