Skip to content

Commit

Permalink
alternative generic solution by returning sys.executable
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Dec 30, 2021
1 parent b70e5ef commit c5a4e6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,30 @@ def configure_env(

io = event.io
poetry = command.poetry

executable = None
find_compatible = None

# add on option to trigger this
with contextlib.suppress(CalledProcessError):
executable = decode(
subprocess.check_output(
list_to_shell_command(["pyenv", "which", "python"]),
list_to_shell_command(
[
"python",
"-c",
'"import sys; print(sys.executable)"',
]
),
shell=True,
).strip()
)
find_compatible = True

env_manager = EnvManager(poetry)
env = env_manager.create_venv(io, executable=executable)
env = env_manager.create_venv(
io, executable=executable, find_compatible=find_compatible
)

if env.is_venv() and io.is_verbose():
io.write_line(f"Using virtualenv: <comment>{env.path}</>")
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ def create_venv(
name: Optional[str] = None,
executable: Optional[str] = None,
force: bool = False,
find_compatible: Optional[bool] = None,
) -> Union["SystemEnv", "VirtualEnv"]:
if self._env is not None and not force:
return self._env
Expand Down Expand Up @@ -820,7 +821,7 @@ def create_venv(
# If an executable has been specified, we stop there
# and notify the user of the incompatibility.
# Otherwise, we try to find a compatible Python version.
if executable:
if executable and not find_compatible:
raise NoCompatiblePythonVersionFound(
self._poetry.package.python_versions, python_patch
)
Expand Down

0 comments on commit c5a4e6c

Please sign in to comment.