pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
5.95k stars 301 forks source link

Feature request: ability to update the version string in multiple files #684

Open jimustafa opened 1 year ago

jimustafa commented 1 year ago

In some cases, the version string can be present in multiple files, such as in __about__.py, the README, or referenced in the documentation. There exists some tools to match and update the version string across multiple files, such as tbump and bump2version, among others. It could be useful to incorporate similar functionality into hatch: a scheme that allows the specification of multiple files and their associated patterns for matching and updating the version string.

Another option could be a post-version-update hook that runs tbump or bumpversion to update a collection of files, and maybe even run git to create a "bump version" commit. Below is an example of trying to do this with a script using tbump that is called manually with hatch run tbump-sync after updating the version with hatch version:

[tool.hatch]
build.only-packages = true
version.path = "src/package/__about__.py"

[tool.hatch.envs.default]
dependencies = [
  "pre-commit",
  "tbump",
]

[tool.hatch.envs.default.scripts]
tbump-sync = "tbump $(hatch version) --only-patch"

[tool.tbump]
version.current = "0.1.0b1"
version.regex = '''
  (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
  (?P<pre_release>(a|b|rc)\d+)?
  '''
git.message_template = "Bump to {new_version}"
git.tag_template = "v{new_version}"

[[tool.tbump.file]]
src = "README.md"
search = "rev: v{current_version}"
FeryET commented 1 year ago

Maybe a bump-my-version integration would be a good step?

https://github.com/callowayproject/bump-my-version

I would like to write an integration for that tool, but I'm not familiar with developing plugins for hatch.