source: this_version.py @ 35f995c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since 35f995c was 35f995c, checked in by Paul Brossier <piem@piem.org>, 7 years ago

this_version.py: always return a string, not unicode

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[aab682e]1
2import os
[638be5f]3
4
[255c4c8]5__version_info = {}
[aab682e]6
[07bfe2d2]7
[255c4c8]8def get_version_info():
9    # read from VERSION
10    # return dictionary filled with content of version
[aab682e]11
[255c4c8]12    if not __version_info:
[c23d45f]13        this_file_dir = os.path.dirname(os.path.abspath(__file__))
[07bfe2d2]14        version_file = os.path.join(this_file_dir, 'VERSION')
[c23d45f]15
16        if not os.path.isfile(version_file):
17            raise SystemError("VERSION file not found.")
18
19        for l in open(version_file).readlines():
20
[07bfe2d2]21            if l.startswith('AUBIO_MAJOR_VERSION'):
22                __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1])
23            if l.startswith('AUBIO_MINOR_VERSION'):
24                __version_info['AUBIO_MINOR_VERSION'] = int(l.split('=')[1])
25            if l.startswith('AUBIO_PATCH_VERSION'):
26                __version_info['AUBIO_PATCH_VERSION'] = int(l.split('=')[1])
27            if l.startswith('AUBIO_VERSION_STATUS'):
28                __version_info['AUBIO_VERSION_STATUS'] = \
29                    l.split('=')[1].strip()[1:-1]
30
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])
37
38        if len(__version_info) < 6:
39            raise SystemError("Failed parsing VERSION file.")
[c23d45f]40
41        # switch version status with commit sha in alpha releases
42        if __version_info['AUBIO_VERSION_STATUS'] and \
[07bfe2d2]43                '~alpha' in __version_info['AUBIO_VERSION_STATUS']:
[c23d45f]44            AUBIO_GIT_SHA = get_git_revision_hash()
45            if AUBIO_GIT_SHA:
[07bfe2d2]46                __version_info['AUBIO_VERSION_STATUS'] = '~git' + AUBIO_GIT_SHA
[255c4c8]47
48    return __version_info
49
50
51def get_aubio_version_tuple():
52    d = get_version_info()
[07bfe2d2]53    return (d['AUBIO_MAJOR_VERSION'],
54            d['AUBIO_MINOR_VERSION'],
55            d['AUBIO_PATCH_VERSION'])
56
[255c4c8]57
58def get_libaubio_version_tuple():
59    d = get_version_info()
[07bfe2d2]60    return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE'])
61
[255c4c8]62
63def get_libaubio_version():
[07bfe2d2]64    return '%s.%s.%s' % get_libaubio_version_tuple()
[255c4c8]65
[07bfe2d2]66
67def get_aubio_version(add_status=True):
[c6c20be]68    # return string formatted as MAJ.MIN.PATCH{~git<sha> , ''}
[255c4c8]69    vdict = get_version_info()
[07bfe2d2]70    verstr = '%s.%s.%s' % get_aubio_version_tuple()
[255c4c8]71    if add_status and vdict['AUBIO_VERSION_STATUS']:
[c6c20be]72        verstr += vdict['AUBIO_VERSION_STATUS']
[35f995c]73    return str(verstr)
[aab682e]74
[07bfe2d2]75
76def get_aubio_pyversion(add_status=True):
[aab682e]77    # convert to version for python according to pep 440
78    # see https://www.python.org/dev/peps/pep-0440/
[20a33fb]79    # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''}
[255c4c8]80    vdict = get_version_info()
[07bfe2d2]81    verstr = '%s.%s.%s' % get_aubio_version_tuple()
82    if add_status and vdict['AUBIO_VERSION_STATUS']:
83        if '~git' in vdict['AUBIO_VERSION_STATUS']:
84            verstr += "+a0." + vdict['AUBIO_VERSION_STATUS'][1:]
[c6c20be]85        elif '~alpha' in vdict['AUBIO_VERSION_STATUS']:
[07bfe2d2]86            verstr += "+a0"
87        else:
88            raise SystemError("Aubio version statut not supported : %s" %
89                              vdict['AUBIO_VERSION_STATUS'])
[aab682e]90    return verstr
91
92
[07bfe2d2]93def get_git_revision_hash(short=True):
[aab682e]94
95    if not os.path.isdir('.git'):
96        # print('Version : not in git repository : can\'t get sha')
[638be5f]97        return None
[aab682e]98
99    import subprocess
100    aubio_dir = os.path.dirname(os.path.abspath(__file__))
101    if not os.path.exists(aubio_dir):
102        raise SystemError("git / root folder not found")
[07bfe2d2]103    gitcmd = ['git', '-C', aubio_dir, 'rev-parse']
[aab682e]104    if short:
[c23d45f]105        gitcmd.append('--short')
[aab682e]106    gitcmd.append('HEAD')
[638be5f]107    try:
[c23d45f]108        outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
[638be5f]109    except Exception as e:
[07bfe2d2]110        print('git command error :%s' % e)
[c23d45f]111        return None
[aab682e]112    return outCmd
Note: See TracBrowser for help on using the repository browser.