Commit dc7409e
Make ephemeral exec, venv repl and scie compatible (#3129)
Fix so that scie pex (zipapp, venv) can 1. drop into repl and 2. run in
ephemeral run mode via `-- -c`.
```shell
#!/usr/bin/env bash
set -euo pipefail
TMPDIR=$(mktemp -d)
PEX_ROOT="$TMPDIR/pex_root"
uv run python -m pex . -c pex -o "$TMPDIR/pex.pex" --scie eager --venv --pex-root "$PEX_ROOT" --runtime-pex-root "$PEX_ROOT" 2>&1 | tail -1
echo "=== Venv scie: -- -c ==="
"$TMPDIR/pex" --pex-root "$PEX_ROOT" --runtime-pex-root "$PEX_ROOT" --interpreter-constraint 'CPython>=3.12' -- -c 'import sys; print(sys.executable)' 2>&1
echo "EXIT: $?"
echo ""
echo "=== Venv scie: REPL ==="
echo 'import sys; print("REPL:", sys.executable); quit()' | "$TMPDIR/pex" --pex-root "$PEX_ROOT" --runtime-pex-root "$PEX_ROOT" --interpreter-constraint 'CPython>=3.12' -- 2>&1
echo "EXIT: $?"
echo ""
echo "=== Non-venv scie: -- -c ==="
TMPDIR2=$(mktemp -d)
uv run python -m pex . -c pex -o "$TMPDIR2/pex.pex" --scie eager 2>&1 | tail -1
"$TMPDIR2/pex" --interpreter-constraint 'CPython>=3.12' -- -c 'import sys; print(sys.executable)' 2>&1
echo "EXIT: $?"
```
This gives me on branch:
```console
(pex-dev) ➜ pex git:(fix/scie-ephemeral-run-mode) ✗ bash test_scie_ephemeral.sh
/tmp/tmp.Uj3pbC1P18/pex
=== Venv scie: -- -c ===
/tmp/tmp.Uj3pbC1P18/pex_root/scies/0/base/86232383051a0950a74a9486949c87f88da45978bafa8d826c2f268629a3f508/cpython-3.12.13+20260325-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.12
EXIT: 0
=== Venv scie: REPL ===
Pex 2.91.4 ephemeral hermetic environment with no dependencies.
Python 3.12.13 (main, Mar 24 2026, 22:49:22) [Clang 22.1.1 ] on linux
Type "help", "pex", "copyright", "credits" or "license" for more information.
>>> REPL: /tmp/tmp.Uj3pbC1P18/pex_root/scies/0/base/86232383051a0950a74a9486949c87f88da45978bafa8d826c2f268629a3f508/cpython-3.12.13+20260325-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.12
EXIT: 0
=== Non-venv scie: -- -c ===
/tmp/tmp.3ibEcHDvMR/pex
/home/tobias/.cache/nce/86232383051a0950a74a9486949c87f88da45978bafa8d826c2f268629a3f508/cpython-3.12.13+20260325-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.12
EXIT: 0
```
On main ephemeral exec and venv+repl fail in different ways:
```console
(pex-dev) ➜ pex git:(main) ✗ bash test_scie_ephemeral.sh
/tmp/tmp.tPRXEL8YLa/pex
=== Venv scie: -- -c ===
Ignoring the following environment variables in Pex venv mode:
_PEX_CLI_RUN=/tmp/tmp.tPRXEL8YLa/pex
__PEX_ENTRY_POINT__=/tmp/tmp.tPRXEL8YLa/pex_root/venvs/3/d806b12a09b8ad5281bf3d990cb91bfb694c1be1/414e2ae92b4573e3049bcfe135ed1296986a612d
Could not find script 'import sys; print(sys.executable)' in any distribution within PEX!
EXIT: 1
=== Venv scie: REPL ===
Ignoring the following environment variables in Pex venv mode:
_PEX_CLI_RUN=/tmp/tmp.tPRXEL8YLa/pex
__PEX_ENTRY_POINT__=/tmp/tmp.tPRXEL8YLa/pex_root/venvs/3/d806b12a09b8ad5281bf3d990cb91bfb694c1be1/414e2ae92b4573e3049bcfe135ed1296986a612d
Ignoring the following environment variables in Pex venv mode:
_PEX_CLI_RUN=/tmp/tmp.tPRXEL8YLa/pex
_PEX_CLI_RUN_NO_ARGS=/tmp/tmp.tPRXEL8YLa/pex
__PEX_ENTRY_POINT__=/tmp/tmp.tPRXEL8YLa/pex_root/venvs/3/d806b12a09b8ad5281bf3d990cb91bfb694c1be1/414e2ae92b4573e3049bcfe135ed1296986a612d
... # this loops forever
=== Non-venv scie: -- -c ===
/tmp/tmp.seG0un8tmn/pex
Could not find script 'import sys; print(sys.executable)' in any distribution within PEX!
EXIT: 1
```
---------
Co-authored-by: John Sirois <john.sirois@gmail.com>1 parent 013a078 commit dc7409e
File tree
6 files changed
+84
-6
lines changed- pex
- bin
- tests/integration
- cli/commands
- scie
6 files changed
+84
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1289 | 1289 | | |
1290 | 1290 | | |
1291 | 1291 | | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
1292 | 1297 | | |
1293 | 1298 | | |
1294 | 1299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | | - | |
235 | | - | |
236 | | - | |
| 234 | + | |
237 | 235 | | |
| 236 | + | |
238 | 237 | | |
239 | 238 | | |
240 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
0 commit comments