<https://github.com/lablup/example-self-contained-...
# general
r
https://github.com/lablup/example-self-contained-python-app I have made a minimalistic example to combine pex + scie to build a self-contained self-bootstrapping Python app executable.
πŸŽ‰ 2
πŸ‘€ 1
Currently there are not many user-friendly docs, and I tried my best to figure out what is the minimal configuration to achieve this. Feedbacks are welcome!
https://github.com/lablup/example-self-contained-python-app/commit/f7db8e54bce4a4ea301d5ae2ec22f073896c2d1e I'm not sure why I must provide the absolute path of
science
executable, but this makes it portable with PATH.
w
Just FYI - I have a first pass at a plugin I needed to make for a project like 6-7 months ago. Has many limitations, but it's good for simple combinations https://github.com/sureshjoshi/pants-plugins/tree/main/pants-plugins/experimental/scie
πŸ‘€ 1
I've been using this in prod for the same amount of time
r
oh, that’s great! i will try it.
πŸ‘ 1
it seems to work pretty well, but i found a strange issue while working with some entrypoints of pex binary targets.
__main__.py
and
main.py
are lost in the pex package.;; I haven't done anything special with them....
is there any special treatment done to
main.py
or
__main__.py
when building pex?
hmm... it was some strange behavior of dependency resolution when
___init___.py
has
from . import module
patterns. I have added an explicit import there and resolved the missing
main.py
issue.
I had to manually update the science binary versions and the indygreg release date to match the interpreter constraint, and now confirmed the built binary is executed in a fresh new Ubuntu VM.
The last issue remains here... is that the executable downloads the indygreg build even though it seems to already include one considering the file size! (~26MB)
ah, this is not a bug; accidentally my pex build size was similar to the indygreg build...
πŸ˜† 1
w
That's a hilarious coincidence
πŸ˜‡ 1
Please note that my plugin could also be causing some inconsistencies you're seeing. So, if there are errors you see, PEX is it's own thing, my plugin is an attempted hack of a wrapper, that works for simple cases. I'll be formalizing it in the next couple of months and maybe PR'ing into main, but not until we can have > 1 PEX fix, as that's a silly, lazy limitation by me
πŸ‘ 1
r
yes, i’m currently seeing rough edges such as missing configurability without writing full lift.toml by myself, but still i appreciate your work!
w
Oh yeah, I did verrry limited work, because the lift.toml is so full specified already, seemed silly to go into too much depth on an API before I'd used it a lot
e
To answer the original question,
__main__.py
is treated specially, not by Pex per-se, but by any Python zipapp Pex-like thing. That file is taken over since it's the bootstrap entry point and Pex (or Shiv, etc.) uses it to wire up the
sys.path
for 3rd party dep consumption. In Pex's case the
__main__.py
contents are: https://github.com/pantsbuild/pex/blob/a43c48c2a4b18b352be2c3175e0ae363ff8876d7/pex/pex_builder.py#L122-L229 For Shiv it's much simpler: https://github.com/linkedin/shiv/blob/a0cb71d04e0d7b58bb8561677ea148eb89d5a499/src/shiv/builder.py#L33-L38
πŸ‘€ 1