MCPcopy Create free account
hub / github.com/Drakkar-Software/OctoBot / _shell_python

Function _shell_python

pants-plugins/python_plugins/register.py:71–89  ·  view source on GitHub ↗

Return the Python interpreter active in the user's shell. Pants runs under its own managed Python, so sys.executable points to Pants' interpreter, not the user's. We resolve the shell's interpreter in priority order: 1. $VIRTUAL_ENV/bin/python (unix) or $VIRTUAL_ENV/Scripts/python.exe

()

Source from the content-addressed store, hash-verified

69
70
71def _shell_python() -> str:
72 """Return the Python interpreter active in the user's shell.
73
74 Pants runs under its own managed Python, so sys.executable points to Pants' interpreter,
75 not the user's. We resolve the shell's interpreter in priority order:
76 1. $VIRTUAL_ENV/bin/python (unix) or $VIRTUAL_ENV/Scripts/python.exe (windows)
77 2. python3 / python on $PATH — e.g. a conda env or system install
78 Falls back to sys.executable if nothing else is found.
79 """
80 venv = os.environ.get("VIRTUAL_ENV")
81 if venv:
82 # Windows venvs use Scripts/, unix venvs use bin/
83 for candidate in (
84 os.path.join(venv, "Scripts", "python.exe"),
85 os.path.join(venv, "bin", "python"),
86 ):
87 if os.path.isfile(candidate):
88 return candidate
89 return shutil.which("python3") or shutil.which("python") or sys.executable
90
91
92@goal_rule

Callers 1

install_depsFunction · 0.85

Calls 2

getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected