Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove docker.credentials.utils.find_executable #3028

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/credentials/store.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,7 +15,7 @@ def __init__(self, program, environment=None):
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(
Expand Down
28 changes: 0 additions & 28 deletions docker/credentials/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/credentials/store_test.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,9 +22,9 @@ def teardown_method(self):
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')
Expand Down