summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNingú <47453810+n1ngu@users.noreply.github.com>2022-08-02 16:19:50 +0200
committerGitHub <noreply@github.com>2022-08-02 10:19:50 -0400
commit42789818bed5d86b487a030e2e60b02bf0cfa284 (patch)
tree0e983a230bbe7841487bf31a380ce82e8e18df4a
parentab5e927300b0fd44b002e657eb371a6e7356c809 (diff)
downloaddocker-py-42789818bed5d86b487a030e2e60b02bf0cfa284.tar.gz
credentials: eliminate distutils deprecation warnings (#3028)
While removing any usage of the deprecated `distutils` package, ("The distutils package is deprecated and slated for removal in Python 3.12.") this internal utility can be removed straightaway because the `shutil.which` replacement for `distutils.spawn.find_executable` already honors the `PATHEXT` environment variable in windows systems. See https://docs.python.org/3/library/shutil.html#shutil.which Signed-off-by: Daniel Möller <n1ngu@riseup.net>
-rw-r--r--docker/credentials/store.py4
-rw-r--r--docker/credentials/utils.py28
-rw-r--r--tests/integration/credentials/store_test.py6
3 files changed, 5 insertions, 33 deletions
diff --git a/docker/credentials/store.py b/docker/credentials/store.py
index e55976f..297f468 100644
--- a/docker/credentials/store.py
+++ b/docker/credentials/store.py
@@ -1,11 +1,11 @@
import errno
import json
+import shutil
import subprocess
from . import constants
from . import errors
from .utils import create_environment_dict
-from .utils import find_executable
class Store:
@@ -15,7 +15,7 @@ class Store:
and erasing credentials using `program`.
"""
self.program = constants.PROGRAM_PREFIX + program
- self.exe = find_executable(self.program)
+ self.exe = shutil.which(self.program)
self.environment = environment
if self.exe is None:
raise errors.InitializationError(
diff --git a/docker/credentials/utils.py b/docker/credentials/utils.py
index 3f720ef..5c83d05 100644
--- a/docker/credentials/utils.py
+++ b/docker/credentials/utils.py
@@ -1,32 +1,4 @@
-import distutils.spawn
import os
-import sys
-
-
-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 sys.platform != 'win32':
- return distutils.spawn.find_executable(executable, path)
-
- if path is None:
- path = os.environ['PATH']
-
- paths = path.split(os.pathsep)
- extensions = os.environ.get('PATHEXT', '.exe').split(os.pathsep)
- base, ext = os.path.splitext(executable)
-
- if not os.path.isfile(executable):
- for p in paths:
- for ext in extensions:
- f = os.path.join(p, base + ext)
- if os.path.isfile(f):
- return f
- return None
- else:
- return executable
def create_environment_dict(overrides):
diff --git a/tests/integration/credentials/store_test.py b/tests/integration/credentials/store_test.py
index d0cfd54..213cf30 100644
--- a/tests/integration/credentials/store_test.py
+++ b/tests/integration/credentials/store_test.py
@@ -1,9 +1,9 @@
import os
import random
+import shutil
import sys
import pytest
-from distutils.spawn import find_executable
from docker.credentials import (
CredentialsNotFound, Store, StoreError, DEFAULT_LINUX_STORE,
@@ -22,9 +22,9 @@ class TestStore:
def setup_method(self):
self.tmp_keys = []
if sys.platform.startswith('linux'):
- if find_executable('docker-credential-' + DEFAULT_LINUX_STORE):
+ if shutil.which('docker-credential-' + DEFAULT_LINUX_STORE):
self.store = Store(DEFAULT_LINUX_STORE)
- elif find_executable('docker-credential-pass'):
+ elif shutil.which('docker-credential-pass'):
self.store = Store('pass')
else:
raise Exception('No supported docker-credential store in PATH')