From 255fe0af022bbd0b92d4b4f30e1668e15327d0a7 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 23 Mar 2017 18:29:30 +0100 Subject: [PATCH] this_version.py: simplify, add main to check --- this_version.py | 64 +++++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 45 deletions(-) diff --git a/this_version.py b/this_version.py index cbafdb16..903c16da 100644 --- a/this_version.py +++ b/this_version.py @@ -1,14 +1,11 @@ - +#! python import os - -__version_info = {} - +__version_info = {} # keep a reference to parse VERSION once def get_version_info(): # read from VERSION # return dictionary filled with content of version - if not __version_info: this_file_dir = os.path.dirname(os.path.abspath(__file__)) version_file = os.path.join(this_file_dir, 'VERSION') @@ -17,7 +14,6 @@ def get_version_info(): raise SystemError("VERSION file not found.") for l in open(version_file).readlines(): - if l.startswith('AUBIO_MAJOR_VERSION'): __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1]) if l.startswith('AUBIO_MINOR_VERSION'): @@ -47,56 +43,31 @@ def get_version_info(): return __version_info - -def get_aubio_version_tuple(): - d = get_version_info() - return (d['AUBIO_MAJOR_VERSION'], - d['AUBIO_MINOR_VERSION'], - d['AUBIO_PATCH_VERSION']) - - -def get_libaubio_version_tuple(): - d = get_version_info() - return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE']) - - def get_libaubio_version(): - return '%s.%s.%s' % get_libaubio_version_tuple() - + verfmt = '%(LIBAUBIO_LT_CUR)s.%(LIBAUBIO_LT_REV)s.%(LIBAUBIO_LT_AGE)s' + return str(verfmt % get_version_info()) -def get_aubio_version(add_status=True): - # return string formatted as MAJ.MIN.PATCH{~git , ''} - vdict = get_version_info() - verstr = '%s.%s.%s' % get_aubio_version_tuple() - if add_status and vdict['AUBIO_VERSION_STATUS']: - verstr += vdict['AUBIO_VERSION_STATUS'] - return str(verstr) +def get_aubio_version(): + verfmt = '%(AUBIO_MAJOR_VERSION)s.%(AUBIO_MINOR_VERSION)s.%(AUBIO_PATCH_VERSION)s%(AUBIO_VERSION_STATUS)s' + return str(verfmt % get_version_info()) - -def get_aubio_pyversion(add_status=True): +def get_aubio_pyversion(): # convert to version for python according to pep 440 # see https://www.python.org/dev/peps/pep-0440/ # outputs MAJ.MIN.PATCH[a0[+git.[.mods]]] - vdict = get_version_info() - verstr = '%s.%s.%s' % get_aubio_version_tuple() - if add_status and vdict['AUBIO_VERSION_STATUS']: - if vdict['AUBIO_VERSION_STATUS'].startswith('~git+'): - pep440str = vdict['AUBIO_VERSION_STATUS'].replace('+', '.') - verstr += pep440str.replace('~git.', 'a0+') - elif '~alpha' in vdict['AUBIO_VERSION_STATUS']: - verstr += "a0" - else: - raise SystemError("Aubio version statut not supported : %s" % - vdict['AUBIO_VERSION_STATUS']) + aubio_version = get_aubio_version() + if '~git+' in aubio_version: + pep440str = aubio_version.replace('+', '.') + verstr = pep440str.replace('~git.', 'a0+') + elif '~alpha' in aubio_version: + verstr += "a0" return verstr - def get_git_revision_hash(short=True): - + # get commit id, with +mods if local tree is not clean if not os.path.isdir('.git'): # print('Version : not in git repository : can\'t get sha') return None - import subprocess aubio_dir = os.path.dirname(os.path.abspath(__file__)) if not os.path.exists(aubio_dir): @@ -110,7 +81,6 @@ def get_git_revision_hash(short=True): except Exception as e: print('git command error :%s' % e) return None - # check if we have a clean tree gitcmd = ['git', '-C', aubio_dir, 'diff-index', '--quiet'] gitcmd.append('HEAD') @@ -119,3 +89,7 @@ def get_git_revision_hash(short=True): except Exception as e: gitsha += '+mods' return gitsha + +if __name__ == '__main__': + print ('%30s'% 'aubio version:', get_aubio_version()) + print ('%30s'% 'python-aubio version:', get_aubio_pyversion()) -- 2.11.0