Conversation
When 'version_file' is set, tags in the repo are ignored. This is a footgun for release flows that push a tag like 'v2.1.0rc1' while the version file still says '2.1.0': the built package silently gets version 2.1.0 (see issue dolfinus#155). Add a 'prefer_tag: bool' option (default False to keep the current behavior). When enabled and the repo has at least one tag, the latest tag is used as the version source instead of the version file content, honoring 'tag_formatter', dev/dirty templates and 'ccount' exactly like the tag-based schema does. When the tag and the version file content differ (ignoring a leading 'v'), a warning is logged either way, so stale version files are easier to notice.
dolfinus
reviewed
Sep 30, 2026
Comment on lines
+9
to
+11
| ignored (see :issue:`155` in the issue tracker of this project for the | ||
| discussion). With this option enabled, the latest Git tag takes precedence | ||
| over the version file content. |
Owner
There was a problem hiding this comment.
Suggested change
| ignored (see :issue:`155` in the issue tracker of this project for the | |
| discussion). With this option enabled, the latest Git tag takes precedence | |
| over the version file content. | |
| ignored (see :issue:`155`). With this option enabled, the latest Git tag takes precedence over the version file content. |
|
|
||
| version_file_path = project_root.joinpath(version_file) | ||
| if not version_file_path.exists(): | ||
| if prefer_tag and tag is not None: |
Owner
There was a problem hiding this comment.
I think this could be simplified instead of copy-pasting the branch
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new boolean option
prefer_tag(defaultFalse) for theversion_fileversioning schema: when enabled and the repo contains at least one tag, the latest Git tag is used as the version source instead of the version file content.When the tag and the version file content differ (a leading
vis ignored in the comparison), a warning is logged either way, so stale version files are easier to notice.Motivation
This follows the direction discussed in #155. The footgun: a release flow pushes a tag
v2.1.0rc1, but theversion_filestill contains2.1.0— the built package silently gets version2.1.0, becauseversion_fileignores tags entirely (documented indocs/schemas/file/version_file.rst).In #155, @dolfinus suggested:
and, instead of a strict tag/file equality check:
This PR implements exactly that.
Behavior
prefer_tagnot set (default): behavior is unchanged — version file wins, tags ignored (no breaking change for existing repos).prefer_tag = true, repo has tags: latest tag (persort_by, honoringtag_filter) is the version source;tag_formatter,dev_template/dirty_templateandccountwork exactly like in the tag-based schema.prefer_tag = true, no tags: version file is used as usual.Testing
tests/test_integration/test_version_file.py(6 test functions, 12 cases): default-off behavior, tagged HEAD with/withoutcount_commits_from_version_file, dev commits after the tag, no-tag fallback, andv-prefixed tag comparison.116 passedon the pre-existing suite plus the new tests; the only failures are the pre-existinggit_missing/git_not_executablecases which are unrelated to this change (they require an environment withoutgitonPATH).