-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
explicitly resolve Python for pex run/package #21948
base: main
Are you sure you want to change the base?
Conversation
Thanks for taking this on. There's CI errors that'll seem to be indicating real problems:
(Apologies if I end up telling you thinks you already know. This investigation is also firming up my understanding of pex.) As background, (AIUI) I think there's two broad categories for pex builds:
There's seem to be a few ways to specify specific platforms to build a PEX for:
These can all be specified multiple times and are additive, e.g., on my arm64 macOS machine, this builds a PEX compatible with (i.e. contains wheels for those platforms):
pex \
-v \
--layout=packed \
--complete-platform linux_cp310_x86_64.json \
--python $(which python3.11) \
--platform manylinux_2_17_aarch64-cp-3.12.9-cp312 \
numpy -o numpy-pex
# ...
# pex: Resolving for:
# cp311-cp311-macosx_15_0_arm64 interpreter at /opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/bin/python3.11
# abbreviated platform cp312-cp312-manylinux_2_17_aarch64
# complete platform cp310-cp310-manylinux_2_31_x86_64: 1153.3ms
# ...
ls numpy-pex/.deps
# numpy-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
# numpy-2.2.2-cp311-cp311-macosx_14_0_arm64.whl
# numpy-2.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl By not providing any of these options, one can also let PEX do an search on the current platform for an appropriate interpreter, which seems to be guided by (among a few other options):
For instance, I happen to have a few PBS interpreters on my system: pex \
-v \
--layout=packed \
--python-path=$HOME/.cache/pants/named_caches/python_build_standalone/3.12.6/bin:$HOME/.cache/pants/named_caches/python_build_standalone/3.10.15/bin \
--interpreter-constraint '==3.10.*' \
numpy -o numpy-force310
# ...
# pex: Resolving for:
# cp310-cp310-macosx_15_0_arm64 interpreter at /Users/huon/.cache/pants/named_caches/python_build_standalone/3.10.15/bin/python3.10: 1322.9ms
# ...
ls numpy-force310/.deps
# numpy-2.2.2-cp310-cp310-macosx_14_0_arm64.whl Specifying pex \
-v \
--layout=packed \
--python-path=$HOME/.cache/pants/named_caches/python_build_standalone/3.12.6/bin:$HOME/.cache/pants/named_caches/python_build_standalone/3.10.15/bin \
--complete-platform linux_cp310_x86_64.json \
numpy -o numpy-path-and-platforms
# ...
# pex: Resolving for:
# complete platform cp310-cp310-manylinux_2_31_x86_64: 1167.8ms
# ...
ls numpy-path-and-platforms/.deps
# numpy-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl So, I think unconditionally specifying The investigation above leads me to think of two possible solutions:
What do you think? |
This effectively ensures that when we try to build a pex, it's done using the executable that we're resolving either way. I'm sure this specific implementation is suboptimal, but it resolves the specific issues seens in #21048 and makes my repro pass.
As I noted on the issue, what is currently happening is that if we pick a pyenv interpreter to run the pex, it won't be available in the Pex (i.e., the tool) invocation sandbox. This causes Pex to barf when finding a compatible interpreter for its work.