-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Decouple PEX runtime interpreter selection from buildtime interpreter selection. #1020
Comments
I created #1033 a few days ago, which I think may be quite similar in intent to this ticket. There are two main differences I can see:
I think that they seem quite complementary, in particular regarding this last point of yours:
This ticket would address that conundrum, whereas #1033 would enable specifically resolving wheels at build time for an exact
Which I think could be considered the "speed of light" in terms of what it is possible for Pex to do anyway. |
You can already do that. Whenever you don't expect the targeted interpreter (PythonInterpreter) to be on the local machine, you specify a Platform. If the PEX could be built on an unknown machine, you should exclusively use Platforms, say:
That combined with
You directly target two platforms and you don't need to be on either platform to build the PEX (as long as you're pointing at repos that already have all the requisite pre-built wheels available), but, if you do happen to be on one of the platforms and that platform does have the targeted interpreter, it will be resolved and used to build any missing wheels. |
Thank you so much! I will try to contribute a doc fix (if necessary) in response to your great comments on #1033. |
This is needed to support pex-tool#1020 and pex-tool#1108.
Work towards pex-tool#899, pex-tool#1020 and pex-tool#1108.
This removes our dependency on pkg_resources Environment / WorkingSet in favor of performing our own recursive resolve of runtime distributions to activate using distribution metadata. This fixes an old test bug noticed by Benjy but, more importanty, sets the stage to fix pex-tool#899, pex-tool#1020 and pex-tool#1108 by equipping PEXEnvironment with the ability to resolve the appropriate transitive set of distributions from a root set of requirements instead of the current full set of transitive requirements stored post-resolve in PexInfo.
We now only use the namespace package APIs when absolutely needed at runtime. Work towards pex-tool#1020
We now only use the namespace package APIs when absolutely needed at runtime. Work towards #1020
Previously two proxies for interpreter applicability were used: 1. The shebang selected interpreter or the explicit interpreter used to invoke the PEX. 2. Any embedded interpreter constraints. This could lead to selecting an interpreter that was not actually able to resolve all required distributions from within the PEX, which is the only real criteria, and a failure to boot. Fix the runtime interpreter resolution process to test an interpreter can resolve the PEX before using it or re-execing to it. In the use case, the resolve test performed is cached work and leads to no extra overhead. In the re-exec case the resolve test can cost O(100ms), but at the benefit of ensuring either the selected interpreter will definitely work or no interpreters on the search path can work. Fixes pex-tool#1020
There is more that can be done here to optimize the PEX ZIPAPP re-exec case - namely caching that the successfully tested interpreter works with the given PEX to avoid the testing the next time the PEX ZIPAPP is run, but I'm going to close this out with #1770 since the robustness issue has been addressed. |
Previously two proxies for interpreter applicability were used: 1. The shebang selected interpreter or the explicit interpreter used to invoke the PEX. 2. Any embedded interpreter constraints. This could lead to selecting an interpreter that was not actually able to resolve all required distributions from within the PEX, which is the only real criteria, and a failure to boot. Fix the runtime interpreter resolution process to test an interpreter can resolve the PEX before using it or re-execing to it. In the use case, the resolve test performed is cached work and leads to no extra overhead. In the re-exec case the resolve test can cost O(100ms), but at the benefit of ensuring either the selected interpreter will definitely work or no interpreters on the search path can work. Fixes #1020
The fix for pex-tool#1020 did not add language for the new resolve check failures.
The fix for #1020 did not add language for the new resolve check failures.
The Pex CLI supports various options for constraining the interpreters a given PEX should be built to work with. Today these are:
--python
or--interpreter-constraint
(these are mutually exclusive)--platform
And combinations of these are then possibly modified by
--resolve-local-platforms
and--use-first-matching-interpreter
.The result is a PEX file built by one or more local interpreters that can run in turn run on an unrelated set of interpreters. The last statement might be surprising, but is true and exposes the fundamental flaw in trying to use buildtime interpreter selection constraints to constrain runtime interpreter selection. To clarify, consider building a PEX file for Pex itself:
As we can see, the PEX file is universal since all contained distributions are universal and yet the PEX file will only run on a machine with a
python3.8
binary on thePATH
. Today this can be hacked around by either specifying an alternative--python-shebang
(say#!/usr/bin/env python
or executing the PEX file via a manually selected interpreter (/my/python pex.pex
).Ideally, once bootstrapped by a Pex compatible interpreter (Python 2.7 or Python3.5+), the PEX runtime should select a local interpreter compatible with the actual contained distributions. This would allow PEX files to run on all machines they should be able to run on assuming
#!/usr/bin/env python
points to a Pex compatible Python interpreter.Switching the PEX runtime to select interpreters based on contained distributions would fix at least 2 bugs:
#!/usr/bin/env python
(solves the above example bug in pex.pex).The latter bug today manifests when using, say,
--interpreter-constraints="CPython>=3.6"
which finds just a CPython 3.7 distributuion on the build machine. The resulting PEX can then potentially only run on CPython 3.7 interpreter if platform specific wheels were built but at runtime a CPython 3.6 interpreter will be selected if found even if a local CPython 3.7 is present.The text was updated successfully, but these errors were encountered: