Skip to content

Commit

Permalink
pass path to executable for getting a specific venv
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Jun 14, 2021
1 parent 9a6e18d commit 0ecffe0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,25 @@ class EnvManager:
def __init__(self, poetry: Poetry) -> None:
self._poetry = poetry

def _python_version(self, executable: str) -> str:
try:
python_version = decode(
subprocess.check_output(
list_to_shell_command(
[
executable,
"-c",
"\"import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))\"",
]
),
shell=True,
)
)
except CalledProcessError as e:
raise EnvCommandError(e)

return python_version

def activate(self, python: str, io: IO) -> "Env":
venv_path = self._poetry.config.get("virtualenvs.path")
if venv_path is None:
Expand Down Expand Up @@ -548,11 +567,18 @@ def deactivate(self, io: IO) -> None:

envs_file.write(envs)

def get(self, reload: bool = False) -> Union["VirtualEnv", "SystemEnv"]:
def get(
self, reload: bool = False, executable: Optional[str] = None
) -> Union["VirtualEnv", "SystemEnv"]:
if self._env is not None and not reload:
return self._env

python_minor = ".".join([str(v) for v in sys.version_info[:2]])
if executable:
python_version = self._python_version(executable)
python_version = Version.parse(python_version.strip())
python_minor = f"{python_version.major}.{python_version.minor}"
else:
python_minor = ".".join([str(v) for v in sys.version_info[:2]])

venv_path = self._poetry.config.get("virtualenvs.path")
if venv_path is None:
Expand Down Expand Up @@ -743,7 +769,7 @@ def create_venv(
return self._env

cwd = self._poetry.file.parent
env = self.get(reload=True)
env = self.get(reload=True, executable=executable)

if not env.is_sane():
force = True
Expand Down

0 comments on commit 0ecffe0

Please sign in to comment.