Skip to content

feat: Add uv lock --rewrite (#15220)#19217

Open
mud2monarch wants to merge 3 commits intoastral-sh:mainfrom
mud2monarch:force-newest-lock-file
Open

feat: Add uv lock --rewrite (#15220)#19217
mud2monarch wants to merge 3 commits intoastral-sh:mainfrom
mud2monarch:force-newest-lock-file

Conversation

@mud2monarch
Copy link
Copy Markdown

Summary

This PR adds a new CLI flag --rewrite that forces a re-resolution and rewrite of the lockfile even if the dependencies and requirements have not changed.

Changes:

This is most useful for teams who do not enforce a shared uv version and see large lockfile diffs that are not semantically meaningful. Closes #15220.

Test Plan

  • Test lock_rewrite() modeled on lock_refresh()
  • Test lock_rewrite_conflicts_locked_env() to check guarantees that rewrite does not coexist with locked (other guarantees enforced by clap annotations and LockSettings::resolve())

Other Qs/commentary

  • Very open to feedback and requests. This is my first PR.
  • This PR complies with the AI policy
  • Should I add env/config support for --rewrite? As-is, this is only available as a CLI flag. I thought I'd keep things simple for my first PR, but I can also add it.
  • Should --rewrite force a new lockfile write even if the text contents would not change at all? E.g., imagine running uv lock --rewrite twice. I am split on the expected behavior. This PR resolves the original user's issue without this, but there may be other situations where someone really wants to blindly rewrite (e.g., they use their filesystem's timestamp to ensure freshness?), and this would be the intuitive flag to use to force that behavior.

@charliermarsh
Copy link
Copy Markdown
Member

How does this differ from the refresh flag?

@mud2monarch
Copy link
Copy Markdown
Author

mud2monarch commented Apr 29, 2026

Thank you! While very similar, I do think these are distinct flags. --rewrite keeps the entirety of the cache and only looks to resolve the lockfile.

In the scenario presented by the issue, the requester has valid lockfiles and working dependencies across the team, but uv version mismatches cause lockfile diffs during the pre-commit pipeline. It seems quite costly to require that the user clear the entirety of their team's cache every commit (which is quite an expensive operation) in order to achieve the zero-lockfile-diff they're hoping to achieve.

@mud2monarch
Copy link
Copy Markdown
Author

mud2monarch commented Apr 29, 2026

Ah, hmm, based on the docs, I thought that --refresh was equivalent to uv cache clean then uv lock && uv sync but that doesn't appear to be the case. I suppose this is duplicative, unfortunately.

I guess #15220 is a stale issue? Feel free to close if so. I'd love an opportunity to contribute if you can identify a good first issue that is not stale. I use UV and am a big fan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Force newest lock file format (revision = 3, upload-time=...)

2 participants