7 def get_version_info():
9 # return dictionary filled with content of version
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')
16 if not os.path.isfile(version_file):
17 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'] = l.split('=')[1].strip()[1:-1]
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])
38 if len(__version_info) <6:
39 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'],d['AUBIO_MINOR_VERSION'],d['AUBIO_PATCH_VERSION'])
56 def get_libaubio_version_tuple():
57 d = get_version_info()
58 return (d['LIBAUBIO_LT_CUR'],d['LIBAUBIO_LT_REV'],d['LIBAUBIO_LT_AGE'])
60 def get_libaubio_version():
61 return '%s.%s.%s'%get_libaubio_version_tuple()
63 def 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']
71 def get_aubio_pyversion(add_status = True):
72 # convert to version for python according to pep 440
73 # see https://www.python.org/dev/peps/pep-0440/
74 # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''}
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:]
83 raise SystemError("Aubio version statut not supported : %s"%vdict['AUBIO_VERSION_STATUS'])
88 def get_git_revision_hash( short=True):
90 if not os.path.isdir('.git'):
91 # print('Version : not in git repository : can\'t get sha')
95 aubio_dir = os.path.dirname(os.path.abspath(__file__))
96 if not os.path.exists(aubio_dir):
97 raise SystemError("git / root folder not found")
98 gitcmd = ['git','-C',aubio_dir ,'rev-parse']
100 gitcmd.append('--short')
101 gitcmd.append('HEAD')
103 outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
104 except Exception as e:
105 print ('git command error :%s'%e)