[aab682e] | 1 | |
---|
| 2 | import os |
---|
[638be5f] | 3 | |
---|
| 4 | |
---|
[255c4c8] | 5 | __version_info = {} |
---|
[aab682e] | 6 | |
---|
[07bfe2d2] | 7 | |
---|
[255c4c8] | 8 | def get_version_info(): |
---|
| 9 | # read from VERSION |
---|
| 10 | # return dictionary filled with content of version |
---|
[aab682e] | 11 | |
---|
[255c4c8] | 12 | if not __version_info: |
---|
[c23d45f] | 13 | this_file_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
[07bfe2d2] | 14 | version_file = os.path.join(this_file_dir, 'VERSION') |
---|
[c23d45f] | 15 | |
---|
| 16 | if not os.path.isfile(version_file): |
---|
| 17 | raise SystemError("VERSION file not found.") |
---|
| 18 | |
---|
| 19 | for l in open(version_file).readlines(): |
---|
| 20 | |
---|
[07bfe2d2] | 21 | if l.startswith('AUBIO_MAJOR_VERSION'): |
---|
| 22 | __version_info['AUBIO_MAJOR_VERSION'] = int(l.split('=')[1]) |
---|
| 23 | if l.startswith('AUBIO_MINOR_VERSION'): |
---|
| 24 | __version_info['AUBIO_MINOR_VERSION'] = int(l.split('=')[1]) |
---|
| 25 | if l.startswith('AUBIO_PATCH_VERSION'): |
---|
| 26 | __version_info['AUBIO_PATCH_VERSION'] = int(l.split('=')[1]) |
---|
| 27 | if l.startswith('AUBIO_VERSION_STATUS'): |
---|
| 28 | __version_info['AUBIO_VERSION_STATUS'] = \ |
---|
| 29 | l.split('=')[1].strip()[1:-1] |
---|
| 30 | |
---|
| 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]) |
---|
| 37 | |
---|
| 38 | if len(__version_info) < 6: |
---|
| 39 | raise SystemError("Failed parsing VERSION file.") |
---|
[c23d45f] | 40 | |
---|
| 41 | # switch version status with commit sha in alpha releases |
---|
| 42 | if __version_info['AUBIO_VERSION_STATUS'] and \ |
---|
[07bfe2d2] | 43 | '~alpha' in __version_info['AUBIO_VERSION_STATUS']: |
---|
[c23d45f] | 44 | AUBIO_GIT_SHA = get_git_revision_hash() |
---|
| 45 | if AUBIO_GIT_SHA: |
---|
[7b9b6ba] | 46 | __version_info['AUBIO_VERSION_STATUS'] = '~git+' + AUBIO_GIT_SHA |
---|
[255c4c8] | 47 | |
---|
| 48 | return __version_info |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def get_aubio_version_tuple(): |
---|
| 52 | d = get_version_info() |
---|
[07bfe2d2] | 53 | return (d['AUBIO_MAJOR_VERSION'], |
---|
| 54 | d['AUBIO_MINOR_VERSION'], |
---|
| 55 | d['AUBIO_PATCH_VERSION']) |
---|
| 56 | |
---|
[255c4c8] | 57 | |
---|
| 58 | def get_libaubio_version_tuple(): |
---|
| 59 | d = get_version_info() |
---|
[07bfe2d2] | 60 | return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE']) |
---|
| 61 | |
---|
[255c4c8] | 62 | |
---|
| 63 | def get_libaubio_version(): |
---|
[07bfe2d2] | 64 | return '%s.%s.%s' % get_libaubio_version_tuple() |
---|
[255c4c8] | 65 | |
---|
[07bfe2d2] | 66 | |
---|
| 67 | def get_aubio_version(add_status=True): |
---|
[c6c20be] | 68 | # return string formatted as MAJ.MIN.PATCH{~git<sha> , ''} |
---|
[255c4c8] | 69 | vdict = get_version_info() |
---|
[07bfe2d2] | 70 | verstr = '%s.%s.%s' % get_aubio_version_tuple() |
---|
[255c4c8] | 71 | if add_status and vdict['AUBIO_VERSION_STATUS']: |
---|
[c6c20be] | 72 | verstr += vdict['AUBIO_VERSION_STATUS'] |
---|
[35f995c] | 73 | return str(verstr) |
---|
[aab682e] | 74 | |
---|
[07bfe2d2] | 75 | |
---|
| 76 | def get_aubio_pyversion(add_status=True): |
---|
[aab682e] | 77 | # convert to version for python according to pep 440 |
---|
| 78 | # see https://www.python.org/dev/peps/pep-0440/ |
---|
[87a4a5a] | 79 | # outputs MAJ.MIN.PATCH[a0[+git.<sha>[.mods]]] |
---|
[255c4c8] | 80 | vdict = get_version_info() |
---|
[07bfe2d2] | 81 | verstr = '%s.%s.%s' % get_aubio_version_tuple() |
---|
| 82 | if add_status and vdict['AUBIO_VERSION_STATUS']: |
---|
[87a4a5a] | 83 | if vdict['AUBIO_VERSION_STATUS'].startswith('~git+'): |
---|
| 84 | pep440str = vdict['AUBIO_VERSION_STATUS'].replace('+', '.') |
---|
| 85 | verstr += pep440str.replace('~git.', 'a0+') |
---|
[c6c20be] | 86 | elif '~alpha' in vdict['AUBIO_VERSION_STATUS']: |
---|
[87a4a5a] | 87 | verstr += "a0" |
---|
[07bfe2d2] | 88 | else: |
---|
| 89 | raise SystemError("Aubio version statut not supported : %s" % |
---|
| 90 | vdict['AUBIO_VERSION_STATUS']) |
---|
[aab682e] | 91 | return verstr |
---|
| 92 | |
---|
| 93 | |
---|
[07bfe2d2] | 94 | def get_git_revision_hash(short=True): |
---|
[aab682e] | 95 | |
---|
| 96 | if not os.path.isdir('.git'): |
---|
| 97 | # print('Version : not in git repository : can\'t get sha') |
---|
[638be5f] | 98 | return None |
---|
[aab682e] | 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") |
---|
[07bfe2d2] | 104 | gitcmd = ['git', '-C', aubio_dir, 'rev-parse'] |
---|
[aab682e] | 105 | if short: |
---|
[c23d45f] | 106 | gitcmd.append('--short') |
---|
[aab682e] | 107 | gitcmd.append('HEAD') |
---|
[638be5f] | 108 | try: |
---|
[c23d45f] | 109 | outCmd = subprocess.check_output(gitcmd).strip().decode('utf8') |
---|
[638be5f] | 110 | except Exception as e: |
---|
[07bfe2d2] | 111 | print('git command error :%s' % e) |
---|
[c23d45f] | 112 | return None |
---|
[aab682e] | 113 | return outCmd |
---|