source: Version.py @ 20a33fb

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

comment on format of python version

  • 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    # outputs MAJ.MIN.PATCH+a0{.git<sha> , ''}
52    verstr = get_aubio_version()
53    spl = verstr.split('~')
54    if len(spl)==2:
55        verstr = spl[0] + '+a0.'+spl[1]
56
57    # TODO: add rc, .dev, and .post suffixes, add numbering
58    return verstr
59
60
61
62def get_git_revision_hash( short=True):
63
64    if not os.path.isdir('.git'):
65        # print('Version : not in git repository : can\'t get sha')
66        return None
67
68    import subprocess
69    aubio_dir = os.path.dirname(os.path.abspath(__file__))
70    if not os.path.exists(aubio_dir):
71        raise SystemError("git / root folder not found")
72    gitcmd = ['git','-C',aubio_dir ,'rev-parse']
73    if short:
74      gitcmd.append('--short')
75    gitcmd.append('HEAD')
76    try:
77      outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
78    except Exception as e:
79      print ('git command error :%s'%e)
80      return None
81    return outCmd
82
83
84
85# append sha to version in alpha release
86if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
87    AUBIO_GIT_SHA = get_git_revision_hash()
88    if AUBIO_GIT_SHA:
89        AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
Note: See TracBrowser for help on using the repository browser.