Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid non-monotonic versions #1087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/setuptools_scm/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Configuration:
dist_name: str | None = None
version_cls: type[_VersionT] = _Version
search_parent_directories: bool = False
micro_version_factor: int = 1000

parent: _t.PathT | None = None

Expand Down
6 changes: 5 additions & 1 deletion src/setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ def release_branch_semver_version(version: ScmVersion) -> str:
if branch_ver_up_to_minor == tag_ver_up_to_minor:
# We're in a release/maintenance branch, next is a patch/rc/beta bump:
return version.format_next_version(guess_next_version)
# We're in a development branch, next is a minor bump:

# We're in a development branch, next is a minor bump, but take
# the minor into consideration so that e.g. being five commits off
# 1.0.1 is greater than being 10 commits off 1.0.0.
version.distance += version.tag.micro * version.config.micro_version_factor
return version.format_next_version(guess_next_simple_semver, retain=SEMVER_MINOR)


Expand Down
11 changes: 9 additions & 2 deletions testing/test_mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def wd(wd: WorkDir) -> WorkDir:
archival_mapping = {
"1.0": {"tag": "1.0"},
"1.1.0.dev3+h000000000000": {
"latesttag": "1.0",
"latesttag": "1.0.0",
"latesttagdistance": "3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i need some more examples, i cant quite wrap my head around it

this is a orkaround to ease the pain, but its also unable to completely prevent it

"node": "0" * 20,
},
"1.1.0.dev103+h000000000000": {
"latesttag": "1.0.1",
"latesttagdistance": "3",
"node": "0" * 20,
},
Expand All @@ -51,7 +56,9 @@ def wd(wd: WorkDir) -> WorkDir:
@pytest.mark.parametrize(("expected", "data"), sorted(archival_mapping.items()))
def test_archival_to_version(expected: str, data: dict[str, str]) -> None:
config = Configuration(
version_scheme="release-branch-semver", local_scheme="node-and-date"
version_scheme="release-branch-semver",
local_scheme="node-and-date",
micro_version_factor=100,
)
version = archival_to_version(data, config=config)
assert format_version(version) == expected
Expand Down
Loading