Index: version.py =================================================================== diff -u -r900f99812cee2e022fbbd46cd916b08a1397dda7 -r6e62e3052aaf9138174905faa03b32319ec0cc0f --- version.py (.../version.py) (revision 900f99812cee2e022fbbd46cd916b08a1397dda7) +++ version.py (.../version.py) (revision 6e62e3052aaf9138174905faa03b32319ec0cc0f) @@ -8,35 +8,62 @@ # @file version.py # # @author (last) Peter Lucia -# @date (last) 18-Jun-2020 +# @date (last) 02-Nov-2020 # @author (original) Peter Lucia -# @date (original) 16-Jun-2020 +# @date (original) 18-Jun-2020 # ############################################################################ import subprocess +VERSION = "0.8.1" + def get_branch(): """ Gets the current branch name in the current git repository - @return: The current branch name + @return: The current branch name, None if it can't be determined """ - return subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode("utf-8").strip() + try: + return subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode("utf-8").strip() + except subprocess.CalledProcessError: + return None def get_last_commit(): """ Gets the latest commit in the current git repository - @return: (str) 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 subprocess.check_output("git rev-parse --short=7 HEAD", shell=True).decode("utf-8").strip() + try: + return subprocess.check_output("git rev-parse --short=7 HEAD", shell=True).decode("utf-8").strip() + except subprocess.CalledProcessError: + return None -VERSION = "0.5.0-{0}-{1}".format(get_branch(), get_last_commit()) +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 + @return: True if in a git repo, False otherwise + """ + return subprocess.call(["git", "branch"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 + + +branch = None +commit = None + +DEV_VERSION = VERSION + +if check_if_git_repo(): + branch = get_branch() + commit = get_last_commit() + DEV_VERSION += "-{0}".format(branch) + DEV_VERSION += "-{0}".format(commit) + + if __name__ == '__main__': print(VERSION)