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

add 'bump_complete_version' which allows bumping revisions as well #38

Merged
merged 1 commit into from
Feb 17, 2022
Merged
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
31 changes: 31 additions & 0 deletions dunamai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = [
"bump_version",
"bump_complete_version",
"check_version",
"get_version",
"serialize_pep440",
Expand All @@ -10,6 +11,7 @@
"Version",
]

import copy
import datetime as dt
import re
import shlex
Expand Down Expand Up @@ -1143,6 +1145,35 @@ def bump_version(base: str, index: int = -1) -> str:
return ".".join(str(x) for x in bases)


def bump_complete_version(version: Version, index: int = -1) -> Version:
"""
Increment a version.
If there is no pre-release the core version is bumped. Otherwise, the revision number.
The index parameter is only used when the base version is bumped.

:param version: Version, such as 0.1.0a8+linux.
:param index: Numerical position to increment. Default: -1.
This follows Python indexing rules, so positive numbers start from
the left side and count up from 0, while negative numbers start from
the right side and count down from -1.
Only has an effect when the core version (e.g. 0.1.0) is bumped.
:return: Bumped version.
"""
base = version.base
revision = version.revision
if version.stage is None:
base = bump_version(version.base, index)
else:
if version.revision is None:
revision = 2
else:
revision = version.revision + 1
new_version = copy.copy(version)
new_version.base = base
new_version.revision = revision
return new_version


def _parse_git_timestamp_iso_strict(raw: str) -> dt.datetime:
# Remove colon from timezone offset for pre-3.7 Python:
compat = re.sub(r"(.*T.*[-+]\d+):(\d+)", r"\1\2", raw)
Expand Down