8 def get_version_info():
10 # return dictionary filled with content of version
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')
17 if not os.path.isfile(version_file):
18 raise SystemError("VERSION file not found.")
20 for l in open(version_file).readlines():
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]
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])
39 if len(__version_info) < 6:
40 raise SystemError("Failed parsing VERSION file.")
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()
47 __version_info['AUBIO_VERSION_STATUS'] = '~git' + AUBIO_GIT_SHA
52 def 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'])
59 def get_libaubio_version_tuple():
60 d = get_version_info()
61 return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE'])
64 def get_libaubio_version():
65 return '%s.%s.%s' % get_libaubio_version_tuple()
68 def 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']
77 def 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:]
89 raise SystemError("Aubio version statut not supported : %s" %
90 vdict['AUBIO_VERSION_STATUS'])
94 def get_git_revision_hash(short=True):
96 if not os.path.isdir('.git'):
97 # print('Version : not in git repository : can\'t get sha')
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']
106 gitcmd.append('--short')
107 gitcmd.append('HEAD')
109 outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
110 except Exception as e:
111 print('git command error :%s' % e)