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:

  1. pre-bump.sh runs uv lock, updating the file but leaving it unstaged
  2. bumpver runs git commit
  3. pre-commit detects unstaged files, stashes them
  4. The uv-lock hook runs and modifies uv.lock again
  5. Stashed changes conflict with hook modifications
  6. 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:

  1. bumpver updates version strings in tracked files
  2. pre-bump.sh runs uv lock and stages it
  3. bumpver commits all staged changes
  4. pre-commit hooks run - uv-lock passes because nothing changed
  5. 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

Further reading Link to heading