Changeset 255c4c8


Ignore:
Timestamp:
Mar 13, 2017, 10:23:21 PM (3 years ago)
Author:
Martin Hermant <martin.hermant@gmail.com>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, sampler
Children:
b991cc1
Parents:
20a33fb
Message:

cleaner api for Version.py

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Version.py

    r20a33fb r255c4c8  
    33
    44
    5 for l in open('VERSION').readlines(): exec (l.strip())
     5__version_info = {}
     6
     7def get_version_info():
     8    # read from VERSION
     9    # return dictionary filled with content of version
     10
     11    global __version_info
     12    if not __version_info:
     13      this_file_dir = os.path.dirname(os.path.abspath(__file__))
     14      version_file = os.path.join(this_file_dir,  'VERSION')
     15
     16      if not os.path.isfile(version_file):
     17          raise SystemError("VERSION file not found.")
    618
    719
    8 
    9 def get_aubio_version():
    10     # read from VERSION
    11     this_file_dir = os.path.dirname(os.path.abspath(__file__))
    12     version_file = os.path.join(this_file_dir,  'VERSION')
    13 
    14     if not os.path.isfile(version_file):
    15         raise SystemError("VERSION file not found.")
    16 
    17     for l in open(version_file).readlines():
     20      for l in open(version_file).readlines():
    1821        #exec (l.strip())
    1922        if l.startswith('AUBIO_MAJOR_VERSION'):
    20             AUBIO_MAJOR_VERSION = int(l.split('=')[1])
     23            __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1])
    2124        if l.startswith('AUBIO_MINOR_VERSION'):
    22             AUBIO_MINOR_VERSION = int(l.split('=')[1])
     25            __version_info['AUBIO_MINOR_VERSION'] = int(l.split('=')[1])
    2326        if l.startswith('AUBIO_PATCH_VERSION'):
    24             AUBIO_PATCH_VERSION = int(l.split('=')[1])
     27            __version_info['AUBIO_PATCH_VERSION'] = int(l.split('=')[1])
    2528        if l.startswith('AUBIO_VERSION_STATUS'):
    26             AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1]
     29            __version_info['AUBIO_VERSION_STATUS'] = l.split('=')[1].strip()[1:-1]
    2730
    28     if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \
    29             or AUBIO_PATCH_VERSION is None:
    30         raise SystemError("Failed parsing VERSION file.")
     31        if l.startswith('LIBAUBIO_LT_CUR'):
     32          __version_info['LIBAUBIO_LT_CUR'] = int(l.split('=')[1])
     33        if l.startswith('LIBAUBIO_LT_REV'):
     34          __version_info['LIBAUBIO_LT_REV'] = int(l.split('=')[1])
     35        if l.startswith('LIBAUBIO_LT_AGE'):
     36          __version_info['LIBAUBIO_LT_AGE'] = int(l.split('=')[1])
    3137
    32     verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION,
    33                                      AUBIO_MINOR_VERSION,
    34                                      AUBIO_PATCH_VERSION]))
     38      if len(__version_info) <6:
     39          raise SystemError("Failed parsing VERSION file.")
    3540
    36    
    37     # append sha to version in alpha release
    38     # MAJ.MIN.PATCH.{~git<sha> , ''}
    39     if '~alpha' in AUBIO_VERSION_STATUS :
    40         AUBIO_GIT_SHA = get_git_revision_hash()
    41         if AUBIO_GIT_SHA:
    42             AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
    4341
    44     if AUBIO_VERSION_STATUS is not None :
    45         verstr += AUBIO_VERSION_STATUS
     42      # switch version status with commit sha in alpha releases
     43      if __version_info['AUBIO_VERSION_STATUS'] and \
     44      '~alpha' in __version_info['AUBIO_VERSION_STATUS'] :
     45          AUBIO_GIT_SHA = get_git_revision_hash()
     46          if AUBIO_GIT_SHA:
     47            __version_info['AUBIO_VERSION_STATUS'] = '~git'+AUBIO_GIT_SHA
     48
     49    return __version_info
     50
     51
     52def get_aubio_version_tuple():
     53    d = get_version_info()
     54    return (d['AUBIO_MAJOR_VERSION'],d['AUBIO_MINOR_VERSION'],d['AUBIO_PATCH_VERSION'])
     55
     56def get_libaubio_version_tuple():
     57    d = get_version_info()
     58    return (d['LIBAUBIO_LT_CUR'],d['LIBAUBIO_LT_REV'],d['LIBAUBIO_LT_AGE'])
     59
     60def get_libaubio_version():
     61    return '%s.%s.%s'%get_libaubio_version_tuple()
     62
     63def get_aubio_version(add_status = True):
     64    # return string formatted as MAJ.MIN.PATCH.{~git<sha> , ''}
     65    vdict = get_version_info()
     66    verstr = '%s.%s.%s'%get_aubio_version_tuple()
     67    if add_status and vdict['AUBIO_VERSION_STATUS']:
     68        verstr += "."+vdict['AUBIO_VERSION_STATUS']
    4669    return verstr
    4770
    48 def get_aubio_pyversion():
     71def get_aubio_pyversion(add_status = True):
    4972    # convert to version for python according to pep 440
    5073    # see https://www.python.org/dev/peps/pep-0440/
    5174    # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''}
    52     verstr = get_aubio_version()
    53     spl = verstr.split('~')
    54     if len(spl)==2:
    55         verstr = spl[0] + '+a0.'+spl[1]
    56 
    57     # TODO: add rc, .dev, and .post suffixes, add numbering
     75    vdict = get_version_info()
     76    verstr = '%s.%s.%s'%get_aubio_version_tuple()
     77    if add_status and vdict['AUBIO_VERSION_STATUS'] :
     78      if '~git' in vdict['AUBIO_VERSION_STATUS']:
     79        verstr += "+a0."+vdict['AUBIO_VERSION_STATUS'][1:]
     80      elif '~alpha':
     81        verstr += "+a0"
     82      else:
     83        raise SystemError("Aubio version statut not supported : %s"%vdict['AUBIO_VERSION_STATUS'])
    5884    return verstr
    5985
     
    82108
    83109
    84 
    85 # append sha to version in alpha release
    86 if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
    87     AUBIO_GIT_SHA = get_git_revision_hash()
    88     if AUBIO_GIT_SHA:
    89         AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
  • wscript

    r20a33fb r255c4c8  
    2121
    2222
    23 VERSION = '.'.join ([str(x) for x in [
    24     AUBIO_MAJOR_VERSION,
    25     AUBIO_MINOR_VERSION,
    26     AUBIO_PATCH_VERSION
    27     ]]) + AUBIO_VERSION_STATUS
    28 
    29 LIB_VERSION = '.'.join ([str(x) for x in [
    30     LIBAUBIO_LT_CUR,
    31     LIBAUBIO_LT_REV,
    32     LIBAUBIO_LT_AGE]])
     23
     24
     25VERSION = get_aubio_version()
     26LIB_VERSION = get_libaubio_version()
    3327
    3428top = '.'
     
    135129    ctx.env['DEST_OS'] = target_platform
    136130
     131    version_dict = get_version_info();
    137132    ctx.define('AUBIO_VERSION',VERSION)
    138     ctx.define('AUBIO_MAJOR_VERSION',AUBIO_MAJOR_VERSION)
    139     ctx.define('AUBIO_MINOR_VERSION',AUBIO_MINOR_VERSION)
    140     ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)
    141     ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)
     133    ctx.define('AUBIO_MAJOR_VERSION', version_dict['AUBIO_MAJOR_VERSION'])
     134    ctx.define('AUBIO_MINOR_VERSION', version_dict['AUBIO_MINOR_VERSION'])
     135    ctx.define('AUBIO_PATCH_VERSION', version_dict['AUBIO_PATCH_VERSION'])
     136    ctx.define('AUBIO_VERSION_STATUS', version_dict['AUBIO_VERSION_STATUS'])
    142137   
    143138    if ctx.options.build_type == "debug":
Note: See TracChangeset for help on using the changeset viewer.