source: this_version.py @ f7b7a35

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since f7b7a35 was f7b7a35, checked in by Paul Brossier <piem@piem.org>, 7 years ago

this_version.py: add +mods if git tree is not clean

  • Property mode set to 100644
File size: 4.1 KB
Line 
1
2import os
3
4
5__version_info = {}
6
7
8def get_version_info():
9    # read from VERSION
10    # return dictionary filled with content of version
11
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')
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
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.")
40
41        # switch version status with commit sha in alpha releases
42        if __version_info['AUBIO_VERSION_STATUS'] and \
43                '~alpha' in __version_info['AUBIO_VERSION_STATUS']:
44            AUBIO_GIT_SHA = get_git_revision_hash()
45            if AUBIO_GIT_SHA:
46                __version_info['AUBIO_VERSION_STATUS'] = '~git+' + AUBIO_GIT_SHA
47
48    return __version_info
49
50
51def get_aubio_version_tuple():
52    d = get_version_info()
53    return (d['AUBIO_MAJOR_VERSION'],
54            d['AUBIO_MINOR_VERSION'],
55            d['AUBIO_PATCH_VERSION'])
56
57
58def get_libaubio_version_tuple():
59    d = get_version_info()
60    return (d['LIBAUBIO_LT_CUR'], d['LIBAUBIO_LT_REV'], d['LIBAUBIO_LT_AGE'])
61
62
63def get_libaubio_version():
64    return '%s.%s.%s' % get_libaubio_version_tuple()
65
66
67def get_aubio_version(add_status=True):
68    # return string formatted as MAJ.MIN.PATCH{~git<sha> , ''}
69    vdict = get_version_info()
70    verstr = '%s.%s.%s' % get_aubio_version_tuple()
71    if add_status and vdict['AUBIO_VERSION_STATUS']:
72        verstr += vdict['AUBIO_VERSION_STATUS']
73    return str(verstr)
74
75
76def get_aubio_pyversion(add_status=True):
77    # convert to version for python according to pep 440
78    # see https://www.python.org/dev/peps/pep-0440/
79    # outputs MAJ.MIN.PATCH[a0[+git.<sha>[.mods]]]
80    vdict = get_version_info()
81    verstr = '%s.%s.%s' % get_aubio_version_tuple()
82    if add_status and vdict['AUBIO_VERSION_STATUS']:
83        if vdict['AUBIO_VERSION_STATUS'].startswith('~git+'):
84            pep440str = vdict['AUBIO_VERSION_STATUS'].replace('+', '.')
85            verstr += pep440str.replace('~git.', 'a0+')
86        elif '~alpha' in vdict['AUBIO_VERSION_STATUS']:
87            verstr += "a0"
88        else:
89            raise SystemError("Aubio version statut not supported : %s" %
90                              vdict['AUBIO_VERSION_STATUS'])
91    return verstr
92
93
94def get_git_revision_hash(short=True):
95
96    if not os.path.isdir('.git'):
97        # print('Version : not in git repository : can\'t get sha')
98        return None
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")
104    gitcmd = ['git', '-C', aubio_dir, 'rev-parse']
105    if short:
106        gitcmd.append('--short')
107    gitcmd.append('HEAD')
108    try:
109        gitsha = subprocess.check_output(gitcmd).strip().decode('utf8')
110    except Exception as e:
111        print('git command error :%s' % e)
112        return None
113
114    # check if we have a clean tree
115    gitcmd = ['git', '-C', aubio_dir, 'diff-index', '--quiet']
116    gitcmd.append('HEAD')
117    try:
118        subprocess.check_output(gitcmd).strip().decode('utf8')
119    except Exception as e:
120        gitsha += '+mods'
121    return gitsha
Note: See TracBrowser for help on using the repository browser.