The poetry version
command only updates version in pyproject.toml
file.
This plugin updates version in other files when poetry version <version>
command is executed.
- poetry = ^1.2.0a2
Install the plugin by poetry plugin command.
poetry self add poetry-bumpversion
Say you have __version__
variable set at your_package/__init__.py
file
__version__ = "0.1.0" # It MUST match the version in pyproject.toml file
Add the following to your pyproject.toml
file.
[tool.poetry_bumpversion.file."your_package/__init__.py"]
# Duplicate the line above to add more files
Now run poetry version patch --dry-run
, if your output looks somewhat like below
you are all set (dry-run does not update any file).
Bumping version from 0.5.0 to 0.5.1 poetry-bumpversion: processed file: your_package/__init__.py
If dry-run output looks fine you can run version update command without dry-run flag to
check if version in both pyproject.toml
and your_package/__init__.py
file has been updated.
You can define search and replace terms to be more precise
[tool.poetry_bumpversion.file."your_package/__init__.py"]
search = '__version__ = "{current_version}"'
replace = '__version__ = "{new_version}"'
You can define replacements if you have same search/replace patterns across multiple files.
[[tool.poetry_bumpversion.replacements]]
files = ["your_package/__init__.py", "your_package/version.py"]
search = '__version__ = "{current_version}"'
replace = '__version__ = "{new_version}"'
[[tool.poetry_bumpversion.replacements]]
files = ["README.md"]
search = 'version: {current_version}'
replace = 'version: {new_version}'
This plugin uses itself in it's "Deploy to PyPI" workflow. When a release tag is created on GitHub, the workflow updates package version using the release tag name and deploys it to PyPI. You can copy the deploy workflow code to your repository to set it up.
This project is licensed under MIT License - see the LICENSE file for details.