source: Version.py @ 638be5f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since 638be5f was 638be5f, checked in by Martin Hermant <martin.hermant@gmail.com>, 7 years ago

Version.py :

  • clean comments
  • use try catch instead of which
  • Property mode set to 100644
File size: 2.7 KB
Line 
1
2import os
3
4
5for l in open('VERSION').readlines(): exec (l.strip())
6
7
8
9def get_aubio_version():
10    # read from VERSION
11    this_file_dir = os.path.dirname(os.path.abspath(__file__))
12    version_file = os.path.join(this_file_dir,  'VERSION')
13
14    if not os.path.isfile(version_file):
15        raise SystemError("VERSION file not found.")
16
17    for l in open(version_file).readlines():
18        #exec (l.strip())
19        if l.startswith('AUBIO_MAJOR_VERSION'):
20            AUBIO_MAJOR_VERSION = int(l.split('=')[1])
21        if l.startswith('AUBIO_MINOR_VERSION'):
22            AUBIO_MINOR_VERSION = int(l.split('=')[1])
23        if l.startswith('AUBIO_PATCH_VERSION'):
24            AUBIO_PATCH_VERSION = int(l.split('=')[1])
25        if l.startswith('AUBIO_VERSION_STATUS'):
26            AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1]
27
28    if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \
29            or AUBIO_PATCH_VERSION is None:
30        raise SystemError("Failed parsing VERSION file.")
31
32    verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION,
33                                     AUBIO_MINOR_VERSION,
34                                     AUBIO_PATCH_VERSION]))
35
36   
37    # append sha to version in alpha release
38    # MAJ.MIN.PATCH.{~git<sha> , ''}
39    if '~alpha' in AUBIO_VERSION_STATUS :
40        AUBIO_GIT_SHA = get_git_revision_hash()
41        if AUBIO_GIT_SHA:
42            AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
43
44    if AUBIO_VERSION_STATUS is not None :
45        verstr += AUBIO_VERSION_STATUS
46    return verstr
47
48def get_aubio_pyversion():
49    # convert to version for python according to pep 440
50    # see https://www.python.org/dev/peps/pep-0440/
51    verstr = get_aubio_version()
52    spl = verstr.split('~')
53    if len(spl)==2:
54        verstr = spl[0] + '+a0.'+spl[1]
55
56    # TODO: add rc, .dev, and .post suffixes, add numbering
57    return verstr
58
59
60
61def get_git_revision_hash( short=True):
62
63    if not os.path.isdir('.git'):
64        # print('Version : not in git repository : can\'t get sha')
65        return None
66
67    import subprocess
68    aubio_dir = os.path.dirname(os.path.abspath(__file__))
69    if not os.path.exists(aubio_dir):
70        raise SystemError("git / root folder not found")
71    gitcmd = ['git','-C',aubio_dir ,'rev-parse']
72    if short:
73      gitcmd.append('--short')
74    gitcmd.append('HEAD')
75    try:
76      outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
77    except Exception as e:
78      print ('git command error :%s'%e)
79      return None
80    return outCmd
81
82
83
84# append sha to version in alpha release
85if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
86    AUBIO_GIT_SHA = get_git_revision_hash()
87    if AUBIO_GIT_SHA:
88        AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
Note: See TracBrowser for help on using the repository browser.