diff --git a/_updateversion.py b/_updateversion.py index d77a0be47..9ae7ad0cc 100644 --- a/_updateversion.py +++ b/_updateversion.py @@ -1,16 +1,15 @@ #!/usr/bin/env/python # coding=utf-8 -import sys import os import subprocess -_HERE = os.path.join(os.path.abspath(os.path.dirname(__file__)),'tofu') +_HERE = os.path.abspath(os.path.dirname(__file__)) def updateversion(path=_HERE): # Fetch version from git tags, and write to version.py # Also, when git is not available (PyPi package), use stored version.py - version_py = os.path.join(path,"version.py") + version_py = os.path.join(path, 'tofu', 'version.py') try: version_git = subprocess.check_output(["git", "describe"]).rstrip().decode() diff --git a/setup.py b/setup.py index 23e3c2e42..5f45f94c0 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,10 @@ from Cython.Distutils import build_ext import numpy as np # ... -import _updateversion as up +# Remove _updateversion import due to build-time dependency +# => updateversion defined in here for commodity +# => find a cleaner solution later +# import _updateversion as up # ... for `clean` command from distutils.command.clean import clean as Clean @@ -143,6 +146,26 @@ def check_for_openmp(cc_var): # == Getting tofu version ===================================================== _HERE = os.path.abspath(os.path.dirname(__file__)) + + +def updateversion(path=_HERE): + # Fetch version from git tags, and write to version.py + # Also, when git is not available (PyPi package), use stored version.py + version_py = os.path.join(path, 'tofu', 'version.py') + try: + version_git = subprocess.check_output(["git", + "describe"]).rstrip().decode() + except Exception as err: + with open(version_py, 'r') as fh: + version_git = fh.read().strip().split("=")[-1].replace("'", '') + version_git = version_git.lower().replace('v', '') + + version_msg = "# Do not edit, pipeline versioning governed by git tags!" + with open(version_py, "w") as fh: + msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git) + fh.write(version_msg + msg) + return version_git + def get_version_tofu(path=_HERE): # Try from git @@ -163,7 +186,7 @@ def get_version_tofu(path=_HERE): .decode() ) if git_branch in ["master"]: - version_tofu = up.updateversion(os.path.join(path, "tofu")) + version_tofu = updateversion(os.path.join(path, "tofu")) else: isgit = False except Exception: diff --git a/tofu/version.py b/tofu/version.py index f16ec2709..e5dd80cc9 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-a4' +__version__ = '1.4.2-a4-5-g9b404aa'