Skip to content

Commit

Permalink
use shutil.which() to detect the active python
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Apr 6, 2023
1 parent 860c838 commit 809e98c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import platform
import plistlib
import re
import shutil
import subprocess
import sys
import sysconfig
Expand Down Expand Up @@ -532,26 +533,31 @@ def _full_python_path(python: str) -> Path:
@staticmethod
def _detect_active_python(io: None | IO = None) -> Path | None:
io = io or NullIO()
io.write_error_line(
(
"Trying to detect current active python executable as specified in"
" the config."
),
verbosity=Verbosity.VERBOSE,
)

executable = None
python = shutil.which("python")
if python is not None:
with contextlib.suppress(EnvCommandError):
executable = EnvManager._full_python_path(python)

try:
io.write_error_line(
(
"Trying to detect current active python executable as specified in"
" the config."
),
verbosity=Verbosity.VERBOSE,
)
executable = EnvManager._full_python_path("python")
if executable is not None:
io.write_error_line(f"Found: {executable}", verbosity=Verbosity.VERBOSE)
except EnvCommandError:
else:
io.write_error_line(
(
"Unable to detect the current active python executable. Falling"
" back to default."
),
verbosity=Verbosity.VERBOSE,
)

return executable

@staticmethod
Expand Down

0 comments on commit 809e98c

Please sign in to comment.