Skip to content

fix(python-uv): keep lock hashes so require-hashes projects build - #959

Merged
bnusunny merged 5 commits into
aws:developfrom
bnusunny:fix/uv-export-hashes
Nov 13, 2026
Merged

bnusunny merged 5 commits into
aws:developfrom
bnusunny:fix/uv-export-hashes

Conversation

@bnusunny

Copy link
Copy Markdown
Contributor

Issue #, if available: Part of #839 (item 3, require-hashes)

Description of changes

A uv project that sets require-hashes = true under [tool.uv.pip] can't be built from its uv.lock:

error: In `--require-hashes` mode, all requirements must have a hash, but none were provided for: six==1.16.0

uv pip install runs in the project directory, so it reads that setting. But the lock was exported with --no-hashes, which left it nothing to check. This PR drops --no-hashes, so the exported requirements carry the hashes from the lock.

Projects that don't set require-hashes are unaffected: uv checks hashes where they're present and still installs path dependencies, which have none. A path dependency combined with require-hashes = true still fails, because uv can't hash a local directory. That conflict is in the project's own config.

Description of how you validated changes

  • New integration test test_workflow_uses_lock_file_with_require_hashes. With the fix reverted it fails with the error above.
  • tests/unit, tests/functional and tests/integration for python_uv all pass with uv 0.13.7: 103 passed.
  • Built four projects by hand with the fix: plain, require-hashes, a local path dependency, and a path dependency with require-hashes. The first three build. The fourth fails as described above.

Checklist

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

uv pip install runs in the project directory, so it reads [tool.uv.pip]
require-hashes from pyproject.toml. Exporting the lock with --no-hashes
then left it nothing to verify and the build failed.
@bnusunny
bnusunny requested a review from a team as a code owner November 10, 2026 19:34
@aws-sam-tooling-bot

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

Copy link
Copy Markdown

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

Commit b76ae16 · build LambdaToolingHandsOn-NoDocker:2c52fcd5-e61b-4b3c-8c58-14fe5a089a09. 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: a project with [tool.uv.pip] require-hashes = true and a uv.lock builds, and the exported requirements carry … ✅ pass Head: fixture uv.lock + pyproject with [tool.uv.pip] require-hashes = true builds (BUILD OK, exit 0). Exported lock_requirements.txt has six==1.16.0 with --hash=sha256:1e61c374... and --hash=sha256:8…
S2 Regression check: the unchanged fixture project (no require-hashes) with uv.lock still builds, and its export now inclu… ✅ pass Head and base both build the unchanged fixture for x86_64 and arm64 (BUILD OK, exit 0, six.py and six-1.16.0.dist-info present). Head export has two --hash=sha256 lines for six; base export has none.
S3 A workspace where the app depends on a registry package (hashed) and a workspace path member (no hash). Hashed and unha… ✅ pass Workspace app depending on six==1.16.0 and workspace member workspace-lib. Head: BUILD OK; export contains an unhashed './lib' line and a hashed six line, and they install together with no require-ha…
S4 A wrong wheel hash in uv.lock now fails the build. The base passed --no-hashes, so it didn't check hashes. ✅ pass uv.lock with both six hashes replaced by 000.../111.... Head: BUILD FAILED with uv 'Hash mismatch for six==1.16.0', expected 000.../111..., computed 8abb2f1d...; no six.py in artifacts. Reproduced …
S5 Pyproject build without a lock (the workflow runs uv lock, then export) for arm64 python3.12 with require-hashes, using… ✅ pass pyproject-numpy.toml without a lock, require-hashes = true, python3.12 arm64. Head: BUILD OK; artifacts include numpy, numpy-2.1.2.dist-info, numpy.libs; numpy/_core/_multiarray_umath.cpython-312-aar…
S6 Known limitation stated by the author: a path dependency combined with require-hashes = true fails. Check that the fail… ✅ pass App with path dep ../locallib and six. Without require-hashes: BUILD OK, artifacts include locallib, locallib-0.1.0.dist-info, six.py. With require-hashes = true: BUILD FAILED, exit 1, no traceback. …
S7 The repo's own python_uv tests, including the new test_workflow_uses_lock_file_with_require_hashes, pass on the PR. ✅ pass Head: unit+functional python_uv: 98 passed, 53 subtests passed. Integration python_uv: 38 passed. -k require_hashes: 2 passed (TestPythonUvWorkflow_0 and _1_experimentalBuildPerformance), none skippe…
Runner's notes in full
  • S1: Head: fixture uv.lock + pyproject with [tool.uv.pip] require-hashes = true builds (BUILD OK, exit 0). Exported lock_requirements.txt has six==1.16.0 with --hash=sha256:1e61c374... and --hash=sha256:8abb2f1d...; artifacts include six.py, six-1.16.0.dist-info, main.py. Base: BUILD FAILED (exit 1), 'In --require-hashes mode, all requirements must have a hash, but none were provided for: six==1.16.0'.
  • S3: Workspace app depending on six==1.16.0 and workspace member workspace-lib. Head: BUILD OK; export contains an unhashed './lib' line and a hashed six line, and they install together with no require-hashes error. Artifacts include six.py and a real workspace_lib package dir (__init__.py, py.typed) plus dist-info. Base: same artifacts, export without hashes.
  • S4: uv.lock with both six hashes replaced by 000.../111.... Head: BUILD FAILED with uv 'Hash mismatch for six==1.16.0', expected 000.../111..., computed 8abb2f1d...; no six.py in artifacts. Reproduced with a fresh UV_CACHE_DIR and with the warm default cache. Base: BUILD OK and six installed despite the wrong hashes. The lock-file path wraps the error as WorkflowUnknownError; base does the same for its lock-file errors (S1), so this is not new.
  • S5: pyproject-numpy.toml without a lock, require-hashes = true, python3.12 arm64. Head: BUILD OK; artifacts include numpy, numpy-2.1.2.dist-info, numpy.libs; numpy/_core/_multiarray_umath.cpython-312-aarch64-linux-gnu.so present; export has 96 --hash lines. Base: BUILD FAILED (WorkflowFailedError) 'all requirements must have a hash, but none were provided for: numpy==2.1.2 ...'.
  • S6: App with path dep ../locallib and six. Without require-hashes: BUILD OK, artifacts include locallib, locallib-0.1.0.dist-info, six.py. With require-hashes = true: BUILD FAILED, exit 1, no traceback. uv's message reads 'all requirements must have a hash, but none were provided for: file:///.../s6/locallib'. The exception type is WorkflowUnknownError wrapping 'Lock file operation failed', not WorkflowFailedError. The first build's uv lock had written uv.lock into the app dir, so the second build took the lock-file path. Lock-file errors on base use the same wrapping (S1).
  • S7: Head: unit+functional python_uv: 98 passed, 53 subtests passed. Integration python_uv: 38 passed. -k require_hashes: 2 passed (TestPythonUvWorkflow_0 and _1_experimentalBuildPerformance), none skipped.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-NoDocker:2c52fcd5-e61b-4b3c-8c58-14fe5a089a09 · commit b76ae16

History (5)
Commit Result When (UTC) Build
b76ae16 No problems observed 2026-11-13 18:57 LambdaToolingHandsOn-NoDocker:2c52fcd5-e61b-4b3c-8c58-14fe5a089a09
217e0eb No problems observed 2026-11-13 18:20 LambdaToolingHandsOn-NoDocker:7b9fb10c-f7fa-4b2b-86e9-788f51d6ead4
4104e9e No problems observed 2026-11-12 21:30 LambdaToolingHandsOn-NoDocker:4c00a1ff-956a-4013-a2fb-d70787b6805c
52d508c No problems observed 2026-11-10 21:52 LambdaToolingHandsOn-NoDocker:3092950a-4700-41f9-a661-e28856f041c1
b9a8308 No problems observed 2026-11-10 19:41 LambdaToolingHandsOn-NoDocker:4e0f2381-1163-4b97-998e-bdfbc0477ecf

@vicheey vicheey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, small and correct. Keeping the lock's hashes also gets us integrity checks on lock-based builds for free. LGTM.

@bnusunny
bnusunny enabled auto-merge (squash) November 13, 2026 18:50
@bnusunny
bnusunny merged commit 72cac2c into aws:develop Nov 13, 2026
125 checks passed
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.

3 participants