mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #4955 from pypa/windows-locate-pyenv-from-path
Windows: locate pyenv from PATH correctly
This commit is contained in:
+1
-2
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user