Hi Pants team, I'm running into some difficulties ...
# general
f
Hi Pants team, I'm running into some difficulties with an upgrade to our Python version. I'm trying to create PEX packages for Python 3.12, but it's failing due to our old friend, mysqlclient. I get this error:
Copy code
[ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ProcessExecutionFailure: Process 'Building 1 requirement for pant.pex from the python.lock resolve: mysqlclient<3.0,>=2.2' failed with exit code 1.
stdout:

stderr:
No pre-built wheel was available for mysqlclient 2.2.7.
Successfully built the wheel mysqlclient-2.2.7-cp311-cp311-linux_aarch64.whl from the sdist mysqlclient-2.2.7.tar.gz but it is not compatible with the requested foreign target complete platform cp312-cp312-manylinux_2_39_aarch64.
You'll need to build a wheel from mysqlclient-2.2.7.tar.gz on the foreign target platform and make it available to Pex via a `--find-links` repo or a custom `--index`.
So you can see that Pants is compiling this against Python 3.11 instead of 3.12. This is on Ubuntu 24.04, where the system Python version is 3.12. It seems that Pants itself is running on a 3.11 venv and it is incorrectly using this as the basis for building the mysqlclient wheel instead of the system python. Is there any way to workaround this? Or will we just have to wait until Pants gets a Python upgrade?
h
What are your interpreter constraints? Are you certain there is a 3.12 on the search path?
f
My pants.toml is using
interpreter_constraints = ['>=3.12,<3.13']
which python3
points to
/usr/bin/python3
, and
python3 --version
confirms that this is v3.12.3
I have not set
search_path
so it will be using the default, which according to the docs should be
["python", "python3"]
. There is no
python
bin on my PATH
I've put together a little demo project. It's using a Docker container so there should be no externalities to worry about. Unarchive this and run the test script and you should be able to replicate the problem
I can file this as a bug report, assuming it is a bug and I haven't missed something
Also this is happening with py 3.13 as well, it's just easier to demo 3.12 since that's the system py version on this image
c
There is some context (that yeah probably needs to be folded into the docs better) at https://github.com/jasonwbarnett/repro-pants-debugger-issue/issues/1 Does that make sense?
f
Kind of. How would I set
--resolve-local-platforms
? That's not a CLI option is it?
Or is the takeaway here that we should build the mysqlclient wheel outside of Pants first as a separate process, then copy it in for
pants package
?
c
Or is the takeaway here that we should build the mysqlclient wheel outside of Pants first as a separate process, then copy it in for pants package?
Yeah; as a practical matter if you support multiple os/arch (say you have programmers who use macs and you deploy on linux) it is usually much easier -- admittedly with some annoying startup overhead -- to pre-build the wheels you need than to configure everyone's workstation to be able to cross-compile
f
This isn't multi-arch, we're only targeting one system
Prebuilding the wheels is a bit problematic since we'd need to somehow work out what version of the package the lockfile is pointing to. Or just build every version, but that seems a bit wasteful
I'm going to try the resolve-local-platforms thing
h
@fast-xylophone-56613 Can you put that demo project in a public github repo? that way we can use links, diffs etc in a straightforward way
f
Setting resolve-local-platforms resolved this for me so I think we're good, unless you wanted to investigate more. I just assumed Pants/PEX would use my PATH python by default - maybe the docs could use some expansion on how that all works
h
But FWIW I’m pretty sure this is due to Pex (via Pants) not finding a 3.12 interpreter, and then falling back to “yolo mode”, where it tries to build with the interpreter its running on
We should probably turn that off by default, since it causes more confusion when it fails then it helps when it happens to work
f
I think it should definitely be disabled if the, ehm, yolo builder is outside the interpreter constraints 🙂
That was what perplexed me to start with because I only had 3.12 installed, and yet somehow was getting 3.11 builds. Rather confusing.
h
To clarify, you added
--resolve-local-platforms
to
extra_build_args
on your
pex_binary
target?
f
Yes, it worked after that
h
Great, well then I’ll let that be 🙂