-
-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds -m
option to saved .pex file interpreter emulation
#418
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR, this looks reasonable to me w/ one comment.
would also like to see an integration test exercising the new feature before landing.
pex/pex.py
Outdated
import code | ||
code.interact() | ||
elif sys.argv[1] == '-m': | ||
mod = sys.argv[2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this unchecked access of index position 2 would cause an unhandled IndexError
for the case of ./a.pex -m
.
isn't this what |
This allows you to invoke a module from a saved PEX file with `app.pex -m <module>`, in addition to invoking a script with `app.pex <file>` and a REPL with `app.pex`, as could already be done previously. This makes a saved PEX file more suitable as a basic replacement for the `python` binary on platforms that allow you to do that but that don't have good support for Python dependency management themselves, such as PySpark.
Added an extra check to avoid possible It's true that this new flag does something you could already accomplish by setting But my use case involves trying to use the built PEX file as the Python binary with a framework that doesn't know about |
it might be worth noting that the Another way of achieving what you want without modifying pex source is to simply have a wrapper script that handles this
It should also be noted that you can use pex files as the shebang of a script a la Not trying to discourage this change, just offering potential solutions that might work w/o cutting a new feature. |
my understanding is that the |
Indeed, in order to get pex working with PySpark now, I'm doing something very similar to what @sixninetynine suggested: with every PySpark job we write, I include a bash script that contains This has been working fine for us for the last couple months, but as the number of PySpark jobs grows, so too does the number of places where this set of shim scripts needs to be duplicated, and shipped along with every run of every job. I feel it would be cleaner to move the functionality into the upstream interpreter logic, but of course I'll leave the final design decision to you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding tests - one last comment and we should be good to merge.
code.interact() | ||
elif len(sys.argv) > 2 and sys.argv[1] == '-m': | ||
mod = sys.argv[2] | ||
sys.argv = sys.argv[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.argv
should not be modified here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noting that sys.argv
is modified below in the existing code too.. but I don't think that's necessary either. mind yanking it too while you're in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually.. scratch that.. I see why the sys.argv
modification is needed now (sorry about the thrash).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure what the reason for sys.argv
modification was, so I was just trying to match the behavior below. If a different modification is needed here, let me know and I can make that change.
@kwlzn If you let me know what the desired behavior is for modifying |
If anything else needs to be changed before this can be merged, please let me know and I'll be happy to change it. |
@kwlzn Any thoughts on what further changes are needed? |
Superseded by #563 |
This allows you to invoke a module from a saved PEX file with
app.pex -m <module>
, in addition to invoking a script withapp.pex <file>
and a REPL withapp.pex
, as could already be done previously.This makes a saved PEX file more suitable as a basic replacement for the
python
binary on platforms that allow you to do that but that don't have good support for Python dependency management themselves, such as PySpark.