From ecc243fc69e2b66aa249981ed663d0346e79df47 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Tue, 15 Feb 2022 11:27:40 -0500 Subject: [PATCH 1/3] Had to patch this locally to get windows to find pyenv which was already on the PATH. --- pipenv/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 0794df46..6ec8f341 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -1623,7 +1623,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): From dabd4bfe86555167b0c4292ecde6bcf9b5db9789 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Tue, 15 Feb 2022 11:37:29 -0500 Subject: [PATCH 2/3] remvoe unused import --- pipenv/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 6ec8f341..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 From 9eb1e7b6d94d4b8e917c8aa026166cba20181f63 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Tue, 15 Feb 2022 20:27:55 -0500 Subject: [PATCH 3/3] Fix test of find_windows_executable and expand coverage. --- tests/unit/test_utils_windows_executable.py | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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