Skip to content

Commit

Permalink
Merge pull request #1097 from mrapp-ke/merge-bugfix
Browse files Browse the repository at this point in the history
Merge bugfix into feature branch
  • Loading branch information
issue-api-tokens[bot] authored Nov 5, 2024
2 parents ee1f1be + 3d5e357 commit 0869938
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions scons/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"""
import sys

from typing import Optional, Tuple
from dataclasses import dataclass
from typing import Optional

VERSION_FILE = '.version'

Expand All @@ -14,6 +15,31 @@
VERSION_FILE_ENCODING = 'utf-8'


@dataclass
class Version:
"""
Represents a semantic version.
Attributes:
major: The major version number
minor: The minor version number
patch: The patch version number
dev: The development version number
"""
major: int
minor: int
patch: int
dev: Optional[int] = None

def __str__(self) -> str:
version = str(self.major) + '.' + str(self.minor) + '.' + str(self.patch)

if self.dev:
version += '.dev' + str(self.dev)

return version


def __read_version_file(version_file) -> str:
with open(version_file, mode='r', encoding=VERSION_FILE_ENCODING) as file:
lines = file.readlines()
Expand Down Expand Up @@ -55,7 +81,7 @@ def __update_development_version(dev: int):
__write_version_file(DEV_VERSION_FILE, updated_version)


def __parse_version(version: str) -> Tuple[int, int, int]:
def __parse_version(version: str) -> Version:
parts = version.split('.')

if len(parts) != 3:
Expand All @@ -65,26 +91,17 @@ def __parse_version(version: str) -> Tuple[int, int, int]:
major = __parse_version_number(parts[0])
minor = __parse_version_number(parts[1])
patch = __parse_version_number(parts[2])
return major, minor, patch


def __format_version(major: int, minor: int, patch: int, dev: Optional[int] = None) -> str:
version = str(major) + '.' + str(minor) + '.' + str(patch)
return Version(major=major, minor=minor, patch=patch)

if dev is not None:
version += '.dev' + str(dev)

return version


def __get_current_version() -> Tuple[int, int, int]:
def __get_current_version() -> Version:
current_version = __read_version_file(VERSION_FILE)
print('Current version is "' + current_version + '"')
return __parse_version(current_version)


def __update_version(major: int, minor: int, patch: int, dev: Optional[int] = None):
updated_version = __format_version(major, minor, patch, dev)
def __update_version(version: Version):
updated_version = str(version)
print('Updated version to "' + updated_version + '"')
__write_version_file(VERSION_FILE, updated_version)

Expand All @@ -110,36 +127,36 @@ def apply_development_version(**_):
"""
Appends the development version to the current semantic version.
"""
major, minor, patch = __get_current_version()
dev = __get_current_development_version()
__update_version(major, minor, patch, dev)
version = __get_current_version()
version.dev = __get_current_development_version()
__update_version(version)


def increment_patch_version(**_):
"""
Increments the patch version.
"""
major, minor, patch = __get_current_version()
patch += 1
__update_version(major, minor, patch)
version = __get_current_version()
version.patch += 1
__update_version(version)


def increment_minor_version(**_):
"""
Increments the minor version.
"""
major, minor, patch = __get_current_version()
minor += 1
patch = 0
__update_version(major, minor, patch)
version = __get_current_version()
version.minor += 1
version.patch = 0
__update_version(version)


def increment_major_version(**_):
"""
Increments the major version.
"""
major, minor, patch = __get_current_version()
major += 1
minor = 0
patch = 0
__update_version(major, minor, patch)
version = __get_current_version()
version.major += 1
version.minor = 0
version.patch = 0
__update_version(version)

0 comments on commit 0869938

Please sign in to comment.