Skip to content
Discussion options

You must be logged in to vote

There's no built-in variable for the total commit count, but format-jinja together with format-jinja-imports can shell out to git for exactly the number you want:

[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 v0.1.0 and 3 total commits, and the build produced 0.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: 0 on acti…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RobertoRoos
Comment options

@mtkennerly
Comment options

Answer selected by mtkennerly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants