5 __version_info = {} # keep a reference to parse VERSION once
7 def get_version_info():
9 # return dictionary filled with content of version
10 if not __version_info:
11 this_file_dir = os.path.dirname(os.path.abspath(__file__))
12 version_file = os.path.join(this_file_dir, 'VERSION')
14 if not os.path.isfile(version_file):
15 raise SystemError("VERSION file not found.")
17 for l in open(version_file).readlines():
18 if l.startswith('AUBIO_MAJOR_VERSION'):
19 __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1])
20 if l.startswith('AUBIO_MINOR_VERSION'):
21 __version_info['AUBIO_MINOR_VERSION'] = int(l.split('=')[1])
22 if l.startswith('AUBIO_PATCH_VERSION'):
23 __version_info['AUBIO_PATCH_VERSION'] = int(l.split('=')[1])
24 if l.startswith('AUBIO_VERSION_STATUS'):
25 __version_info['AUBIO_VERSION_STATUS'] = \
26 l.split('=')[1].strip()[1:-1]
28 if l.startswith('LIBAUBIO_LT_CUR'):
29 __version_info['LIBAUBIO_LT_CUR'] = int(l.split('=')[1])
30 if l.startswith('LIBAUBIO_LT_REV'):
31 __version_info['LIBAUBIO_LT_REV'] = int(l.split('=')[1])
32 if l.startswith('LIBAUBIO_LT_AGE'):
33 __version_info['LIBAUBIO_LT_AGE'] = int(l.split('=')[1])
35 if len(__version_info) < 6:
36 raise SystemError("Failed parsing VERSION file.")
38 # switch version status with commit sha in alpha releases
39 if __version_info['AUBIO_VERSION_STATUS'] and \
40 '~alpha' in __version_info['AUBIO_VERSION_STATUS']:
41 AUBIO_GIT_SHA = get_git_revision_hash()
43 __version_info['AUBIO_VERSION_STATUS'] = '~git+' + AUBIO_GIT_SHA
47 def get_libaubio_version():
48 verfmt = '%(LIBAUBIO_LT_CUR)s.%(LIBAUBIO_LT_REV)s.%(LIBAUBIO_LT_AGE)s'
49 return str(verfmt % get_version_info())
51 def get_aubio_version():
52 verfmt = '%(AUBIO_MAJOR_VERSION)s.%(AUBIO_MINOR_VERSION)s.%(AUBIO_PATCH_VERSION)s%(AUBIO_VERSION_STATUS)s'
53 return str(verfmt % get_version_info())
55 def get_aubio_pyversion():
56 # convert to version for python according to pep 440
57 # see https://www.python.org/dev/peps/pep-0440/
58 # outputs MAJ.MIN.PATCH[a0[+git.<sha>[.mods]]]
59 aubio_version = get_aubio_version()
60 if '~git+' in aubio_version:
61 pep440str = aubio_version.replace('+', '.')
62 verstr = pep440str.replace('~git.', 'a0+')
63 elif '~alpha' in aubio_version:
64 verstr = aubio_version.replace('~alpha', 'a0')
66 verstr = aubio_version
69 def get_git_revision_hash(short=True):
70 # get commit id, with +mods if local tree is not clean
71 if not os.path.isdir('.git'):
72 # print('Version : not in git repository : can\'t get sha')
75 aubio_dir = os.path.dirname(os.path.abspath(__file__))
76 if not os.path.exists(aubio_dir):
77 raise SystemError("git / root folder not found")
78 gitcmd = ['git', '-C', aubio_dir, 'rev-parse']
80 gitcmd.append('--short')
83 gitsha = subprocess.check_output(gitcmd).strip().decode('utf8')
84 except Exception as e:
85 sys.stderr.write('git command error :%s\n' % e)
87 # check if we have a clean tree
88 gitcmd = ['git', '-C', aubio_dir, 'status', '--porcelain']
90 output = subprocess.check_output(gitcmd).decode('utf8')
92 sys.stderr.write('Info: current tree is not clean\n\n')
93 sys.stderr.write(output + '\n')
95 except subprocess.CalledProcessError as e:
96 sys.stderr.write('git command error :%s\n' % e)
100 if __name__ == '__main__':
101 if len(sys.argv) > 1 and sys.argv[1] == '-v':
102 print (get_aubio_version())
103 elif len(sys.argv) > 1 and sys.argv[1] == '-p':
104 print (get_aubio_version())
106 print ('%30s'% 'aubio version:', get_aubio_version())
107 print ('%30s'% 'python-aubio version:', get_aubio_pyversion())