I'm doing some Python development for ARM. I don't...
# general
p
I'm doing some Python development for ARM. I don't have an ARM device but our CI produces an arm64 .pex file. Sometimes I then go to test it on a device and discover I've got like a one line typo I'd like to quickly fix and test. Does anyone know of an easy way to unzip a .pex, edit it, and then re-zip it? I did come up with the following to run an un-zipped pex:
PYTHONPATH=$(echo $(pwd)/.deps/* | tr ' ' ':') python -m device.session.main
but that's a bit ugly and I don't know how to convert that back to a
.pex
easily (I think I could figure out some flags to tell it to use the
.deps
, not to check
pypi
, etc. but is there an easier way?
h
How are you building the pex? The
pex
tool takes a
--layout
flag, with one of the values
{zipapp,packed,loose}
. You're building a zipapp (which is the default) but you might want to try
packed
or
loose
, which will create a directory instead.
The distinction between
packed
and
loose
is, from the help:
Copy code
--layout {zipapp,packed,loose}
                        By default, a PEX is created as a single file zipapp when `-o` is specified, but either a packed or loose directory tree based layout can be chosen instead. A packed layout PEX is an executable directory
                        structure designed to have cache-friendly characteristics for syncing incremental updates to PEXed applications over a network. At the top level of the packed directory tree there is an executable
                        `__main__.py`script. The directory can also be executed by passing its path to a Python executable; e.g: `python packed-pex-dir/`. The Pex bootstrap code and all dependency code are packed into individual zip
                        files for efficient caching and syncing. A loose layout PEX is similar to a packed PEX, except that neither the Pex bootstrap code nor the dependency code are packed into zip files, but are instead present as
                        collections of loose files in the directory tree providing different caching and syncing tradeoffs. Both zipapp and packed layouts install themselves in the PEX_ROOT as loose apps by default before executing,
                        but these layouts compose with `--venv` execution mode as well and support `--seed`ing. (default: zipapp)
If you're building via Pants using a
pex_binary
target, you can set
execution_mode
on the
pex_binary
to
venv
- you still get a single file in dist, but when you execute it, it first splats itself out into a venv, and then you can tinker inside that venv
I think
p
cool. Thanks!