Bumping pyproject.toml version using Git Tags

#python#git#python packaging#uv

No longer necessary

This is no longer necessary since UV version 0.7.0 added a uv version command that now handles this using uv version $(git describe --tags --abbrev=0), however this post shall remain for posterity.

When automating package releases, I want the version in my pyproject.toml to match the Git tag I’m using for the release to ensures consistency between my Git tags and the actual published package version.

Previously I’ve used Poetry to manage my projects dependencies and build versions, so I’ve been able to use the poetry version command with command substitution: poetry version $(git describe --tags --abbrev=0).

More recently I’ve started to switch to using uv to manage my projects (as well as my venvs and tool installs - replacing pyenv and pipx) but it currently does not have a nice way to bump versions.

However, using the uv tools feature it’s possible to run other CLI tools in a CI environment to directly manipulate the TOML file using toml-cli with the uvx runner:

uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $(git describe --tags --abbrev=0)

Top