Skip to content

Commit

Permalink
fix: take virtualenvs.prefer-active-python into account when gettin…
Browse files Browse the repository at this point in the history
…g current environment
  • Loading branch information
finswimmer committed Nov 6, 2022
1 parent 5f51efb commit a42859d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/poetry/utils/env.py
Expand Up @@ -556,6 +556,26 @@ def _detect_active_python(self) -> str | None:
)
return executable

def _get_python_version(self) -> list[int]:
version_info = list(sys.version_info[:3])

if self._poetry.config.get("virtualenvs.prefer-active-python"):
executable = self._detect_active_python()

if executable:
python_patch = decode(
subprocess.check_output(
list_to_shell_command(
[executable, "-c", GET_PYTHON_VERSION_ONELINER]
),
shell=True,
).strip()
)

version_info = [int(v) for v in python_patch.split(".")[:3]]

return version_info

def activate(self, python: str) -> Env:
venv_path = self._poetry.config.virtualenvs_path
cwd = self._poetry.file.parent
Expand Down Expand Up @@ -667,7 +687,7 @@ def get(self, reload: bool = False) -> Env:
if self._env is not None and not reload:
return self._env

python_minor = ".".join([str(v) for v in sys.version_info[:2]])
python_minor = ".".join([str(v) for v in self._get_python_version()[:2]])

venv_path = self._poetry.config.virtualenvs_path

Expand Down

0 comments on commit a42859d

Please sign in to comment.