I was setting up automated version bumps for a Python project using bumpver and uv. The problem: when bumpver updates the version in pyproject.toml, the uv.lock file also needs updating - and those changes need to be included in the same commit.
The naive approach Link to heading
My first thought was to use bumpver’s pre_commit_hook to run uv lock:
# bumpver.toml
[tool.bumpver]
current_version = "26.01.14"
version_pattern = "0Y.0M.0D[-INC0]"
commit = true
tag = true
push = true
pre_commit_hook = "uv lock"
This fails immediately - bumpver expects a path to a script, not a command:
WARNING - Couldn't parse bumpver.toml: Invalid value for pre_commit_hook: Path 'uv lock' does not exist
The script approach Link to heading
So I created a script:
# scripts/pre-bump.sh
#!/bin/bash
uv lock
And updated the config:
pre_commit_hook = "scripts/pre-bump.sh"
This runs, but then things get messy. I had uv-lock as a pre-commit hook too (from uv-pre-commit). When bumpver tries to commit:
pre-bump.shrunsuv lock, updating the file but leaving it unstaged- bumpver runs
git commit - pre-commit detects unstaged files, stashes them
- The
uv-lockhook runs and modifiesuv.lockagain - Stashed changes conflict with hook modifications
- Everything rolls back
The fix Link to heading
The pre-bump script needs to stage the lockfile:
# scripts/pre-bump.sh
#!/bin/bash
uv lock
git add uv.lock
Now the flow works:
- bumpver updates version strings in tracked files
pre-bump.shrunsuv lockand stages it- bumpver commits all staged changes
- pre-commit hooks run -
uv-lockpasses because nothing changed - Tag gets created and pushed
Full setup Link to heading
Here’s the complete configuration:
# bumpver.toml
[tool.bumpver]
current_version = "26.01.14"
version_pattern = "0Y.0M.0D[-INC0]"
commit_message = "chore: Bump version {old_version} -> {new_version}"
commit = true
tag = true
push = true
pre_commit_hook = "scripts/pre-bump.sh"
[tool.bumpver.file_patterns]
"pyproject.toml" = ['version = "{version}"']
# scripts/pre-bump.sh
#!/bin/bash
uv lock
git add uv.lock
# .pre-commit-config.yaml (relevant bit)
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.9.7
hooks:
- id: uv-lock
Make the script executable:
chmod +x scripts/pre-bump.sh