Skip to content

fix(python-uv): don't reinstall pruned packages - #979

Open
bnusunny wants to merge 2 commits into
aws:developfrom
bnusunny:fix/python-uv-prune-no-deps
Open

bnusunny wants to merge 2 commits into
aws:developfrom
bnusunny:fix/python-uv-prune-no-deps

Conversation

@bnusunny

Copy link
Copy Markdown
Contributor

Issue #, if available: Follow-up to #966

Description of changes

uv_prune (SAM CLI UvPrune) didn't remove a package that another kept package depends on. uv export --prune botocore leaves botocore out of the exported requirements, but the next step, uv pip install -r <export>, resolved dependencies again and installed botocore and its dependencies anyway. On Lambda the bundled copy then shadows the runtime's.

The export is already the full locked set, so the lock path now installs it with --no-deps. install_requirements() gets a no_deps option, and only _build_from_lock_file() sets it, which covers pyproject.toml builds with or without uv.lock. requirements.txt builds still resolve dependencies. DESIGN.md is updated.

The existing prune test prunes boto3, a direct dependency that nothing else requires, so it passed before this fix. The new integration test prunes botocore under aws-xray-sdk.

Description of how you validated changes

  • New integration test test_workflow_prunes_transitive_dependency_of_kept_package fails on develop (botocore 1.44.7 installed) and passes with the fix. New unit tests check --no-deps is passed only on the lock path.
  • make lint and make black-check pass. pytest tests/unit passes (1078), and tests/integration/workflows/python_uv passes with uv 0.13.9 (74).
  • Workspace members and path dependencies: the export lists their dependencies, so the installed set is unchanged with --no-deps.
  • End to end with SAM CLI develop and this branch, a python3.13 arm64 function with UvPrune: [botocore] deployed to Lambda now loads botocore from the runtime instead of /var/task, and the build drops from 30 MB to 2.3 MB. requirements.txt, UvCompileBytecode and layer builds produce the same output as before.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The lock build installs the `uv export` output with `uv pip install -r`, which
resolved dependencies again. A package removed with uv_prune came back when a
kept package depends on it (e.g. pruning botocore under aws-xray-sdk), along
with its own dependencies.

The export is already the full locked closure, so install it with --no-deps.
Plain requirements.txt builds still resolve dependencies.
@bnusunny
bnusunny requested a review from a team as a code owner November 20, 2026 16:42
@bnusunny
bnusunny requested review from licjun and vicheey November 20, 2026 16:43
@aws-sam-tooling-bot

aws-sam-tooling-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🧪 Hands-on test: No problems observed in 8 scenarios

Commit 0751f8f · build LambdaToolingHandsOn-NoDocker:d494b751-89f7-4060-84c8-9fbe5874fc5a. The plan's scenarios ran on an isolated build host; a problem is reported only if it reproduced at least twice. Passing scenarios show only that these checks behaved as expected, not that the change is correct.

Scenarios

Scenario Planned check Result Runner's note
S1 Main fix: with an existing uv.lock, uv_prune of botocore (a dependency of the kept aws-xray-sdk) keeps botocore and its… ✅ pass With a uv.lock (aws-xray-sdk==2.14.0) and uv_prune=[botocore], the head build exits 0 and logs uv pip install -r .../lock_requirements.txt --no-deps ... --python-platform x86_64-manylinux_2_17. che…
S2 Without uv_prune, the lock path with --no-deps still installs the full transitive closure (botocore's dependencies come… ✅ pass Without uv_prune, head (--no-deps) installs the full closure: aws_xray_sdk, wrapt, botocore, jmespath, dateutil, six and urllib3 (CHECK OK). Importing botocore.session, dateutil, jmespath, urllib3 an…
S3 pyproject.toml without uv.lock (the build runs uv lock itself) on arm64: the prune also holds on this path, which now a… ✅ pass pyproject.toml without uv.lock, arm64, uv_prune=[botocore]. On head the build exits 0, writes s3/uv.lock, and the install command has --no-deps and --python-platform aarch64-manylinux_2_17. check.py …
S4 Workspace member whose sibling workspace library has its own dependency: with --no-deps that dependency must still come… ✅ pass Workspace testdata copy, lock removed, lib given deps six==1.16.0 and requests==2.32.3, built from the app member. Head exits 0 with --no-deps and writes uv.lock at the workspace root. check.py print…
S5 Non-workspace path dependency with its own dependency, plus uv_extras and uv_groups whose packages have transitive depe… ✅ pass Path dependency (pathdep -> idna==3.10), extra http (requests), group lambda (aws-xray-sdk), unselected group other (pyasn1), uv_prune=[botocore]. Head exits 0 with --no-deps. check.py prints CHECK O…
S6 Platform markers and native wheels with --no-deps: a Windows-only marker dependency (colorama via click) stays out, and… ✅ pass Adapted: with an unpinned click, uv resolved click 8.5.1, which has no colorama dependency (17-s6-project.log). I pinned click==8.1.8, whose lock entry has colorama under marker sys_platform == 'win3…
S7 requirements.txt builds are unchanged: uv still resolves dependencies, and no --no-deps is passed. ✅ pass requirements.txt with requests==2.32.3. On head the build exits 0 and logs uv pip install -r .../s7/requirements.txt --target ... without --no-deps (nodeps_count=0). check.py prints CHECK OK with r…
S8 Repository tests: the python_uv unit tests (including the new --no-deps assertions) and the prune, workspace and build-… ✅ pass Head only. Unit tests in tests/unit/workflows/python_uv: 191 passed, 53 subtests passed. Integration -k 'prune or build_options': 6 passed, including test_workflow_prunes_transitive_dependency_of_kep…
Runner's notes in full
  • S1: With a uv.lock (aws-xray-sdk==2.14.0) and uv_prune=[botocore], the head build exits 0 and logs uv pip install -r .../lock_requirements.txt --no-deps ... --python-platform x86_64-manylinux_2_17. check.py prints CHECK OK: aws_xray_sdk, wrapt and app.py are present; botocore, jmespath, dateutil, six and urllib3 are absent. On base the same build lacks --no-deps, and botocore-1.44.10, jmespath, python_dateutil, six and urllib3 all land in the artifacts (check.py FAIL). That is the bug this PR fixes.
  • S2: Without uv_prune, head (--no-deps) installs the full closure: aws_xray_sdk, wrapt, botocore, jmespath, dateutil, six and urllib3 (CHECK OK). Importing botocore.session, dateutil, jmespath, urllib3 and aws_xray_sdk.core from the artifacts prints IMPORT OK, with botocore loaded from the artifacts dir. The base listing is identical. The only difference is a __pycache__/six.cpython-311.pyc that my own import check wrote into the head output.
  • S3: pyproject.toml without uv.lock, arm64, uv_prune=[botocore]. On head the build exits 0, writes s3/uv.lock, and the install command has --no-deps and --python-platform aarch64-manylinux_2_17. check.py prints CHECK OK with botocore, jmespath, dateutil, six and urllib3 absent. On base the install lacks --no-deps and all five are present (check.py FAIL), as expected.
  • S4: Workspace testdata copy, lock removed, lib given deps six==1.16.0 and requests==2.32.3, built from the app member. Head exits 0 with --no-deps and writes uv.lock at the workspace root. check.py prints CHECK OK: workspace_lib (package and dist-info), six.py, requests, urllib3, idna, certifi and charset_normalizer are present, and there are 0 .pth files. The base top-level listing is identical (diff prints SAME-SET).
  • S5: Path dependency (pathdep -> idna==3.10), extra http (requests), group lambda (aws-xray-sdk), unselected group other (pyasn1), uv_prune=[botocore]. Head exits 0 with --no-deps. check.py prints CHECK OK: pathdep and its dist-info, idna-3.10, requests, urllib3, certifi, charset_normalizer, aws_xray_sdk and wrapt are present. botocore, jmespath, dateutil and pyasn1 are absent, and there is no optsapp dist-info. On base, check.py fails only on botocore, jmespath and dateutil, as the plan predicts.
  • S6: Adapted: with an unpinned click, uv resolved click 8.5.1, which has no colorama dependency (17-s6-project.log). I pinned click==8.1.8, whose lock entry has colorama under marker sys_platform == 'win32'. The arm64 head build exits 0 with --no-deps and --python-platform aarch64-manylinux_2_17. check.py prints CHECK OK: click, pydantic, pydantic_core, annotated_types and typing_extensions are present and colorama is absent. The .so file is _pydantic_core.cpython-311-aarch64-linux-gnu.so. Base gives the same .so and an identical top-level listing (S6-SAME-SET in 21-head-s7-requirements.log).
  • S7: requirements.txt with requests==2.32.3. On head the build exits 0 and logs uv pip install -r .../s7/requirements.txt --target ... without --no-deps (nodeps_count=0). check.py prints CHECK OK with requests, urllib3, idna, certifi and charset_normalizer present. Base runs the same install command and installs the same packages.
  • S8: Head only. Unit tests in tests/unit/workflows/python_uv: 191 passed, 53 subtests passed. Integration -k 'prune or build_options': 6 passed, including test_workflow_prunes_transitive_dependency_of_kept_package for both TestPythonUvWorkflow_0 and TestPythonUvWorkflow_1_experimentalBuildPerformance. Integration -k workspace: 4 passed. I did not copy the new test to base.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-NoDocker:d494b751-89f7-4060-84c8-9fbe5874fc5a · commit 0751f8f

History (2)
Commit Result When (UTC) Build
0751f8f No problems observed 2026-11-23 22:40 LambdaToolingHandsOn-NoDocker:d494b751-89f7-4060-84c8-9fbe5874fc5a
7de59e1 No problems observed 2026-11-20 16:49 LambdaToolingHandsOn-NoDocker:c2ebc84d-05d2-4127-97bd-9693808fd63b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant