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:
Albert Hopkins
2022-08-26 15:40:07 +00:00
committed by Oz N Tiram
parent d33f4ec541
commit 44edfd4883
3 changed files with 16 additions and 1 deletions
+1
View File
@@ -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``.
+1 -1
View File
@@ -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:
+14
View File
@@ -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"