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 efab161
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,22 @@ def _detect_active_python(self) -> str | None:
)
return executable

def _get_python_version(self) -> list[int]:
if self._poetry.config.get("virtualenvs.prefer-active-python"):
executable = self._detect_active_python()
python_patch = decode(
subprocess.check_output(
list_to_shell_command(
[executable, "-c", GET_PYTHON_VERSION_ONELINER]
),
shell=True,
).strip()
)

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

return sys.version_info[:3]

def activate(self, python: str) -> Env:
venv_path = self._poetry.config.virtualenvs_path
cwd = self._poetry.file.parent
Expand Down Expand Up @@ -667,7 +683,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 efab161

Please sign in to comment.