pex-tool / pex

A tool for generating .pex (Python EXecutable) files, lock files and venvs.
https://docs.pex-tool.org
Apache License 2.0
2.49k stars 254 forks source link

Implement support for preserving and injecting Python args. #2427

Closed jsirois closed 4 weeks ago

jsirois commented 4 weeks ago

Support preserving and injecting Python args.

Pex now supports --inject-python-args similar to --inject-args but for specifying arguments to pass to the Python interpreter as opposed to arguments to pass to the application code. This is supported for both zipapp and venv execution modes as well as standard shebang launching, launching via a Python explicitly or via the --sh-boot mechanism.

In addition, PEX files now support detecting and passing through Python args embedded in shebangs or passed explicitly on the command line for all Pythons Pex supports save for PyPy<3.10 where there appears to be no facility to retrieve the original argv PyPy was executed with.

Closes #2422

jsirois commented 4 weeks ago

This was a good idea from @bkad and it completes the work started by @BrandonTheBuilder in #1746 at PyCon US 2022. I think Pex now supports all Python interpreter args that make sense in all modes of operation.

zmanji commented 4 weeks ago

The tests make sense to me and capture the original request of passing -u to the interpreter.