Reputation: 33
Using the pex tool to package python proyects (https://pex.readthedocs.io/en/v2.1.55/); is there a way to know where the original Pex file is located?. Until now I just have been able to see where the "unzipped" files are located but need to programmatically resolve the original file location since the program can run under different environments. I have a test script ~/print_location.py
import pathlib
print(pathlib.Path(__file__))
And the pex binary ~/print_location.pex
Output:/home/usr/.pex/installed_wheels/4d...e5/print_location-1-py3-none-any.whl/print_location.py
Expected:/home/usr/print_location.pex
Upvotes: 1
Views: 769
Reputation: 481
As of Pex 2.1.53 at runtime a PEX exposes the original PEX file location in the PEX
environment variable.
The docs say:
If your code benefits from knowing whether it is running from within a PEX or not, you can inspect the PEX environment variable. If it is set, it will be the absolute path of the PEX your code is running in. Normally this will be a PEX zip file, but it could be a directory path if the PEX was built with a --layout of packed or loose.
Upvotes: 2