Index: leahi_dialin/version.py =================================================================== diff -u -r1c0302ebcb0d4d70249ab0932f43b0143e19a1d9 -r230095218088ec691b15c63393c7bc1d51ed9ab3 --- leahi_dialin/version.py (.../version.py) (revision 1c0302ebcb0d4d70249ab0932f43b0143e19a1d9) +++ leahi_dialin/version.py (.../version.py) (revision 230095218088ec691b15c63393c7bc1d51ed9ab3) @@ -7,17 +7,20 @@ # # @file version.py # -# @author (last) Dara Navaei -# @date (last) 18-Jan-2023 +# @author (last) Zoltan Miskolci +# @date (last) 22-Jun-2026 # @author (original) Peter Lucia -# @date (original) 18-Jun-2020 +# @date (original) 22-Jun-2021 # ############################################################################ + +# Module imports import subprocess import os.path +from typing import Tuple -VERSION = "0.9.0" +VERSION_FILE_LOCATION = f'{os.path.realpath(__file__)}/../../VERSION' def get_branch(): """ @@ -41,7 +44,7 @@ """ Gets the latest commit in the current git repository - @return: (str) the latest commit in the current git repository, None if it can't be determined + @return: (str) The latest commit in the current git repository, None if it can't be determined """ try: # Change the folder to where this file is for git versioning and then back to the original position @@ -53,6 +56,7 @@ except subprocess.CalledProcessError: return None + def check_if_git_repo(): """ Checks if we're in a git repo or not to know if we can get the git branch and commit @@ -62,22 +66,35 @@ curdir = os.path.abspath(os.curdir) os.chdir(os.path.dirname(__file__)) - res = subprocess.call(["git", "branch"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 + res = subprocess.call(["git", "branch"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 os.chdir(curdir) return res -branch = None -commit = None +def read_version_file() -> Tuple[str, str, str, str]: + """ + Loads the information from the VERSION file. -DEV_VERSION = VERSION + @return: Version information + """ + version = None + build_num = None + branch = None + commit = None -if check_if_git_repo(): - branch = get_branch() - commit = get_last_commit() - DEV_VERSION += ".{0}".format(branch) - DEV_VERSION += ".{0}".format(commit) + with open(file = os.path.abspath(VERSION_FILE_LOCATION)) as f: + content = f.read().split('-') + version = content[0] + build_num = content[1] + branch = content[2] + if branch == 'local' and check_if_git_repo(): + branch = get_branch() + commit = get_last_commit() + return f'{version}.{build_num}.{branch}.{commit}' + +DEV_VERSION = read_version_file() + if __name__ == '__main__': - print(VERSION) + print(DEV_VERSION) \ No newline at end of file