Repository navigation
fix(build): hash the uv manifest and lock for cached builds, and build python-uv layers and container builds - #9419
Conversation
The dependency hash looked up the pip manifest (requirements.txt) for python-uv functions, so a uv project without one never got a hash and reinstalled dependencies on every --cached build. A python-uv layer raised UnsupportedRuntimeException instead. Hash the manifest Lambda Builders detects (detect_uv_manifest) and, for pyproject.toml, the nearest uv.lock and the pyproject.toml beside it.
A python-uv layer failed with "'python-uv' runtime is not supported for layers": the layer subfolder map had no python-uv entry, and the build method was passed to Lambda Builders as the runtime, so uv got --python -uv. Map python-uv to python/ and build with the layer's first CompatibleRuntimes entry, which a python-uv layer now requires.
🧪 Hands-on test: No problems observed in 7 scenariosCommit Scenarios
Runner's notes in full
🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build History (5)
|
There was a problem hiding this comment.
🧪 Hands-on test reproduced 2 new problems on commit 08da2a4. Commands and evidence are in the hands-on comment.
- [BUG] python-uv function with pyproject.toml but no uv.lock reinstalls dependencies on the second unchanged
sam build --cached· low · samcli/lib/build/dependency_hash_generator.py:96 - [BUG] python-uv hash includes an unrelated uv.lock from any parent directory, which Lambda Builders never uses · low · samcli/lib/build/dependency_hash_generator.py:96
🤖 Automated hands-on test — not a review approval
python-uv has no fixed manifest name, so --use-container passed None and failed before uv ran, for functions and layers alike. Use the manifest Lambda Builders detects, as the --cached hash already does.
|
Credit where it's due: @tomaDev's #9113 found and fixed the same layer problems first: the missing |
There was a problem hiding this comment.
🧪 Hands-on test reproduced 2 new problems on commit bb675e3. Commands and evidence are in the hands-on comment.
- [BUG] python-uv dependency hash includes an unrelated uv.lock from any ancestor directory outside the SAM project · low · samcli/lib/build/dependency_hash_generator.py:96
- [BUG] uv project without uv.lock reinstalls dependencies on the second unchanged --cached build because the build creates fn/uv.lock after the hash was taken · low · samcli/lib/build/dependency_hash_generator.py:87
🤖 Automated hands-on test — not a review approval
…dency-hash-review
…t-build uv hash uv only reads the project's own uv.lock or the one at its workspace root, so an unrelated uv.lock in a parent directory no longer changes the hash. When a project has no uv.lock, uv creates one during the build; the hash is now taken again after the build so the next unchanged --cached build reuses dependencies.
…hash-merge # Conflicts: # samcli/lib/build/workflow_config.py
Which issue(s) does this change fix?
Related to aws/aws-lambda-builders#839 (uv support).
Why is this change necessary?
--cachedbuilds decide whether to reinstall dependencies from a hash of the manifest. ForBuildMethod: python-uvthat hash looked up the pip manifest,requirements.txt:pyproject.tomlanduv.lockgot no hash, so its dependencies were reinstalled on every cached build.requirements.txt, even when uv builds from the lock.A
python-uvlayer couldn't be built at all, cached or not:--cachedit failed in the hash with'python-uv' runtime is not supported, because a layer's build method is passed in as the runtime.--cached, or past the hash, it failed with'python-uv' runtime is not supported for layers. Builders also gotpython-uvas the runtime and ranuv export --python -uv.--use-containerfailed for everypython-uvbuild, functions included, withargument should be a str or an os.PathLike object ... not 'NoneType'.python-uvhas no fixed manifest name, so SAM passedNoneas the manifest to mount.How does it address the issue?
For
python-uv, the hash now covers the files uv actually reads:detect_uv_manifest, available since 1.62; SAM pins 1.68), so SAM and the build always agree on it;pyproject.toml, the nearestuv.lock(for a workspace member that's the one at the workspace root) and thepyproject.tomlbeside that lock.Paths in the hash are relative to the code directory, so moving the project doesn't force a reinstall.
--manifeststill takes precedence, and other build methods are unchanged.python-uvlayers now go underpython/and build with the layer's firstCompatibleRuntimesentry, the same way container builds pick the runtime formakefilelayers.Container builds now get the same detected manifest. Builds without
--use-containerare unchanged, because Lambda Builders still detects the manifest itself.Checked with
sam build --cached --beta-featureson a uv-only function plus apython-uvlayer. Editing only the function code reuses both dependency sets. Adding a dependency and re-locking reinstalls only the function's. The layer artifact haspython/six.py.Also checked with
sam build --use-container --beta-featureson the same project, then--cachedtwice. All builds pass, the layer builds with--python 3.12inbuild-python3.12, and the third build comes from the cache.Not fixed here: with
--mount-with WRITEthe build runs as the host uid, which has no home in the image, so uv fails withfailed to create directory /.cache/uv.--container-env-var UV_CACHE_DIR=/tmp/uv-cacheworks around it.What side effects does this change have?
python-uvfunction after upgrading reinstalls its dependencies once, because the stored hash changes.python-uvlayer now requiresCompatibleRuntimes, and fails with a clear error without it. These layers could not be built before, so no working template breaks.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.