Skip to content
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 subcommand for reading/bumping the version in pyproject.toml #6298

Open
cauebs opened this issue Aug 21, 2024 · 21 comments · May be fixed by #7248
Open

Add a subcommand for reading/bumping the version in pyproject.toml #6298

cauebs opened this issue Aug 21, 2024 · 21 comments · May be fixed by #7248
Labels
enhancement New feature or request projects Related to project management capabilities

Comments

@cauebs
Copy link

cauebs commented Aug 21, 2024

✅ Both Rye and Poetry have this, and it's quite useful both...

  • to avoid manually incrementing the version number (and potentially making a mistake there with the digits),
  • and to have this field on the pyproject.toml file serve as the single source of truth for a project's version, easily accessible (via uv) 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, since uv'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.

@zanieb zanieb added enhancement New feature or request projects Related to project management capabilities labels Aug 21, 2024
@JonZeolla
Copy link

JonZeolla commented Aug 22, 2024

Would maintaining version identifiers outside of pyproject.toml be considered out of scope for uv? For instance, updating something like a __version__ in a src/package/__init__.py?

Or, even better, support a dynamic version like hatch does with a

[project]
dynamic = ["version"]

[tool.hatch.version]
path = "src/package/__init__.py"

@DeadNews
Copy link

It's most convenient to me to have git tag based versioning:

https://github.com/mtkennerly/poetry-dynamic-versioning

I would love to have this functionality.

@raayu83
Copy link

raayu83 commented Aug 29, 2024

Would also love to see this... I'm currently using poetry-version-plugin in versioned projects and want to switch them to uv

@menzenski
Copy link

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.

Would maintaining version identifiers outside of pyproject.toml be considered out of scope for uv? For instance, updating something like a version in a src/package/init.py?

@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 importlib.metadata.version:

[tool.poetry]
name = "my-package"
version = "1,2,3"
# my_package/__init__.py

from importlib.metadata import version

__version__ = version("my_package")

@raayu83
Copy link

raayu83 commented Sep 5, 2024

Personally I also like the idea of basing the version on the current git tag when using together with CI/CD.
In that case it would be great if there was a command to set the version in pyproject.toml to the value of the git tag.

@HenriBlacksmith
Copy link

Personally I also like the idea of basing the version on the current git tag when using together with CI/CD.

In that case it would be great if there was a command to set the version in pyproject.toml to the value of the git tag.

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
script to bump the CHANGELOGs like a hook to a python script.

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?

@phi-friday
Copy link

phi-friday commented Sep 7, 2024

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

@nrbnlulu nrbnlulu linked a pull request Sep 10, 2024 that will close this issue
@daviewales
Copy link

Consider how poetry does it: https://python-poetry.org/docs/cli#version

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:

The new version should be a valid PEP 440 string or a valid bump rule: patch, minor, major, prepatch, preminor, premajor, prerelease

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.

@pkucmus
Copy link

pkucmus commented Sep 12, 2024

With hatch even when you have the version set as dynamic and red from an example __about__.py module and you bump hatch version $(git describe --broken --tags --always --dirty) (that what I do on build in CI/CD) it will actually change the python module. Which is kinda nice.

@phi-friday
Copy link

With hatch even when you have the version set as dynamic and red from an example __about__.py module and you bump hatch version $(git describe --broken --tags --always --dirty) (that what I do on build in CI/CD) it will actually change the python module. Which is kinda nice.

Using uvx hatch version ... is mostly fine, but I can't use it when it's a stub only package because there is no *.py.

@david-waterworth
Copy link

I'd love to see something like this as well - I currently use python-semantic-version but that uses SemVer rather than PEP440 - which causes a few minor issues such as not being able to parse tags that are valid PEP440 but not SemVer git tags (i.e. tags we added before migrating to PSV). It also has a nice CHANGELOG generation module, and the ability to generate release or dev version based on branch name (main vs feature). Version bumping rules are based on commit message parsing (i.e. if message starts with feat: bump minor version, if fix: bump patch etc.). As part of the PSV build process, all files that are modified (i.e. pyproject.toml, version.py) are staged, committed and pushed. The commit is also tagged with the version. You can then filter by the commit message in your CI pipeline to prevent infinite recursion.

@zanieb
Copy link
Member

zanieb commented Oct 14, 2024

As a workaround, I use this in my project:

sed -i -e "s/0.0.0/${GITHUB_REF#refs/*/}/" pyproject.toml

https://github.com/astral-sh/packse/blob/70abfe8f64a9746452c02cb514942f879c7eaccc/.github/workflows/release.yaml#L34-L36

@struckchure
Copy link

As a workaround, I use this in my project:

sed -i -e "s/0.0.0/${GITHUB_REF#refs/*/}/" pyproject.toml

https://github.com/astral-sh/packse/blob/70abfe8f64a9746452c02cb514942f879c7eaccc/.github/workflows/release.yaml#L34-L36

Exactly what I did, I just wasn't comfortable w/ it

@struckchure
Copy link

Is there a reason why this won't/can't be implemented?

@zanieb
Copy link
Member

zanieb commented Oct 14, 2024

The uv version command already exists, so I need to come up with a design to either phase that out in favor this functionality or choose a new command name.

Basically, that part isn't trivial and we're doing a lot of other things.

@sam57719
Copy link

@zanieb according to the docs there are already other ways to get the uv version.

E.g.

uv --version      # Same output as `uv version`
uv -V             # Will not include the build commit and date
uv pip --version  # Can be used with a subcommand

@zanieb
Copy link
Member

zanieb commented Oct 14, 2024

@sam57719 that doesn't mean it's not a breaking change to switch the functionality. There is downstream code that will break if we change it.

@struckchure
Copy link

The uv version command already exists, so I need to come up with a design to either phase that out in favor this functionality or choose a new command name.

Basically, that part isn't trivial and we're doing a lot of other things.

Maybe we could just have a way to bump by updating the .toml file?
something like ...

uv build --override-config "project.version=x.x.x"

Maybe someone already thought of that, I'm new to uv 🤷‍♂️

@chrisrodrigue
Copy link

Related: #6440

@OverkillGuy
Copy link

OverkillGuy commented Oct 20, 2024

Here's a workaround that may help wait for the feature: uv tree --depth 0 shows the tree of version dependencies of ... just our package:

$ uv tree --depth 0
Resolved 66 packages in 1ms
mass-driver v0.18.0a1

Noting the "Resolved 66 packages in 1ms" is coming on stderr (debug message), so with a bit of fanciful shell:

$ uv tree --depth=0  2> /dev/null | awk '{print $2}'
v0.18.0a1

Not perfect, but it's a start!

PS: Still would love the feature, and personally believe the breakage/change of semantics of uv version is worth it (given uv -V and uv self both exist), but I understand this requires careful thought.

@bluss
Copy link
Contributor

bluss commented Oct 20, 2024

That uv tree -q removes the actual tree output itself is probably a bug and now reported #8379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request projects Related to project management capabilities
Projects
None yet
Development

Successfully merging a pull request may close this issue.