From 53906c17e95b3b95e27c0676bccceaaeb12f8859 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Tue, 5 Nov 2024 23:44:13 +0100 Subject: [PATCH 1/2] Add class Version to file versioning.py. --- scons/versioning.py | 77 +++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/scons/versioning.py b/scons/versioning.py index 1fecf51f6e..059f310a0e 100644 --- a/scons/versioning.py +++ b/scons/versioning.py @@ -5,7 +5,8 @@ """ import sys -from typing import Optional, Tuple +from dataclasses import dataclass +from typing import Optional VERSION_FILE = '.version' @@ -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() @@ -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: @@ -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) @@ -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) From 3d5e357f2f994912f8392c506805ab61b1eb74be Mon Sep 17 00:00:00 2001 From: michael-rapp <6638695+michael-rapp@users.noreply.github.com> Date: Tue, 5 Nov 2024 23:02:37 +0000 Subject: [PATCH 2/2] [Bot] Merge bugfix into feature branch. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index a8839f70de..d33c3a2128 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.11.2 \ No newline at end of file +0.12.0 \ No newline at end of file