How to retrieve the absolute revision number? #247
|
For a particular project I want to include the revision number in the version string, e.g. I see two numbers for the formatting field, Is there currently some way to achieve this? EDIT: Basically the output of |
Replies: 1 comment 2 replies
|
There's no built-in variable for the total commit count, but [tool.poetry-dynamic-versioning]
enable = true
format-jinja = "{{ base }}.dev{{ check_output(['git', 'rev-list', '--count', 'HEAD'], text=True) | trim }}"
format-jinja-imports = [
{ module = "subprocess", item = "check_output" },
]Just tested this on a repo with tag Two caveats: this only works where git history is available, so building from an sdist won't have it, and shallow CI clones will undercount. If you build in GitHub Actions, set |
There's no built-in variable for the total commit count, but
format-jinjatogether withformat-jinja-importscan shell out to git for exactly the number you want:Just tested this on a repo with tag
v0.1.0and 3 total commits, and the build produced0.1.0.dev3.Two caveats: this only works where git history is available, so building from an sdist won't have it, and shallow CI clones will undercount. If you build in GitHub Actions, set
fetch-depth: 0onacti…