From 9b404aac2e0e500a04991074ceb5ca9a71c5dc16 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 28 Nov 2019 10:38:38 +0100 Subject: [PATCH 1/2] [Issue292] Hotfix by defining updateversion in setup.py and keeping _updateversion.py also --- _updateversion.py | 5 ++--- setup.py | 26 ++++++++++++++++++++++++-- tofu/version.py | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) 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..2fad01b84 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,25 @@ 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: + 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 +185,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..9c572aae8 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-4-g9531f81' From 623b6f7b4f6ce4f4165b8ff1bcabac865b80abb5 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 28 Nov 2019 10:52:12 +0100 Subject: [PATCH 2/2] [Issue292] PEP8 Compliance --- setup.py | 11 ++++++----- tofu/version.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 2fad01b84..5f45f94c0 100644 --- a/setup.py +++ b/setup.py @@ -147,6 +147,7 @@ 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 @@ -154,13 +155,13 @@ def updateversion(path=_HERE): try: version_git = subprocess.check_output(["git", "describe"]).rstrip().decode() - except: - with open(version_py,'r') as fh: - version_git = fh.read().strip().split("=")[-1].replace("'",'') - version_git = version_git.lower().replace('v','') + 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: + 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 diff --git a/tofu/version.py b/tofu/version.py index 9c572aae8..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-4-g9531f81' +__version__ = '1.4.2-a4-5-g9b404aa'