Skip to content

Commit

Permalink
fix(env): get full python path for appropriate executable
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Dec 19, 2022
1 parent cfdba43 commit 770f07f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def create_venv(
self._io.write_error_line(
f"Using <c1>{python}</c1> ({python_patch})"
)
executable = python
executable = self._full_python_path(python)
python_minor = ".".join(python_patch.split(".")[:2])
break

Expand Down
26 changes: 18 additions & 8 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils._compat import WINDOWS
from poetry.utils.env import GET_BASE_PREFIX
from poetry.utils.env import GET_PYTHON_VERSION_ONELINER
from poetry.utils.env import EnvCommandError
from poetry.utils.env import EnvManager
from poetry.utils.env import GenericEnv
Expand Down Expand Up @@ -1002,7 +1003,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_

m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.7",
executable="python3",
executable="/usr/bin/python3",
flags={
"always-copy": False,
"system-site-packages": False,
Expand All @@ -1027,7 +1028,9 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
poetry.package.python_versions = "^3.6"

mocker.patch("sys.version_info", (2, 7, 16))
mocker.patch("subprocess.check_output", side_effect=["3.5.3", "3.9.0"])
mocker.patch(
"subprocess.check_output", side_effect=["3.5.3", "3.9.0", "/usr/bin/python3.9"]
)
m = mocker.patch(
"poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
)
Expand All @@ -1036,7 +1039,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific

m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.9",
executable="python3.9",
executable="/usr/bin/python3.9",
flags={
"always-copy": False,
"system-site-packages": False,
Expand Down Expand Up @@ -1459,11 +1462,18 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(

poetry.package.python_versions = "~3.5.1"

def mock_check_output(cmd: str, *args: Any, **kwargs: Any) -> str:
if GET_PYTHON_VERSION_ONELINER in cmd:
if "python3.5" in cmd:
return "3.5.12"
else:
return "3.7.1"
else:
return "/usr/bin/python3.5"

check_output = mocker.patch(
"subprocess.check_output",
side_effect=lambda cmd, *args, **kwargs: str(
"3.5.12" if "python3.5" in cmd else "3.7.1"
),
side_effect=mock_check_output,
)
m = mocker.patch(
"poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
Expand All @@ -1474,7 +1484,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
assert check_output.called
m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.5",
executable="python3.5",
executable="/usr/bin/python3.5",
flags={
"always-copy": False,
"system-site-packages": False,
Expand Down Expand Up @@ -1582,7 +1592,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt(

m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.7",
executable="python3",
executable="/usr/bin/python3",
flags={
"always-copy": False,
"system-site-packages": False,
Expand Down

0 comments on commit 770f07f

Please sign in to comment.