Hi, it seems that `pex` doesn’t allow to specify ...
# pex
b
Hi, it seems that
pex
doesn’t allow to specify the
script
and
entry_point
at the same time, any special reason for that ? Sometime it’s convenient to run the command like
gunicorn app:app
e
@bulky-evening-62934 pardon my ignorance here - is
gunicorn
in your example a script that needs an entry point argument to run? In other words are you wanting Pex to accept both an entry point (whether specified by a
script
or an
entry_point
) and some additional fixed arguments to always pass to that entry point?
b
I’m just curious about the reason behind this design, actually I could set the script as
gunicorn
and run the specific entry point with the built pex file. But why we set this limitation ?
e
Before I can answer that I want to make sure I understand what you want / need here. Per my question above, is it true that the
gunicorn
script expects an entry point argument and that you want to seal that argument in to the PEX file so that you do not need to type
./my-gunicorn.pex my.entry:point
but instead can just type
./my-gunicorn.pex
?
b
yes
e
OK - So I'd re-characterize the feature needed here. Would this work for you?:
Copy code
pex gunicorn my_app==1.0.0. -c gunicorn --program-args my.entry:point -o my-gunicorn.pex
In other words, the fact this one script (gunicorn) needs an entry point argument is specific. More generally, you may have a different console script that needs other types of arguments. The main point is you want to set those arguments once at pex creation time.
In the example above
--program-args
would be the new feature.
Along these lines, for full generality, you might imagine
--program-env
to seal in default environment variables to the PEX that the entry point needs.
If my sketch makes sense and suits your needs I think it probably makes sense as a new Pex feature.
b
Got it, exact,
program-args
seems to be an appealing option. To make sure, that’s the same effect as I pass those args when running the built pex file right ?
e
Correct. I think the main semantics would need to be
[script|entry point] (program-args) ... additional command line args ...
. So for the example above of:
Copy code
ex gunicorn my_app==1.0.0. -c gunicorn --program-args my.entry:point -o my-gunicorn.pex
Running:
Copy code
./my-gunicorn.pex --bob sally george
Would actually run:
Copy code
./my-gunicorn.pex my.entry:point --bob sally george
👍 1
b
Thanks a lot! Another unrelated question, I don’t want to set python shebang when building the pex file, if I would like to use a specific python interpreter when running the pex file, setting
PEX_PYTHON=/path/to/python
should be enough ?
e
/path/to/python my.pex
is enough. Using
PEX_PYTHON=/path/to/python my.pex
works too, but is a bit more indirect than it need be.
b
great! And for setting pex root, I could do
PEX_ROOT=/path
? do you know where I could find the document/code which lists those Pex ENV VARs ?
e
You can use
pex --help-variables
.
Note, there is a fairly new Pex CLI flag
--runtime-pex-root
that lets you seal in a
PEX_ROOT
for your PEX file to use when run. This may allow you to eliminate saying
PEX_ROOT=foo ./my.pex
if you know the machines you'll run this pex on always have
foo
available as an appropriate
PEX_ROOT
.
OK - the feature we discussed is documented here: https://github.com/pantsbuild/pex/issues/987 I think that could clean up lambdex creation.
b
Oh, that’s nice For some reason, I cannot make sure the pex root is always same, but I could still use PEX_ROOT right ?
e
That's right.
👍 1
Hey @bulky-evening-62934, I wanted to close this loop. I'll be away for most of the rest of June after this week so I won't be able to get to https://github.com/pantsbuild/pex/issues/987 for a while. If you have any interest in implementing the feature though I could give you a few pointers. I think it's a pretty manageable change for a new contributor.
b
hey @enough-analyst-54434, sounds good to me, tell me how could i help on this topic ? BTW,
--program-args
could be something complex like
app:main --arg1 XX --arg2 XX
or just
app:main
?
e
It could be complex.
Ok, I'll add some pointers on the issue to aid hacking on this.
👍 1
OK, finally got around to this. @bulky-evening-62934 I've added details to the issue spelling out what needs to be done: https://github.com/pantsbuild/pex/issues/987#issuecomment-642146041 If you need more info let me know and thanks in advance if you do decide to hack on this.
b
Sure, I will take a look at it ; )