quaint-forest-8735
08/26/2022, 12:21 AMpex
CLI again to produce the same pex w/ the extra file. This seems brittle, so was curious if there's any functionality in PexBuilder
that could make this cleanerquaint-forest-8735
08/26/2022, 12:22 AMenough-analyst-54434
08/26/2022, 12:35 AMenough-analyst-54434
08/26/2022, 12:37 AMPEX
env var will be available to the running PEX code to locate the original zip file (it gets unpacked and spread at runtime). I'm not sure if the existing unpacking will unpack your added files or not; so you may need this trick to unpack the file / get its stream yourself.quaint-forest-8735
08/26/2022, 12:38 AMquaint-forest-8735
08/26/2022, 12:38 AMenough-analyst-54434
08/26/2022, 12:40 AM__pex__
import handling in modern Pex? I have lost track of various threads and can't remember if I discussed this with you or someone else.quaint-forest-8735
08/26/2022, 12:40 AMpex
executable from githubenough-analyst-54434
08/26/2022, 12:41 AMquaint-forest-8735
08/26/2022, 12:41 AMenough-analyst-54434
08/26/2022, 12:43 AM$ cat foo.py
with open("extra") as fp:
print(fp.read())
$ pex --exe foo.py -o foo.pex
$ echo "Remora-like" > extra
$ zip foo.pex extra
adding: extra (stored 0%)
$ ./foo.pex
Remora-like
enough-analyst-54434
08/26/2022, 12:43 AMenough-analyst-54434
08/26/2022, 12:46 AMPEX
env var trick:
$ cat foo.py
import contextlib
import os
import zipfile
with contextlib.closing(zipfile.ZipFile(os.environ["PEX"])) as zf:
print(zf.read("extra"))
$ pex --exe foo.py -o foo.pex
$ echo "Remora-like" > extra
$ zip foo.pex extra
adding: extra (stored 0%)
$ rm extra
$ ./foo.pex
b'Remora-like\n'
enough-analyst-54434
08/26/2022, 12:47 AMextra
file the 1st time after adding it to the zip and the PEX code was just reading that loose file.quaint-forest-8735
08/26/2022, 1:37 AMzipfile
that also fixes the permissions so we can accomplish this w/ a tool in our repo, thank you again for the pointers