-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a command to read and update (i.e., bump) the project version, e.g., uv version
#6298
Comments
Would maintaining version identifiers outside of Or, even better, support a dynamic version like hatch does with a [project]
dynamic = ["version"]
[tool.hatch.version]
path = "src/package/__init__.py" |
It's most convenient to me to have https://github.com/mtkennerly/poetry-dynamic-versioning I would love to have this functionality. |
Would also love to see this... I'm currently using poetry-version-plugin in versioned projects and want to switch them to uv |
Also very interested in this feature. This kind of read/update version command seems very common (not only Poetry but npm, etc) and it'd make migration to uv from other tools that much more straightforward.
@JonZeolla I've used PDM's dynamic versioning in the past (which is essentially the same as the Hatch example you provide) but have found it kind of annoying in practice. IMO it's preferable to have the version in pyproject.toml be the source of truth. That version can be exposed in the Python package using [tool.poetry]
name = "my-package"
version = "1,2,3" # my_package/__init__.py
from importlib.metadata import version
__version__ = version("my_package") |
Personally I also like the idea of basing the version on the current git tag when using together with CI/CD. |
Covering what bump-my-version (and previously bumpversion) do would cover that (including customizing the git tag and commit message format) An interesting addition would be to have a way to trigger a custom An even better but probably too opinionated option could be to add a CHANGELOG management system (like changie) but it might be out of scope of uv? |
For others who need this. uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $VERSION I'm using it like this in github action. VERSION=$(uvx dunamai from any --no-metadata --style pep440)
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $VERSION
uv build |
Consider how My workflow looks like this: # Show current version
poetry version
# Bump version
poetry version minor
# Add a git tag with a matching version to what's in pyproject.toml
git tag "v$(poetry version -s)" Poetry tries to be clever to avoid needing an option to specify whether you are auto-bumping or manually setting a version:
This assumes that no-one will ever want to use one of those strings as a version, but that seems like a reasonably safe assumption. |
With hatch even when you have the |
Using |
I'd love to see something like this as well - I currently use |
As a workaround, I use this in my project:
|
Exactly what I did, I just wasn't comfortable w/ it |
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Use the just runner in CI to avoid differing invocations in the project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Use the just runner in CI to avoid differing invocations in the project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Use the just runner in CI to avoid differing invocations in the project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
- Use justfile instead of Makefile, since the release script can be integrated natively: `just release patch`. Might be possible to even include this in pyproject.toml since `uv` will provide a task runner (astral-sh/uv#5903) that might be based on just. - Adjust the linting checks in the CI to run against the whole project. - Use the just runner in CI to avoid differing invocations in the project. - Add commitizen for bumping the release. This was provided by poetry in the past. I make too many mistakes without a tool here. In the future, this will be covered by uv as well: astral-sh/uv#6298 - next… let's try to release a dev release and let's have a look if the pipeline works correctly.
Hello uv team! The "uv version" feature for updating project versions is crucial for projects with frequent alpha/dev releases. Currently, Poetry's simple command Is there a roadmap or timeline for implementing this functionality in uv? Thanks |
The simplest solution I can envision is to run:
|
To update the version, I use the following workaround:
|
One option could be to change
There’s a rule to keep in mind: if you want to create something new, you may need to break something old. |
I completely agree, note that:
|
You can read the pyproject file and print the version with the following: uv run --python 3.12 -- \
python -c '
import tomllib, pathlib
file = pathlib.Path("pyproject.toml")
metadata = tomllib.loads(file.read_text())
print(metadata["project"]["version"])
' Need to use a python version that has tomllib (i.e. 3.11 or greater). |
Expanding on the answer in #6298 (comment), the following bash script can both print and increment versions: #!/usr/bin/env bash
v="$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)"
if [ -z "$1" ]; then
echo "$v"
exit 0
fi
uvx --from bump2version bumpversion --allow-dirty --current-version "$v" "$1" pyproject.toml Further, if you use mise, you may get tab-completion with the following task (run as # .mise.toml
[tasks.bump]
description = "Bump the python package version. Takes one argument: `major`, `minor` or `patch`."
quiet = true
usage = '''
arg "[semver]" help="The SemVer name that should be incremented." {
choices "major" "minor" "patch"
}
'''
run = """
#!/usr/bin/env bash
v="$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)"
if [ -z {{arg(name="semver")}} ]; then
echo "$v"
exit 0
fi
uvx --from bump2version bumpversion --allow-dirty --current-version "$v" {{arg(name="semver")}} pyproject.toml
""" |
Inspired by one of the comments above, here's my GitHub action for getting version which is a workaround for at least one small chunk of the functionality being discussed here: - name: Install uv
uses: astral-sh/setup-uv@v5
- name: Get package version
id: version
run: |
VERSION=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)
echo "package_version=$VERSION" >> $GITHUB_OUTPUT |
@zanieb Any updates on this? Almost everyone who uses UV as a package manager needs this feature 😁. |
We've managed to get (what I think everyone else means by) this behaviour using setuptools_scm with uv: https://pypi.org/project/setuptools-scm/ [project] [tool.setuptools_scm] [build-system] Hopefully this is helpful. Python packaging and distribution seems to be much more complex than I hoped. |
Another alternative, for those who feel this is the last feature missing from uv to move over: replace the package bumping command with `bump-my-version`.Docs: https://callowayproject.github.io/bump-my-version/ Configured for your particular repo via In my case: [tool.bumpversion]
allow_dirty = false
commit = true
message = "Bump to version v{new_version}"
tag = true
tag_message = "Release v{new_version}"
setup_hooks = ["make"] # Run 'make' as validation before starting
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'
[[tool.bumpversion.files]]
filename = "CHANGELOG.md"
search = "## [Unreleased]"
replace = "## [Unreleased]\n\n## v{new_version} - {now:%Y-%m-%d}" Running it via:
This does:
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ The project uses semantic versioning (see [semver](https://semver.org)).
## [Unreleased]
+## v0.1.1 - 2025-02-06
+
### Fixed
- No longer crashing on the bad thing
## v0.1.0 - 2025-01-20
### Added
diff --git a/pyproject.toml b/pyproject.toml
index eec4d73..d64caef 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,7 @@ name = "redis_backend"
description = "A cool project"
authors = ["..."]
readme = "README.md"
-version = "0.1.0"
+version = "0.1.1" So I call # Make a release commit + tag, creating Changelog entry
# Set BUMP variable to any of supported (major, minor, patch)
# See 'bump-my-version show-bump' for options
# Variable BUMP defaults to 'patch' (v1.2.3 -> v1.2.4)
.PHONY: release
BUMP=patch
release:
uvx bump-my-version bump ${BUMP} And to remind ourselves of the patterns, we can print the possible future versions: $ uvx bump-my-version show-bump
0.1.1 ── bump ─┬─ major ─ 1.0.0
├─ minor ─ 0.2.0
╰─ patch ─ 0.1.2 I hope others like me will feel this is good enough to be unblocked, and move their life over to uv, and Be Happy. ... but I'd still love to get this natively in uv if we can ;) |
There are a number of workarounds posted so far, but I'll add one more to the list. Target workflow.
Implementation:
Keeping my fingers crossed that this only needs to be a "temporary" workaround, but I'm not going to let it stop me from migrating some of our legacy build systems over to uv. |
+1 - Would use this all day long in replacement of poetry version. |
✅ Both Rye and Poetry have this, and it's quite useful both...
pyproject.toml
file serve as the single source of truth for a project's version, easily accessible (viauv
) in CI workflows, etc.🛑 The latter is where my personal interests lie: I have a CI workflow that tags and deploys releases when the version is bumped, currently using Poetry for it. I don't really want to pull in an additional tool to parse the project specs, so it's currently keeping me from considering migrating to
uv
.📜 My proposal is replacing the current functionality of the
version
subcommand with this, sinceuv
's version can already be accessed via the-V | --version
option, and other project management currently exist as "root" subcommands.ℹ️ I'm willing to give this one a go myself if maintainers greenlight the proposal.
The text was updated successfully, but these errors were encountered: