diff --git a/pipenv/utils.py b/pipenv/utils.py index 0794df46..d43158bb 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -14,7 +14,6 @@ import sys import warnings from contextlib import contextmanager -from distutils.spawn import find_executable from pathlib import Path from urllib.parse import urlparse @@ -1623,7 +1622,7 @@ def find_windows_executable(bin_path, exe_name): if os.path.isfile(path): return path - return find_executable(exe_name) + return shutil.which(exe_name) def path_to_url(path): diff --git a/tests/unit/test_utils_windows_executable.py b/tests/unit/test_utils_windows_executable.py index 22f20b35..a6eaa5ad 100644 --- a/tests/unit/test_utils_windows_executable.py +++ b/tests/unit/test_utils_windows_executable.py @@ -15,10 +15,10 @@ pytestmark = pytest.mark.skipif( @pytest.mark.utils @mock.patch('os.path.isfile') -@mock.patch('pipenv.utils.find_executable') -def test_find_windows_executable(mocked_find_executable, mocked_isfile): +@mock.patch('shutil.which') +def test_find_windows_executable_when_not_found(mocked_which, mocked_isfile): mocked_isfile.return_value = False - mocked_find_executable.return_value = None + mocked_which.return_value = None found = utils.find_windows_executable('fake/path', 'python') assert found is None @@ -29,3 +29,22 @@ def test_find_windows_executable(mocked_find_executable, mocked_isfile): for ext in os.environ['PATHEXT'].split(';') ] assert mocked_isfile.mock_calls == calls + + +@pytest.mark.utils +@mock.patch('os.path.isfile') +@mock.patch('shutil.which') +def test_find_windows_executable_when_found(mocked_which, mocked_isfile): + mocked_isfile.return_value = False + found_path = '/fake/known/system/path/pyenv' + mocked_which.return_value = found_path + found = utils.find_windows_executable('fake/path', 'pyenv') + assert found is found_path + + assert mocked_isfile.call_count > 1 + + calls = [mock.call('fake\\path\\pyenv')] + [ + mock.call('fake\\path\\pyenv{0}'.format(ext.lower())) + for ext in os.environ['PATHEXT'].split(';') + ] + assert mocked_isfile.mock_calls == calls