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
()
| 69 | |
| 70 | |
| 71 | def _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 |
no test coverage detected