Merge pull request #4955 from pypa/windows-locate-pyenv-from-path

Windows: locate pyenv from PATH correctly
This commit is contained in:
Oz N Tiram
2022-02-16 09:21:51 +01:00
committed by GitHub
2 changed files with 23 additions and 5 deletions
+1 -2
View File
@@ -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):
+22 -3
View File
@@ -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