Changeset 255fe0a for this_version.py


Ignore:
Timestamp:
Mar 23, 2017, 6:29:30 PM (2 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, sampler
Children:
8da4d59
Parents:
f7b7a35
Message:

this_version.py: simplify, add main to check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • this_version.py

    rf7b7a35 r255fe0a  
    1 
     1#! python
    22import os
    33
    4 
    5 __version_info = {}
    6 
     4__version_info = {} # keep a reference to parse VERSION once
    75
    86def get_version_info():
    97    # read from VERSION
    108    # return dictionary filled with content of version
    11 
    129    if not __version_info:
    1310        this_file_dir = os.path.dirname(os.path.abspath(__file__))
     
    1815
    1916        for l in open(version_file).readlines():
    20 
    2117            if l.startswith('AUBIO_MAJOR_VERSION'):
    2218                __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1])
     
    4844    return __version_info
    4945
     46def get_libaubio_version():
     47    verfmt = '%(LIBAUBIO_LT_CUR)s.%(LIBAUBIO_LT_REV)s.%(LIBAUBIO_LT_AGE)s'
     48    return str(verfmt % get_version_info())
    5049
    51 def get_aubio_version_tuple():
    52     d = get_version_info()
    53     return (d['AUBIO_MAJOR_VERSION'],
    54             d['AUBIO_MINOR_VERSION'],
    55             d['AUBIO_PATCH_VERSION'])
     50def get_aubio_version():
     51    verfmt = '%(AUBIO_MAJOR_VERSION)s.%(AUBIO_MINOR_VERSION)s.%(AUBIO_PATCH_VERSION)s%(AUBIO_VERSION_STATUS)s'
     52    return str(verfmt % get_version_info())
    5653
    57 
    58 def get_libaubio_version_tuple():
    59     d = get_version_info()
    60     return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE'])
    61 
    62 
    63 def get_libaubio_version():
    64     return '%s.%s.%s' % get_libaubio_version_tuple()
    65 
    66 
    67 def get_aubio_version(add_status=True):
    68     # return string formatted as MAJ.MIN.PATCH{~git<sha> , ''}
    69     vdict = get_version_info()
    70     verstr = '%s.%s.%s' % get_aubio_version_tuple()
    71     if add_status and vdict['AUBIO_VERSION_STATUS']:
    72         verstr += vdict['AUBIO_VERSION_STATUS']
    73     return str(verstr)
    74 
    75 
    76 def get_aubio_pyversion(add_status=True):
     54def get_aubio_pyversion():
    7755    # convert to version for python according to pep 440
    7856    # see https://www.python.org/dev/peps/pep-0440/
    7957    # outputs MAJ.MIN.PATCH[a0[+git.<sha>[.mods]]]
    80     vdict = get_version_info()
    81     verstr = '%s.%s.%s' % get_aubio_version_tuple()
    82     if add_status and vdict['AUBIO_VERSION_STATUS']:
    83         if vdict['AUBIO_VERSION_STATUS'].startswith('~git+'):
    84             pep440str = vdict['AUBIO_VERSION_STATUS'].replace('+', '.')
    85             verstr += pep440str.replace('~git.', 'a0+')
    86         elif '~alpha' in vdict['AUBIO_VERSION_STATUS']:
    87             verstr += "a0"
    88         else:
    89             raise SystemError("Aubio version statut not supported : %s" %
    90                               vdict['AUBIO_VERSION_STATUS'])
     58    aubio_version = get_aubio_version()
     59    if '~git+' in aubio_version:
     60        pep440str = aubio_version.replace('+', '.')
     61        verstr = pep440str.replace('~git.', 'a0+')
     62    elif '~alpha' in aubio_version:
     63        verstr += "a0"
    9164    return verstr
    9265
    93 
    9466def get_git_revision_hash(short=True):
    95 
     67    # get commit id, with +mods if local tree is not clean
    9668    if not os.path.isdir('.git'):
    9769        # print('Version : not in git repository : can\'t get sha')
    9870        return None
    99 
    10071    import subprocess
    10172    aubio_dir = os.path.dirname(os.path.abspath(__file__))
     
    11182        print('git command error :%s' % e)
    11283        return None
    113 
    11484    # check if we have a clean tree
    11585    gitcmd = ['git', '-C', aubio_dir, 'diff-index', '--quiet']
     
    12090        gitsha += '+mods'
    12191    return gitsha
     92
     93if __name__ == '__main__':
     94    print ('%30s'% 'aubio version:', get_aubio_version())
     95    print ('%30s'% 'python-aubio version:', get_aubio_pyversion())
Note: See TracChangeset for help on using the changeset viewer.