Skip to content

Commit 5edb2b7

Browse files
committed
alternative generic solution by returning sys.executable
1 parent 290d7fd commit 5edb2b7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: src/poetry/console/application.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,30 @@ def configure_env(
290290

291291
io = event.io
292292
poetry = command.poetry
293+
293294
executable = None
295+
find_compatible = None
294296

297+
# add on option to trigger this
295298
with contextlib.suppress(CalledProcessError):
296299
executable = decode(
297300
subprocess.check_output(
298-
list_to_shell_command(["pyenv", "which", "python"]),
301+
list_to_shell_command(
302+
[
303+
"python",
304+
"-c",
305+
'"import sys; print(sys.executable)"',
306+
]
307+
),
299308
shell=True,
300309
).strip()
301310
)
311+
find_compatible = True
302312

303313
env_manager = EnvManager(poetry)
304-
env = env_manager.create_venv(io, executable=executable)
314+
env = env_manager.create_venv(
315+
io, executable=executable, find_compatible=find_compatible
316+
)
305317

306318
if env.is_venv() and io.is_verbose():
307319
io.write_line(f"Using virtualenv: <comment>{env.path}</>")

Diff for: src/poetry/utils/env.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ def create_venv(
775775
name: Optional[str] = None,
776776
executable: Optional[str] = None,
777777
force: bool = False,
778+
find_compatible: Optional[bool] = None,
778779
) -> Union["SystemEnv", "VirtualEnv"]:
779780
if self._env is not None and not force:
780781
return self._env
@@ -828,7 +829,7 @@ def create_venv(
828829
# If an executable has been specified, we stop there
829830
# and notify the user of the incompatibility.
830831
# Otherwise, we try to find a compatible Python version.
831-
if executable:
832+
if executable and not find_compatible:
832833
raise NoCompatiblePythonVersionFound(
833834
self._poetry.package.python_versions, python_patch
834835
)

0 commit comments

Comments
 (0)