source: this_version.py @ c23d45f

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchsampler
Last change on this file since c23d45f was c23d45f, checked in by Martin Hermant <martin.hermant@gmail.com>, 2 years ago

fix non conform Indentations

  • Property mode set to 100644
File size: 3.7 KB
Line 
1
2import os
3
4
5__version_info = {}
6
7def get_version_info():
8    # read from VERSION
9    # return dictionary filled with content of version
10
11    global __version_info
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
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
48
49    return __version_info
50
51
52def get_aubio_version_tuple():
53    d = get_version_info()
54    return (d['AUBIO_MAJOR_VERSION'],d['AUBIO_MINOR_VERSION'],d['AUBIO_PATCH_VERSION'])
55
56def get_libaubio_version_tuple():
57    d = get_version_info()
58    return (d['LIBAUBIO_LT_CUR'],d['LIBAUBIO_LT_REV'],d['LIBAUBIO_LT_AGE'])
59
60def get_libaubio_version():
61    return '%s.%s.%s'%get_libaubio_version_tuple()
62
63def 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']
69    return verstr
70
71def get_aubio_pyversion(add_status = True):
72    # convert to version for python according to pep 440
73    # see https://www.python.org/dev/peps/pep-0440/
74    # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''}
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']:
79          verstr += "+a0."+vdict['AUBIO_VERSION_STATUS'][1:]
80      elif '~alpha':
81          verstr += "+a0"
82      else:
83          raise SystemError("Aubio version statut not supported : %s"%vdict['AUBIO_VERSION_STATUS'])
84    return verstr
85
86
87
88def 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')
92        return None
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:
100        gitcmd.append('--short')
101    gitcmd.append('HEAD')
102    try:
103        outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
104    except Exception as e:
105        print ('git command error :%s'%e)
106        return None
107    return outCmd
108
109
Note: See TracBrowser for help on using the repository browser.