[255fe0a] | 1 | #! python |
---|
[aab682e] | 2 | import os |
---|
[638be5f] | 3 | |
---|
[255fe0a] | 4 | __version_info = {} # keep a reference to parse VERSION once |
---|
[07bfe2d2] | 5 | |
---|
[255c4c8] | 6 | def get_version_info(): |
---|
| 7 | # read from VERSION |
---|
| 8 | # return dictionary filled with content of version |
---|
| 9 | if not __version_info: |
---|
[c23d45f] | 10 | this_file_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
[07bfe2d2] | 11 | version_file = os.path.join(this_file_dir, 'VERSION') |
---|
[c23d45f] | 12 | |
---|
| 13 | if not os.path.isfile(version_file): |
---|
| 14 | raise SystemError("VERSION file not found.") |
---|
| 15 | |
---|
| 16 | for l in open(version_file).readlines(): |
---|
[07bfe2d2] | 17 | if l.startswith('AUBIO_MAJOR_VERSION'): |
---|
| 18 | __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1]) |
---|
| 19 | if l.startswith('AUBIO_MINOR_VERSION'): |
---|
| 20 | __version_info['AUBIO_MINOR_VERSION'] = int(l.split('=')[1]) |
---|
| 21 | if l.startswith('AUBIO_PATCH_VERSION'): |
---|
| 22 | __version_info['AUBIO_PATCH_VERSION'] = int(l.split('=')[1]) |
---|
| 23 | if l.startswith('AUBIO_VERSION_STATUS'): |
---|
| 24 | __version_info['AUBIO_VERSION_STATUS'] = \ |
---|
| 25 | l.split('=')[1].strip()[1:-1] |
---|
| 26 | |
---|
| 27 | if l.startswith('LIBAUBIO_LT_CUR'): |
---|
| 28 | __version_info['LIBAUBIO_LT_CUR'] = int(l.split('=')[1]) |
---|
| 29 | if l.startswith('LIBAUBIO_LT_REV'): |
---|
| 30 | __version_info['LIBAUBIO_LT_REV'] = int(l.split('=')[1]) |
---|
| 31 | if l.startswith('LIBAUBIO_LT_AGE'): |
---|
| 32 | __version_info['LIBAUBIO_LT_AGE'] = int(l.split('=')[1]) |
---|
| 33 | |
---|
| 34 | if len(__version_info) < 6: |
---|
| 35 | raise SystemError("Failed parsing VERSION file.") |
---|
[c23d45f] | 36 | |
---|
| 37 | # switch version status with commit sha in alpha releases |
---|
| 38 | if __version_info['AUBIO_VERSION_STATUS'] and \ |
---|
[07bfe2d2] | 39 | '~alpha' in __version_info['AUBIO_VERSION_STATUS']: |
---|
[c23d45f] | 40 | AUBIO_GIT_SHA = get_git_revision_hash() |
---|
| 41 | if AUBIO_GIT_SHA: |
---|
[7b9b6ba] | 42 | __version_info['AUBIO_VERSION_STATUS'] = '~git+' + AUBIO_GIT_SHA |
---|
[255c4c8] | 43 | |
---|
| 44 | return __version_info |
---|
| 45 | |
---|
| 46 | def get_libaubio_version(): |
---|
[255fe0a] | 47 | verfmt = '%(LIBAUBIO_LT_CUR)s.%(LIBAUBIO_LT_REV)s.%(LIBAUBIO_LT_AGE)s' |
---|
| 48 | return str(verfmt % get_version_info()) |
---|
[07bfe2d2] | 49 | |
---|
[255fe0a] | 50 | def get_aubio_version(): |
---|
| 51 | verfmt = '%(AUBIO_MAJOR_VERSION)s.%(AUBIO_MINOR_VERSION)s.%(AUBIO_PATCH_VERSION)s%(AUBIO_VERSION_STATUS)s' |
---|
| 52 | return str(verfmt % get_version_info()) |
---|
[aab682e] | 53 | |
---|
[255fe0a] | 54 | def get_aubio_pyversion(): |
---|
[aab682e] | 55 | # convert to version for python according to pep 440 |
---|
| 56 | # see https://www.python.org/dev/peps/pep-0440/ |
---|
[87a4a5a] | 57 | # outputs MAJ.MIN.PATCH[a0[+git.<sha>[.mods]]] |
---|
[255fe0a] | 58 | aubio_version = get_aubio_version() |
---|
| 59 | if '~git+' in aubio_version: |
---|
| 60 | pep440str = aubio_version.replace('+', '.') |
---|
| 61 | verstr = pep440str.replace('~git.', 'a0+') |
---|
| 62 | elif '~alpha' in aubio_version: |
---|
[f5bb097] | 63 | verstr = aubio_version.replace('~alpha', 'a0') |
---|
| 64 | else: |
---|
| 65 | verstr = aubio_version |
---|
[aab682e] | 66 | return verstr |
---|
| 67 | |
---|
[07bfe2d2] | 68 | def get_git_revision_hash(short=True): |
---|
[255fe0a] | 69 | # get commit id, with +mods if local tree is not clean |
---|
[aab682e] | 70 | if not os.path.isdir('.git'): |
---|
| 71 | # print('Version : not in git repository : can\'t get sha') |
---|
[638be5f] | 72 | return None |
---|
[aab682e] | 73 | import subprocess |
---|
| 74 | aubio_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
| 75 | if not os.path.exists(aubio_dir): |
---|
| 76 | raise SystemError("git / root folder not found") |
---|
[07bfe2d2] | 77 | gitcmd = ['git', '-C', aubio_dir, 'rev-parse'] |
---|
[aab682e] | 78 | if short: |
---|
[c23d45f] | 79 | gitcmd.append('--short') |
---|
[aab682e] | 80 | gitcmd.append('HEAD') |
---|
[638be5f] | 81 | try: |
---|
[f7b7a35] | 82 | gitsha = subprocess.check_output(gitcmd).strip().decode('utf8') |
---|
[638be5f] | 83 | except Exception as e: |
---|
[07bfe2d2] | 84 | print('git command error :%s' % e) |
---|
[c23d45f] | 85 | return None |
---|
[f7b7a35] | 86 | # check if we have a clean tree |
---|
[115b452] | 87 | gitcmd = ['git', '-C', aubio_dir, 'status', '--porcelain'] |
---|
[f7b7a35] | 88 | try: |
---|
[115b452] | 89 | output = subprocess.check_output(gitcmd).decode('utf8') |
---|
| 90 | if len(output): |
---|
| 91 | print('Info: current tree is not clean\n') |
---|
| 92 | print(output) |
---|
| 93 | gitsha += '+mods' |
---|
| 94 | except subprocess.CalledProcessError as e: |
---|
| 95 | print (e) |
---|
| 96 | pass |
---|
[f7b7a35] | 97 | return gitsha |
---|
[255fe0a] | 98 | |
---|
| 99 | if __name__ == '__main__': |
---|
| 100 | print ('%30s'% 'aubio version:', get_aubio_version()) |
---|
| 101 | print ('%30s'% 'python-aubio version:', get_aubio_pyversion()) |
---|