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

Merge bugfix into feature branch #1097

Merged
merged 3 commits into from
Nov 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.2
0.12.0
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)
Loading