Skip to content

Commit 4278981

Browse files
authored
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 <[email protected]>
1 parent ab5e927 commit 4278981

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

docker/credentials/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import errno
22
import json
3+
import shutil
34
import subprocess
45

56
from . import constants
67
from . import errors
78
from .utils import create_environment_dict
8-
from .utils import find_executable
99

1010

1111
class Store:
@@ -15,7 +15,7 @@ def __init__(self, program, environment=None):
1515
and erasing credentials using `program`.
1616
"""
1717
self.program = constants.PROGRAM_PREFIX + program
18-
self.exe = find_executable(self.program)
18+
self.exe = shutil.which(self.program)
1919
self.environment = environment
2020
if self.exe is None:
2121
raise errors.InitializationError(

docker/credentials/utils.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
1-
import distutils.spawn
21
import os
3-
import sys
4-
5-
6-
def find_executable(executable, path=None):
7-
"""
8-
As distutils.spawn.find_executable, but on Windows, look up
9-
every extension declared in PATHEXT instead of just `.exe`
10-
"""
11-
if sys.platform != 'win32':
12-
return distutils.spawn.find_executable(executable, path)
13-
14-
if path is None:
15-
path = os.environ['PATH']
16-
17-
paths = path.split(os.pathsep)
18-
extensions = os.environ.get('PATHEXT', '.exe').split(os.pathsep)
19-
base, ext = os.path.splitext(executable)
20-
21-
if not os.path.isfile(executable):
22-
for p in paths:
23-
for ext in extensions:
24-
f = os.path.join(p, base + ext)
25-
if os.path.isfile(f):
26-
return f
27-
return None
28-
else:
29-
return executable
302

313

324
def create_environment_dict(overrides):

tests/integration/credentials/store_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import random
3+
import shutil
34
import sys
45

56
import pytest
6-
from distutils.spawn import find_executable
77

88
from docker.credentials import (
99
CredentialsNotFound, Store, StoreError, DEFAULT_LINUX_STORE,
@@ -22,9 +22,9 @@ def teardown_method(self):
2222
def setup_method(self):
2323
self.tmp_keys = []
2424
if sys.platform.startswith('linux'):
25-
if find_executable('docker-credential-' + DEFAULT_LINUX_STORE):
25+
if shutil.which('docker-credential-' + DEFAULT_LINUX_STORE):
2626
self.store = Store(DEFAULT_LINUX_STORE)
27-
elif find_executable('docker-credential-pass'):
27+
elif shutil.which('docker-credential-pass'):
2828
self.store = Store('pass')
2929
else:
3030
raise Exception('No supported docker-credential store in PATH')

0 commit comments

Comments
 (0)