[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 | global __version_info |
---|
| 13 | if not __version_info: |
---|
[c23d45f] | 14 | this_file_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
[07bfe2d2] | 15 | version_file = os.path.join(this_file_dir, 'VERSION') |
---|
[c23d45f] | 16 | |
---|
| 17 | if not os.path.isfile(version_file): |
---|
| 18 | raise SystemError("VERSION file not found.") |
---|
| 19 | |
---|
| 20 | for l in open(version_file).readlines(): |
---|
| 21 | |
---|
[07bfe2d2] | 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] |
---|
| 31 | |
---|
| 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]) |
---|
| 38 | |
---|
| 39 | if len(__version_info) < 6: |
---|
| 40 | raise SystemError("Failed parsing VERSION file.") |
---|
[c23d45f] | 41 | |
---|
| 42 | # switch version status with commit sha in alpha releases |
---|
| 43 | if __version_info['AUBIO_VERSION_STATUS'] and \ |
---|
[07bfe2d2] | 44 | '~alpha' in __version_info['AUBIO_VERSION_STATUS']: |
---|
[c23d45f] | 45 | AUBIO_GIT_SHA = get_git_revision_hash() |
---|
| 46 | if AUBIO_GIT_SHA: |
---|
[07bfe2d2] | 47 | __version_info['AUBIO_VERSION_STATUS'] = '~git' + AUBIO_GIT_SHA |
---|
[255c4c8] | 48 | |
---|
| 49 | return __version_info |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | def get_aubio_version_tuple(): |
---|
| 53 | d = get_version_info() |
---|
[07bfe2d2] | 54 | return (d['AUBIO_MAJOR_VERSION'], |
---|
| 55 | d['AUBIO_MINOR_VERSION'], |
---|
| 56 | d['AUBIO_PATCH_VERSION']) |
---|
| 57 | |
---|
[255c4c8] | 58 | |
---|
| 59 | def get_libaubio_version_tuple(): |
---|
| 60 | d = get_version_info() |
---|
[07bfe2d2] | 61 | return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE']) |
---|
| 62 | |
---|
[255c4c8] | 63 | |
---|
| 64 | def get_libaubio_version(): |
---|
[07bfe2d2] | 65 | return '%s.%s.%s' % get_libaubio_version_tuple() |
---|
[255c4c8] | 66 | |
---|
[07bfe2d2] | 67 | |
---|
| 68 | def get_aubio_version(add_status=True): |
---|
[255c4c8] | 69 | # return string formatted as MAJ.MIN.PATCH.{~git<sha> , ''} |
---|
| 70 | vdict = get_version_info() |
---|
[07bfe2d2] | 71 | verstr = '%s.%s.%s' % get_aubio_version_tuple() |
---|
[255c4c8] | 72 | if add_status and vdict['AUBIO_VERSION_STATUS']: |
---|
[07bfe2d2] | 73 | verstr += "." + vdict['AUBIO_VERSION_STATUS'] |
---|
[aab682e] | 74 | return verstr |
---|
| 75 | |
---|
[07bfe2d2] | 76 | |
---|
| 77 | def get_aubio_pyversion(add_status=True): |
---|
[aab682e] | 78 | # convert to version for python according to pep 440 |
---|
| 79 | # see https://www.python.org/dev/peps/pep-0440/ |
---|
[20a33fb] | 80 | # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''} |
---|
[255c4c8] | 81 | vdict = get_version_info() |
---|
[07bfe2d2] | 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:] |
---|
| 86 | elif '~alpha': |
---|
| 87 | verstr += "+a0" |
---|
| 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 |
---|