Skip to content

feat: support uv.lock files in the Python strategy#2693

Open
jlopez wants to merge 4 commits intogoogleapis:mainfrom
jlopez:feat/uv-lock-support
Open

feat: support uv.lock files in the Python strategy#2693
jlopez wants to merge 4 commits intogoogleapis:mainfrom
jlopez:feat/uv-lock-support

Conversation

@jlopez
Copy link

@jlopez jlopez commented Mar 2, 2026

Summary

Closes #2561

The Python strategy now automatically updates the project's entry in uv.lock when cutting a release, without requiring any extra-files configuration.

What changed

  • New UvLock updater (src/updaters/python/uv-lock.ts) — mirrors the existing CargoLock pattern: parses the lockfile, finds the matching [[package]] entry by name, and uses replaceTomlValue() to update the version while preserving all formatting and comments.
  • Python strategy (src/strategies/python.ts) — adds uv.lock to buildUpdates() alongside the other Python files. Gated on projectName being known (same condition as __init__.py updates). createIfMissing: false makes it a safe no-op for projects that don't use uv.
  • Package name matching applies PEP 503 normalization (My_Packagemy-package) so names are compared case-insensitively with -, _, and . treated as equivalent.
  • Virtual workspace members (entries without a version field) are skipped with a specific warning distinguishing them from packages that are genuinely absent from the lockfile.

Test plan

  • test/updaters/uv-lock.ts — unit tests covering: version update with formatting preserved (snapshot), PEP 503 name normalization (case, underscores, dots), virtual package warning, not touching unrelated dependencies, empty lockfile, missing package
  • test/strategies/python.ts — asserts uv.lock appears in the update list for both the common-files and skip-changelog paths, in addition to when pyproject.toml is present
  • npm test — all passing, 0 failing

🤖 Generated with Claude Code

@jlopez jlopez requested review from a team as code owners March 2, 2026 18:06
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 2, 2026
@google-cla
Copy link

google-cla bot commented Mar 2, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

jlopez added 3 commits March 2, 2026 11:03
Automatically update the project's entry in uv.lock when releasing a
Python package, without requiring extra-files configuration.

Closes googleapis#2561
- Warn when target package is not found in uv.lock (silent no-op bug)
- Add comment explaining warn-not-throw vs CargoLock for empty lockfiles
- Add comment explaining double-parse is inherent to replaceTomlValue API
- Add test for uv.lock with no [[package]] entries (100% coverage)
- Add test for target package not found in lockfile
- Add tests for PEP 503 underscore/dot normalization
- Distinguish virtual packages (present but version-less) from absent
  packages: emit a dedicated warning instead of the misleading "not
  found" message (fixes false debugging trail in uv mono-repos)
- Rename test 'silently skips packages without a version field' to
  accurately reflect that a warning is now emitted; add logger spy to
  assert the warning text
- Assert uv.lock is included in updates for 'builds common files' and
  'omits changelog if skipChangelog=true' strategy tests, catching any
  regression that moves the uv.lock push inside the pyproject.toml branch
- Correct PEP 508 → PEP 503 in normalizePackageName docstring (PEP 503
  is the authoritative spec for canonical name normalisation)
- Document that replaceTomlValue may throw on a malformed lockfile
@jlopez jlopez force-pushed the feat/uv-lock-support branch from e3e4f65 to 14e4658 Compare March 2, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support uv.lock files out-of-the-box.

2 participants