Add experimental uv resolver for Python lockfiles#22949
Open
Liam-Deacon wants to merge 5 commits intopantsbuild:mainfrom
Open
Add experimental uv resolver for Python lockfiles#22949Liam-Deacon wants to merge 5 commits intopantsbuild:mainfrom
Liam-Deacon wants to merge 5 commits intopantsbuild:mainfrom
Conversation
Fix ruff lint and formatting
Contributor
|
Wow, this is a really creative design 🤩 |
Contributor
|
Thanks for the contribution. We've just branched for 2.31.x, so merging this pull request now will come out in 2.32.x, please move the release notes updates to docs/notes/2.32.x.md if that's appropriate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an experimental
uv-backed resolver option for Python user lockfile generation.Pants still generates and consumes Pex lockfiles, but when opted in it uses
uv pip compileto pre-resolve pins, then usespex lock create --no-transitiveto materialize the Pex lock.pex lock create)[uv].argsMotivation
Issue: #20679 — faster, more ergonomic lockfile generation by leveraging
uv.How it works
Usage
1) Enable resolves and select the uv resolver
2) Pass arbitrary uv flags (passthrough)
Use the standard
argspattern (same as other downloadable tools in Pants):Equivalent CLI:
pants generate-lockfiles --resolve=python-default \ --python-lockfile-resolver=uv \ --uv-args='--index-strategy unsafe-first-match'Current limitations (intentional safeguards)
lock_style = "universal"uv pip compileresolves for a single interpreter environment todaycomplete_platformssources/overrides/excludesnot yet modeled in uv stepBenchmark (real-world example)
Environment:
CPython==3.11.*strictpipvsuv~/repos/python-mono/3rdparty/python/requirements.txt~/repos/python-mono/3rdparty/python/requirements-dev.txtpip.antarcticaam.app/privatereferencesblpapi,StressVaR,module-wrapper,pytest-localstackTiming (
/usr/bin/time -p, Pantsd disabled; repeated to show warm-cache behavior):Method:
/tmp/pants-uv-lockfile-benchmark(isolated), usingpython_requirements(...)pointing at the filteredrequirements.in.PANTS_WORKDIRto avoid Pants's local process cache reusing results.PANTS_GLOBAL_PEX_ROOT=/tmp/pants-uv-lockfile-benchmark/cache/pex_rootPIP_CACHE_DIR=/tmp/pants-uv-lockfile-benchmark/cache/pip_cacheUV_CACHE_DIR=/tmp/pants-uv-lockfile-benchmark/cache/uv_cachepippipuvuvSpeedup (lower is better):
pip/uv = 3.58xpip/uv = 1.16xNotes:
uvpre-solve materially reduces cold-cache solve time in this real-world-ish set.Additional visibility (uv mode only):
uv pip compilepre-solve (previous run-set)In this run-set,
uvreduced end-to-end wall time vspip(especially cold-cache). Warm-cache repeats narrow the gap, which suggests resolver overhead is a larger fraction of first-time generation than subsequent runs.Code changes
src/python/pants/backend/python/subsystems/setup.py[python].lockfile_resolver = {pip,uv}src/python/pants/backend/python/subsystems/uv.pyuvtool +[uv].argspassthroughsrc/python/pants/backend/python/goals/lockfile.pyuv pip compilepre-step (opt-in) thenpex lock create --no-transitivesrc/python/pants/backend/python/goals/lockfile_test.pydocs/docs/python/overview/lockfiles.mdx