I might be late to the party, but this is how I solved it.
pyproject.toml
is using the version as it is defined in the package version file (some_package/version.py
) using poetry-dynamic-versioning which allows "dynamic versioning based on tags in your version control system" but offers also the possibility to utilize Jinja templating to fill in the version.
And that version.py
file again is, in my case, generated by changelog2version which updates the version file based on a markdown changelog file following SemVer.
Ensure to once call poetry self add "poetry-dynamic-versioning[plugin]"
, as documented in poetry-dynamic-versioning.
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
__version_info__ = ("0", "1", "0")
__version__ = ".".join(__version_info__)
[tool.poetry]
name = "my-package-name"
version = "0.0.0+will-be-updated-automatically"
description = "Cool stuff"
authors = ["brainelectronics"]
packages = [
{include = "some_package/**/*.py"}
]
# https://github.com/mtkennerly/poetry-dynamic-versioning/tree/v1.3.0
[tool.poetry-dynamic-versioning]
enable = true
format-jinja-imports = [
{ module = "subprocess", item = "check_output" },
]
format-jinja = """{{ check_output(["python", "-c", "from pathlib import Path; exec(Path('some_package/version.py').read_text()); print(__version__)"]).decode().strip() }}"""
[tool.poetry.dependencies]
python = "^3.10.4"
[tool.poetry.group.dev.dependencies]
poetry-dynamic-versioning = "~1.3.0"
[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"
pyproject.toml
? – Chthonian