mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Fix: try python3 before python in install --system (#5296)
Fix a regression from commit dbea3f5 where `pip install --system` tries
to install using the `python` executable first which, on some systems
may point to Python 2. Instead try `python3` first.
This commit is contained in:
committed by
Oz N Tiram
parent
d33f4ec541
commit
44edfd4883
@@ -0,0 +1 @@
|
||||
Fix an issue when using ``pipenv install --system`` on systems that having the ``python`` executable pointing to Python 2 and a Python 3 executable being ``python3``.
|
||||
@@ -445,7 +445,7 @@ def project_python(project, system=False):
|
||||
if not system:
|
||||
python = project._which("python")
|
||||
else:
|
||||
interpreters = [system_which(p) for p in ("python", "python3")]
|
||||
interpreters = [system_which(p) for p in ("python3", "python")]
|
||||
interpreters = [i for i in interpreters if i] # filter out not found interpreters
|
||||
python = interpreters[0] if interpreters else None
|
||||
if not python:
|
||||
|
||||
@@ -458,3 +458,17 @@ twine = "*"
|
||||
sources = [{}]
|
||||
with pytest.raises(PipenvUsageError):
|
||||
indexes.prepare_pip_source_args(sources, pip_args=None)
|
||||
|
||||
@pytest.mark.utils
|
||||
def test_project_python_tries_python3_before_python_if_system_is_true(self):
|
||||
def mock_shutil_which(command, path=None):
|
||||
if command != "python3":
|
||||
return f"/usr/bin/{command}"
|
||||
return "/usr/local/bin/python3"
|
||||
|
||||
with mock.patch("pipenv.utils.shell.shutil.which", wraps=mock_shutil_which):
|
||||
# Setting project to None as system=True doesn't use it
|
||||
project = None
|
||||
python = shell.project_python(project, system=True)
|
||||
|
||||
assert python == "/usr/local/bin/python3"
|
||||
|
||||
Reference in New Issue
Block a user