Commit 06fcff08 by finswimmer Committed by Bjorn Neergaard

get fullpath of given python executable when activating env

parent b70d2602
...@@ -465,6 +465,21 @@ class EnvManager: ...@@ -465,6 +465,21 @@ class EnvManager:
def __init__(self, poetry: "Poetry") -> None: def __init__(self, poetry: "Poetry") -> None:
self._poetry = poetry self._poetry = poetry
def _full_python_path(self, python: str) -> str:
try:
executable = decode(
subprocess.check_output(
list_to_shell_command(
[python, "-c", '"import sys; print(sys.executable)"']
),
shell=True,
).strip()
)
except CalledProcessError as e:
raise EnvCommandError(e)
return executable
def _detect_active_python(self, io: "IO") -> str: def _detect_active_python(self, io: "IO") -> str:
executable = None executable = None
...@@ -474,14 +489,7 @@ class EnvManager: ...@@ -474,14 +489,7 @@ class EnvManager:
" config.", " config.",
verbosity=Verbosity.VERBOSE, verbosity=Verbosity.VERBOSE,
) )
executable = decode( executable = self._full_python_path("python")
subprocess.check_output(
list_to_shell_command(
["python", "-c", '"import sys; print(sys.executable)"']
),
shell=True,
).strip()
)
io.write_line(f"Found: {executable}", verbosity=Verbosity.VERBOSE) io.write_line(f"Found: {executable}", verbosity=Verbosity.VERBOSE)
except CalledProcessError: except CalledProcessError:
io.write_line( io.write_line(
...@@ -511,6 +519,8 @@ class EnvManager: ...@@ -511,6 +519,8 @@ class EnvManager:
# Executable in PATH or full executable path # Executable in PATH or full executable path
pass pass
python = self._full_python_path(python)
try: try:
python_version = decode( python_version = decode(
subprocess.check_output( subprocess.check_output(
......
...@@ -25,6 +25,8 @@ def check_output_wrapper( ...@@ -25,6 +25,8 @@ def check_output_wrapper(
return version.text return version.text
elif "sys.version_info[:2]" in cmd: elif "sys.version_info[:2]" in cmd:
return f"{version.major}.{version.minor}" return f"{version.major}.{version.minor}"
elif '-c "import sys; print(sys.executable)"' in cmd:
return f"/usr/bin/{cmd.split()[0]}"
else: else:
return str(Path("/prefix")) return str(Path("/prefix"))
......
...@@ -69,7 +69,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -69,7 +69,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
venv_py37 = venv_cache / f"{venv_name}-py3.7" venv_py37 = venv_cache / f"{venv_name}-py3.7"
mock_build_env.assert_called_with( mock_build_env.assert_called_with(
venv_py37, venv_py37,
executable="python3.7", executable="/usr/bin/python3.7",
flags={"always-copy": False, "system-site-packages": False}, flags={"always-copy": False, "system-site-packages": False},
with_pip=True, with_pip=True,
with_setuptools=True, with_setuptools=True,
......
...@@ -154,12 +154,14 @@ VERSION_3_7_1 = Version.parse("3.7.1") ...@@ -154,12 +154,14 @@ VERSION_3_7_1 = Version.parse("3.7.1")
def check_output_wrapper( def check_output_wrapper(
version: Version = VERSION_3_7_1, version: Version = VERSION_3_7_1,
) -> Callable[[List[str], Any, Any], str]: ) -> Callable[[str, Any, Any], str]:
def check_output(cmd: List[str], *args: Any, **kwargs: Any) -> str: def check_output(cmd: str, *args: Any, **kwargs: Any) -> str:
if "sys.version_info[:3]" in cmd: if "sys.version_info[:3]" in cmd:
return version.text return version.text
elif "sys.version_info[:2]" in cmd: elif "sys.version_info[:2]" in cmd:
return f"{version.major}.{version.minor}" return f"{version.major}.{version.minor}"
elif '-c "import sys; print(sys.executable)"' in cmd:
return f"/usr/bin/{cmd.split()[0]}"
else: else:
return str(Path("/prefix")) return str(Path("/prefix"))
...@@ -193,7 +195,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -193,7 +195,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
m.assert_called_with( m.assert_called_with(
Path(tmp_dir) / f"{venv_name}-py3.7", Path(tmp_dir) / f"{venv_name}-py3.7",
executable="python3.7", executable="/usr/bin/python3.7",
flags={"always-copy": False, "system-site-packages": False}, flags={"always-copy": False, "system-site-packages": False},
with_pip=True, with_pip=True,
with_setuptools=True, with_setuptools=True,
...@@ -328,7 +330,7 @@ def test_activate_activates_different_virtualenv_with_envs_file( ...@@ -328,7 +330,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
m.assert_called_with( m.assert_called_with(
Path(tmp_dir) / f"{venv_name}-py3.6", Path(tmp_dir) / f"{venv_name}-py3.6",
executable="python3.6", executable="/usr/bin/python3.6",
flags={"always-copy": False, "system-site-packages": False}, flags={"always-copy": False, "system-site-packages": False},
with_pip=True, with_pip=True,
with_setuptools=True, with_setuptools=True,
...@@ -389,7 +391,7 @@ def test_activate_activates_recreates_for_different_patch( ...@@ -389,7 +391,7 @@ def test_activate_activates_recreates_for_different_patch(
build_venv_m.assert_called_with( build_venv_m.assert_called_with(
Path(tmp_dir) / f"{venv_name}-py3.7", Path(tmp_dir) / f"{venv_name}-py3.7",
executable="python3.7", executable="/usr/bin/python3.7",
flags={"always-copy": False, "system-site-packages": False}, flags={"always-copy": False, "system-site-packages": False},
with_pip=True, with_pip=True,
with_setuptools=True, with_setuptools=True,
...@@ -1022,7 +1024,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( ...@@ -1022,7 +1024,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
m.assert_called_with( m.assert_called_with(
poetry.file.parent / ".venv", poetry.file.parent / ".venv",
executable="python3.7", executable="/usr/bin/python3.7",
flags={"always-copy": False, "system-site-packages": False}, flags={"always-copy": False, "system-site-packages": False},
with_pip=True, with_pip=True,
with_setuptools=True, with_setuptools=True,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment