Hi everyone! :) I ran into an issue with lockfile ...
# general
g
Hi everyone! :) I ran into an issue with lockfile generation and wanted to check if there are any better ways to handle it. I'd love to hear your thoughts! Case:
requirements_pyarrow.txt
with a single entry
awswrangler==3.12.1
results in the following error when running `pants generate-lockfiles --resolve=python-pyarrow`:
Copy code
pip: ERROR: Cannot install awswrangler==3.12.1 because these package versions have conflicting dependencies.
pip: ERROR: ResolutionImpossible: for help visit <https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts>
pip:  
pip:  The conflict is caused by:
pip:      awswrangler 3.12.1 depends on pyarrow<18.0.0 and >=8.0.0; sys_platform == "darwin" and platform_machine == "x86_64"
pip:      awswrangler 3.12.1 depends on pyarrow<21.0.0 and >=18.0.0; sys_platform != "darwin" or platform_machine != "x86_64"
Solution: create the lockfile manually with something like
Copy code
pex3 lock create \
    --style strict \
    --complete-platform 3rdparty/platforms/manylinux_2_28_aarch64.json \
    --complete-platform 3rdparty/platforms/macosx_26_0_arm64.json \
    -r 3rdparty/python/requirements_pyarrow.txt \
    -o python-pyarrow.lock
Then reuse the lockfile with setting
python-pyarrow = "python-pyarrow.lock"
in
pants.toml
and
resolves_generate_lockfiles = false
. I can then use the resolve as usual. The problem with this approach is that I still need to define the requirements in a BUILD file:
Copy code
python_requirements(
    name="pyarrow",
    source="requirements_pyarrow.txt",
    resolve="python-pyarrow",
)
And then run the pex command manually every time something changes in the requirements.
The biggest downside of this approach is that I now need to refer to the
requirements_pyarrow.txt
twice (in the pex command and in the BUILD file) and can't use the
pants generate-lockfiles
command
@happy-kitchen-89482 maybe you can take a look on this one? Thanks in advance! Adding these arguments (style, complete platform) from the [pex-cli] block of pants.toml will solve this issue, so if it feels like a possible solution I might create a PR
👀 1
b
@great-leather-68110 with https://github.com/pex-tool/pex/pull/2940 you can do:
Copy code
python -mpex.cli lock create \
    --pip-version latest-compatible \
    --style universal \
    --target-system linux \
    --target-system mac \
    --interpreter-constraint "==3.11.*" \
    awswrangler==3.12.1 \
    'pyarrow<18,>=8; sys_platform == "darwin" and platform_machine == "x86_64"' \
    'pyarrow<21,>=18; sys_platform != "darwin" or platform_machine != "x86_64"' \
    --indent 2 -o lock.json \
    --pip-log pip.log \
    --elide-unused-requires-dist
In other words, the universal lock splitting referenced in https://pantsbuild.slack.com/archives/C046T6T9U/p1760360455443789 will also work for any top-level requirements that split the lock (that currently works today except for the
platform_machine
marker needed in your case). Here I elevated the conflict error you received to top-level requirements to let Pex know to split the universal lock resolve. I assume you could do the same in Pants by declaring those two dependencies at top-level with a comment indicating why you're doing this even though you have no direct dependency on pyarrow (presumably). I expect to release Pex with that fix for universal lock splitting by end of week. All that said, Pants supporting non-universal locks would be great. I still think universal locks are generally a bad idea despite the ~wide ecosystem support in poetry, pdm, uv, ... etc.
g
@brief-scientist-13682 Thank you for looking into that! I’d also prefer having the option to directly specify the platforms in Pants. We’ll go with the approach from my first message then, as it’s a more straightforward way to define the expected platforms compared to using
target_system
or, say,
platform_machine
. So your fix isn’t blocking, and kudos for developing Pex! I’ll explore the options for passing platforms during Pants lockfile generation.
b
Sounds good. That said, the Pex support for universal resolve splitting is now available here: https://github.com/pex-tool/pex/releases/tag/v2.62.0
g
Thank you!
I've added the option to pass the platform-related PEX argument to pants: https://github.com/pantsbuild/pants/pull/22910 Maybe @happy-kitchen-89482 can take a look?
👀 1