fix(python-uv): cached build copies dependencies to the build dir#870
Open
tomaDev wants to merge 1 commit into
Open
fix(python-uv): cached build copies dependencies to the build dir#870tomaDev wants to merge 1 commit into
tomaDev wants to merge 1 commit into
Conversation
`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>
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.
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:
`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]`.
`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
Tests
Verified locally: `sam build --cached --parallel --beta-features` now
succeeds end-to-end on a 9-function python-uv project.