Hi Is there an easy to get the `pex.platform` for ...
# pex
f
Hi Is there an easy to get the
pex.platform
for your local machine? Like some python code to output the platform string?
e
A few things: In general there is no such thing as a Pex
--platform
for your machine. The
--platform
is per interpreter per machine. So if you have more than one interpreter, you must have in mind which you care about. If you read
pex --help
for
--platform
you'll find it details the platform for the interpreter that is running
pex --help
. You absolutely positively never ever want to use
--platform
anyhow. Please read up on
--complete-platform
and use that instead: https://pex.readthedocs.io/en/v2.1.147/buildingpex.html#complete-platform
f
Basically, I want to build pex or multiple pexs to serve on my local environment (mac) and linux based docker. Is this the correct method? I.e. specifying the platform or complete_platform? This is what I understood by reading the documentation.
e
The correct method is using
--complete-platform
to target the "foreign" interpreter, yes. The
--platform
argument is much older. It originated at Twitter and is broken for most situations. It's only supported because Pex has a policy of not breaking backwards compatibility ever in the 2.x release series.
When using
--complete-platform
/ building a "multiplatform" PEX you probably want to control
--python-shebang
instead of accepting the default to ensure it is a shebang that will work to find all targeted interpreters on all target machines or else use
--sh-boot
.
You can
head -1 my.pex
to see what the default shebang is. That shebang needs to be valid on all targeted machines if you want to run the PEX directly, like so:
./my.pex
. If you run the PEX using Python (
/this/python my.pex
), then, of course, the shebang doesn't matter / isn't used by the OS.
f
Actually, I don't think that's the issue. The third party dependencies have different packages for MacOS vs Linux
I am trying to solve for that.
e
Understood. But if you target, say Python 3.10 & 3.11 for Mac arm and Linux x86-64, so 4 platforms, then, if the shebang is
!/usr/bin/env python3.10
you'll have a problem when the PEX lands on a either a Mac arm or Linux x86-64 machine with Python 3.11 but not 3.10.
f
Got it. We are using python38 on both.
Any suggestions on how I should approach the problem?
e
What problem?
f
The third party dependencies have different packages for MacOS vs Linux
e
Pex handles that. You need to get really specific if you're looking for help. You went silent on a prior thread where I produced an example repo for example.
👍 1