Index: leahi_dialin/version.py =================================================================== diff -u -r2138d06d100fdcf23f2e9069f35ee2fdee62008f -r1c0302ebcb0d4d70249ab0932f43b0143e19a1d9 --- leahi_dialin/version.py (.../version.py) (revision 2138d06d100fdcf23f2e9069f35ee2fdee62008f) +++ leahi_dialin/version.py (.../version.py) (revision 1c0302ebcb0d4d70249ab0932f43b0143e19a1d9) @@ -14,6 +14,7 @@ # ############################################################################ import subprocess +import os.path VERSION = "0.9.0" @@ -26,7 +27,12 @@ """ try: - return subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode("utf-8").strip() + # Change the folder to where this file is for git versioning and then back to the original position + curdir = os.path.abspath(os.curdir) + os.chdir(os.path.dirname(__file__)) + res = subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True).decode("utf-8").strip() + os.chdir(curdir) + return res except subprocess.CalledProcessError: return None @@ -38,19 +44,27 @@ @return: (str) the latest commit in the current git repository, None if it can't be determined """ try: - return subprocess.check_output("git rev-parse --short=7 HEAD", shell=True).decode("utf-8").strip() + # Change the folder to where this file is for git versioning and then back to the original position + curdir = os.path.abspath(os.curdir) + os.chdir(os.path.dirname(__file__)) + res = subprocess.check_output("git rev-parse --short=7 HEAD", shell=True).decode("utf-8").strip() + os.chdir(curdir) + return res 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 @return: True if in a git repo, False otherwise """ - return subprocess.call(["git", "branch"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 + curdir = os.path.abspath(os.curdir) + os.chdir(os.path.dirname(__file__)) + res = subprocess.call(["git", "branch"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 + os.chdir(curdir) + return res branch = None