https://pantsbuild.org/ logo
#general
Title
# general
a

average-breakfast-91545

03/04/2023, 2:30 PM
If I have a python module in
myorg/myapp/mycomponent/handler.py
and a BUILD for a pex_binary in mycomponent with an entrypoint of
handler.py:run
, the resulting module in the binary is
___pex__.myorg.myapp.mycomponent.handler
. Is there some way to introspect that at build time and retrieve that value? For context, I'm interested in building a plugin for the serverless framework that uses pants to build a lambda zip, but I'll need to be able to set the handler on the function correctly.
e

enough-analyst-54434

03/04/2023, 2:34 PM
The
__pex__
bit, no. That's magic available in all (modern) PEX files. You need to know if you're using that magic or not in the given usage context. The rest though is stored in PEX metadata:
Copy code
unzip -qc my.pex PEX-INFO | jq .
You'll notice an entry point field.
If you have
pex
installed,
pex-tools my.pex info
🙌 1
If the PEX file is
--venv
or
--include-tools
then
PEX_TOOLS=1 ./my.pex info
a

average-breakfast-91545

03/04/2023, 2:37 PM
You mentioned in that GH issue that the entry_point wasn't necessary. Could you give a 20 second summary of why? Sorry for peppering with noob qs.
e

enough-analyst-54434

03/04/2023, 2:41 PM
The entry point allows you to execute the PEX as a single file binary:
./my.pex
- but you're not doing that. The server less framework is executing the entry point you need to separately tell it about.
a

average-breakfast-91545

03/04/2023, 2:42 PM
Understood
I think it's still useful in the case where I have multiple lambda handlers in a directory and I want to package them individually, right?
e

enough-analyst-54434

03/04/2023, 2:45 PM
Nope. All it's useful for is if you want to run the PEX file directly and have it do a thing by default. Without an entry point a PEX will run, but act like a hermetic self contained venv and drop you in a repl with the PEX contents on sys.path.
a

average-breakfast-91545

03/04/2023, 2:46 PM
so, if I have two handler modules
get_foo.py
and
upate_foo.py
, how would I specify separate pex_binaries for those?
e

enough-analyst-54434

03/04/2023, 2:46 PM
A PEX with no entry point is substitutable for
python
with all it's contents on that Python's sys.path.
@average-breakfast-91545 do you want 2 binaries or 1 binary with both handlers?
You can do either.
a

average-breakfast-91545

03/04/2023, 2:50 PM
Two binaries
e

enough-analyst-54434

03/04/2023, 2:50 PM
Then use two
pex_binary
targets if using Pants.
Are you using Pants or just Pex?
a

average-breakfast-91545

03/04/2023, 2:51 PM
Pants
e

enough-analyst-54434

03/04/2023, 2:52 PM
Yeah, so that's all. That's sort of obvious though so I suspect something else is going on.
a

average-breakfast-91545

03/04/2023, 2:52 PM
So use script over entry_point?
so I suspect something else is going on
Could well be just that I'm clueless
e

enough-analyst-54434

03/04/2023, 2:53 PM
So, again, you don't need either for AWS lambda since you need to repeat yourself anyhow and re-tell that entry point to AWS in its config.
IE this PEX is not for running like
./my.pex
It's a fancy zip sys.path entry.
a

average-breakfast-91545

03/04/2023, 2:54 PM
Okay, so I have two python modules in a directory, with different sets of dependencies. I'd like to package those into two pex files containing only those dependencies. How do I specify those binaries?
That's what I'm not understanding 🙂
e

enough-analyst-54434

03/04/2023, 2:56 PM
Make two separate
python_source
(singular) targets to own the modules. Refer to 1 of those targets in the corresponding
pex_binary
target.
👍 1
Then you can leave
script
/
entry_point
off each and still get exactly and only what you need in each.
a

average-breakfast-91545

03/04/2023, 2:57 PM
Thank you - you've been very helpful
e

enough-analyst-54434

03/04/2023, 2:57 PM
If you want to not do that, then use
entry_point
The
script
is for console scripts, which is a 3rd party thing. These only: https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-console-scripts-entry-point
👍 1