Skip to content

fix(python-uv): cached build copies dependencies to the build dir#870

Open
tomaDev wants to merge 1 commit into
aws:developfrom
tomaDev:fix/python-uv-cached-copy-dependencies
Open

fix(python-uv): cached build copies dependencies to the build dir#870
tomaDev wants to merge 1 commit into
aws:developfrom
tomaDev:fix/python-uv-cached-copy-dependencies

Conversation

@tomaDev
Copy link
Copy Markdown
Contributor

@tomaDev tomaDev commented May 13, 2026

Issue

Fixes #864.

`sam build --cached --beta-features` against a project using the
python-uv workflow fails with:

```
Build Failed
Error: PythonUvBuilder:CopyDependencies - [Errno 2] No such file or directory: '.aws-sam/build/'
```

The failure is also destructive — it wipes `.aws-sam/build/` for every
function, forcing a full `sam build --beta-features` to recover.

Root cause

`sam build --cached` runs the workflow with a `dependencies_dir` set
(`.aws-sam/deps/`) so deps can be reused across builds. Two bugs
on that path:

  1. `PythonUvWorkflow._setup_build_actions` constructs `CopyDependenciesAction` with the source/destination swapped. Dependencies are installed into `dependencies_dir`, so that is the source of the copy and `artifacts_dir` the destination. As written, the action listed the not-yet-created `artifacts_dir` as source and never populated it — hence the `[Errno 2]`.

  2. `UvRunner.install_requirements` passes `--target` to UV verbatim. UV runs with `cwd` set to the project directory, so a relative `.aws-sam/deps/` target is resolved under the source dir, not the build root. `uv pip install` succeeds but writes to the wrong place — the cached path then can't find the deps.

Fix

  • Swap the `CopyDependenciesAction` arguments in `workflow.py` so it copies from `dependencies_dir` → `artifacts_dir`.
  • Resolve `--target` to an absolute path before invoking UV in `packager.py`.

Tests

  • Unit test in `test_workflow.py` asserts `CopyDependenciesAction` is constructed with the correct source/artifact/destination wiring.
  • Unit test in `test_packager.py` asserts a relative `--target` is made absolute.
  • Existing `dependencies_dir` integration test now asserts deps end up in `artifacts_dir` (previously only checked that the build didn't crash).

Verified locally: `sam build --cached --parallel --beta-features` now
succeeds end-to-end on a 9-function python-uv project.

`sam build --cached` (incremental build) invokes the python-uv workflow
with a `dependencies_dir` set. Two bugs made that path fail with
`CopyDependencies - [Errno 2] No such file or directory`:

1. `PythonUvWorkflow._setup_build_actions` constructed `CopyDependenciesAction`
   with `artifact_dir` and `destination_dir` swapped. Dependencies are
   installed into `dependencies_dir`, so that is the source of the copy and
   `artifacts_dir` the destination; as written the action listed the
   not-yet-created artifacts directory and never populated it.

2. `UvRunner.install_requirements` passed `--target` through verbatim. UV runs
   with `cwd` set to the project directory, so the relative
   `.aws-sam/deps/<uuid>` dependencies dir was created under the source
   directory instead of the build root. Resolve `--target` to an absolute
   path before invoking UV.

Adds regression coverage: workflow unit test asserts the
`CopyDependenciesAction` source/artifact/dest dirs; packager unit test
asserts a relative `--target` is made absolute; the `dependencies_dir`
integration test now asserts dependencies are present in the artifacts dir.

Fixes aws#864

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tomaDev tomaDev requested a review from a team as a code owner May 13, 2026 13:22
@github-actions github-actions Bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 13, 2026
github-actions Bot pushed a commit to tomaDev/aws-lambda-builders that referenced this pull request Jun 1, 2026
Carries our two open upstream PRs (aws#869, aws#870) on patched-stack. Workflow
rebases onto upstream develop, runs python_uv unit + integration tests,
force-pushes the rebased stack on success, opens an issue on failure
(de-duped by patch-validation label).

Drop a commit from patched-stack once its upstream PR merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: PythonUvBuilder:CopyDependencies fails when sam build --cached deletes .aws-sam/build/<FunctionName>

1 participant