source: this_version.py @ 07bfe2d2

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchsampler
Last change on this file since 07bfe2d2 was 07bfe2d2, checked in by Paul Brossier <piem@piem.org>, 2 years ago

fix pep8 errors

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