nutritious-minister-3808
08/16/2022, 1:01 PM-i
interactive mode?
There is a script in a docker container that was previously executed using /path/to/venv/bin/python -i script.py arg1 arg2
. Now with pantsbuild, the /path/to/venv
no longer needs to exist because everything else in the container is packaged using pex. I have considered leaving the current venv there as well as possibly using a modification of this recipe to make a new venv but I was wondering if there was some possible trickery with pex that I was overlooking?ancient-breakfast-45303
08/16/2022, 1:45 PMPEX_INTERPRETER=1 ./my.pex <myscript> arg1
enough-analyst-54434
08/16/2022, 1:45 PM$ pex ansicolors -o ansicolors.pex
$ cat <<EOF > script.py
> import colors
>
> print(colors.blue("Interactive?"))
> EOF
$ ./ansicolors.pex -i script.py
Interactive?
Traceback (most recent call last):
File "/home/jsirois/.pex/unzipped_pexes/28923b82caa398e274ae9593d6da0cfb4344ef1a/__main__.py", line 103, in <module>
bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
File "/home/jsirois/.pex/unzipped_pexes/28923b82caa398e274ae9593d6da0cfb4344ef1a/.bootstrap/pex/pex_bootstrapper.py", line 601, in bootstrap_pex
pex.PEX(entry_point).execute()
File "/home/jsirois/.pex/unzipped_pexes/28923b82caa398e274ae9593d6da0cfb4344ef1a/.bootstrap/pex/pex.py", line 540, in execute
sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
SystemExit
>>>
Unfortunately, it looks like the PEX_INTERPRETER=1 suppression doesn't quite work for interactive mode:
$ pex cowsay --script cowsay -o cowsay.pex --venv prepend
$ ./cowsay.pex 'Moo!'
____
| Moo! |
====
\
\
^__^
(oo)\_______
(__)\ )\/\
||----w |
|| ||
$ PEX_INTERPRETER=1 ./cowsay.pex -c 'import cowsay; cowsay.tux("Quack?")'
______
| Quack? |
======
\
\
\
.--.
|o_o |
|:_/ |
// \ \
(| | )
/'\_ _/`\
\___)=(___/
$ cat <<EOF > script.py
import cowsay
cowsay.tux("It's good for you!")
EOF
$ PEX_INTERPRETER=1 ./cowsay.pex -i script.py
Re-executing with Python interpreter options: cmdline='/home/jsirois/.pex/venvs/c16958b5b5ab036132bf7669f3d56e9ae1315ac0/5985ed09b49a653d6596b0e14d134c5456cf1a9f/bin/python -i /home/jsirois/.pex/venvs/c16958b5b5ab036132bf7669f3d56e9ae1315ac0/5985ed09b49a653d6596b0e14d134c5456cf1a9f/pex script.py'
_________
| script.py |
=========
\
\
^__^
(oo)\_______
(__)\ )\/\
||----w |
|| ||
Traceback (most recent call last):
File "/home/jsirois/.pex/venvs/c16958b5b5ab036132bf7669f3d56e9ae1315ac0/5985ed09b49a653d6596b0e14d134c5456cf1a9f/pex", line 245, in <module>
sys.exit(func())
SystemExit
>>>
nutritious-minister-3808
08/16/2022, 1:54 PM