[aab682e] | 1 | |
---|
| 2 | import os |
---|
[638be5f] | 3 | |
---|
| 4 | |
---|
[255c4c8] | 5 | __version_info = {} |
---|
[aab682e] | 6 | |
---|
[255c4c8] | 7 | def get_version_info(): |
---|
| 8 | # read from VERSION |
---|
| 9 | # return dictionary filled with content of version |
---|
[aab682e] | 10 | |
---|
[255c4c8] | 11 | global __version_info |
---|
| 12 | if not __version_info: |
---|
[c23d45f] | 13 | this_file_dir = os.path.dirname(os.path.abspath(__file__)) |
---|
| 14 | version_file = os.path.join(this_file_dir, 'VERSION') |
---|
| 15 | |
---|
| 16 | if not os.path.isfile(version_file): |
---|
| 17 | raise SystemError("VERSION file not found.") |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | for l in open(version_file).readlines(): |
---|
| 21 | #exec (l.strip()) |
---|
| 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] |
---|
| 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.") |
---|
| 40 | |
---|
| 41 | |
---|
| 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() |
---|
| 46 | if AUBIO_GIT_SHA: |
---|
| 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() |
---|
| 54 | return (d['AUBIO_MAJOR_VERSION'],d['AUBIO_MINOR_VERSION'],d['AUBIO_PATCH_VERSION']) |
---|
| 55 | |
---|
| 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']) |
---|
| 59 | |
---|
| 60 | def get_libaubio_version(): |
---|
| 61 | return '%s.%s.%s'%get_libaubio_version_tuple() |
---|
| 62 | |
---|
| 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'] |
---|
[aab682e] | 69 | return verstr |
---|
| 70 | |
---|
[255c4c8] | 71 | def get_aubio_pyversion(add_status = True): |
---|
[aab682e] | 72 | # convert to version for python according to pep 440 |
---|
| 73 | # see https://www.python.org/dev/peps/pep-0440/ |
---|
[20a33fb] | 74 | # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''} |
---|
[255c4c8] | 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']: |
---|
[c23d45f] | 79 | verstr += "+a0."+vdict['AUBIO_VERSION_STATUS'][1:] |
---|
[255c4c8] | 80 | elif '~alpha': |
---|
[c23d45f] | 81 | verstr += "+a0" |
---|
[255c4c8] | 82 | else: |
---|
[c23d45f] | 83 | raise SystemError("Aubio version statut not supported : %s"%vdict['AUBIO_VERSION_STATUS']) |
---|
[aab682e] | 84 | return verstr |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | def get_git_revision_hash( short=True): |
---|
| 89 | |
---|
| 90 | if not os.path.isdir('.git'): |
---|
| 91 | # print('Version : not in git repository : can\'t get sha') |
---|
[638be5f] | 92 | return None |
---|
[aab682e] | 93 | |
---|
| 94 | import subprocess |
---|
| 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'] |
---|
| 99 | if short: |
---|
[c23d45f] | 100 | gitcmd.append('--short') |
---|
[aab682e] | 101 | gitcmd.append('HEAD') |
---|
[638be5f] | 102 | try: |
---|
[c23d45f] | 103 | outCmd = subprocess.check_output(gitcmd).strip().decode('utf8') |
---|
[638be5f] | 104 | except Exception as e: |
---|
[c23d45f] | 105 | print ('git command error :%s'%e) |
---|
| 106 | return None |
---|
[aab682e] | 107 | return outCmd |
---|
| 108 | |
---|
| 109 | |
---|