Index: setup.py =================================================================== diff -u -r2c3670be196a05ad6c34d798af26bdb798e607d4 -reae2fc37fc7de3d5a2fd977ffbb3792be73553af --- setup.py (.../setup.py) (revision 2c3670be196a05ad6c34d798af26bdb798e607d4) +++ setup.py (.../setup.py) (revision eae2fc37fc7de3d5a2fd977ffbb3792be73553af) @@ -14,33 +14,85 @@ # ############################################################################ import setuptools +import subprocess -setuptools.setup( - name="dialin", - author="Peter Lucia", - author_email="plucia@diality.com", - description="The Diality Dialin API", - packages=setuptools.find_packages(exclude=["test*", "tools", "venv"]), - classifiers=[ # all classifiers: https://pypi.org/classifiers/ - "Programming Language :: Python :: 3.6", - "Operating System :: POSIX :: Linux", - ], - python_requires="~=3.6", - use_scm_version = {"version_scheme" : "no-guess-dev"}, - setup_requires=['setuptools_scm'], - install_requires=[ - "aenum", - "cycler", - "importlib-metadata", - "kiwisolver", - "matplotlib", - "numpy", - "openpyxl", - "pandas", - "pyparsing", - "python-can", - "python-dateutil", - "six", - "wrapt", - ] -) +VERSION = "0.9.0" + + +def get_branch(): + """ + Gets the current branch name in the current git repository + + @return: The current branch name, None if it can't be determined + """ + + 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, None if it can't be determined + """ + try: + return subprocess.check_output("git rev-parse --short=7 HEAD", shell=True).decode("utf-8").strip() + 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 + + +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__': + check_if_git_repo() + setuptools.setup( + name="dialin", + author="Peter Lucia", + author_email="plucia@diality.com", + description="The Diality Dialin API", + packages=setuptools.find_packages(exclude=["test*", "tools", "venv"]), + classifiers=[ # all classifiers: https://pypi.org/classifiers/ + "Programming Language :: Python :: 3.6", + "Operating System :: POSIX :: Linux", + ], + python_requires="~=3.6", + version=DEV_VERSION, + install_requires=[ + "aenum", + "cycler", + "importlib-metadata", + "kiwisolver", + "matplotlib", + "numpy", + "openpyxl", + "pandas", + "pyparsing", + "python-can", + "python-dateutil", + "six", + "wrapt", + ] + ) +