Changeset aab682e for python/lib


Ignore:
Timestamp:
Mar 13, 2017, 7:49:56 PM (8 years ago)
Author:
Martin Hermant <martin.hermant@gmail.com>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
0a2a8dd
Parents:
79ef3b3
Message:

unify version parsing in Version.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/moresetuptools.py

    r79ef3b3 raab682e  
    55from .gen_external import generate_external, header, output_path
    66
    7 def get_aubio_version():
    8     # read from VERSION
    9     this_file_dir = os.path.dirname(os.path.abspath(__file__))
    10     version_file = os.path.join(this_file_dir, '..', '..', 'VERSION')
    11 
    12     if not os.path.isfile(version_file):
    13         raise SystemError("VERSION file not found.")
    14 
    15     for l in open(version_file).readlines():
    16         #exec (l.strip())
    17         if l.startswith('AUBIO_MAJOR_VERSION'):
    18             AUBIO_MAJOR_VERSION = int(l.split('=')[1])
    19         if l.startswith('AUBIO_MINOR_VERSION'):
    20             AUBIO_MINOR_VERSION = int(l.split('=')[1])
    21         if l.startswith('AUBIO_PATCH_VERSION'):
    22             AUBIO_PATCH_VERSION = int(l.split('=')[1])
    23         if l.startswith('AUBIO_VERSION_STATUS'):
    24             AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1]
    25 
    26     if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \
    27             or AUBIO_PATCH_VERSION is None:
    28         raise SystemError("Failed parsing VERSION file.")
    29 
    30     verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION,
    31                                      AUBIO_MINOR_VERSION,
    32                                      AUBIO_PATCH_VERSION]))
    33 
    34    
    35     # append sha to version in alpha release
    36     # MAJ.MIN.PATCH.{~git<sha> , ''}
    37     if '~alpha' in AUBIO_VERSION_STATUS :
    38         AUBIO_GIT_SHA = get_git_revision_hash()
    39         if AUBIO_GIT_SHA:
    40             AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
    41 
    42     if AUBIO_VERSION_STATUS is not None :
    43         verstr += AUBIO_VERSION_STATUS
    44     return verstr
    45 
    46 def get_aubio_pyversion():
    47     # convert to version for python according to pep 440
    48     # see https://www.python.org/dev/peps/pep-0440/
    49     verstr = get_aubio_version()
    50     if '~alpha' in verstr or '~git' in verstr:
    51         verstr = verstr.split('~')[0] + '+a1'
    52         gitsha = get_git_revision_hash(short=True)
    53         if gitsha:
    54             verstr+='.git.'+gitsha
    55     # TODO: add rc, .dev, and .post suffixes, add numbering
    56     return verstr
    57 
    58 
    59 
    60 def get_git_revision_hash( short=True):
    61     def which(program):
    62    
    63         def is_exe(fpath):
    64             return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    65 
    66         fpath, fname = os.path.split(program)
    67         if fpath:
    68             if is_exe(program):
    69                 return program
    70         else:
    71             for path in os.environ["PATH"].split(os.pathsep):
    72                 path = path.strip('"')
    73                 exe_file = os.path.join(path, program)
    74                 if is_exe(exe_file):
    75                     return exe_file
    76 
    77         return None
    78     if not which('git'):
    79         print ('Version : no git found on this system : can\'t get sha')
    80         return ""
    81 
    82     import subprocess
    83     this_file_dir = os.path.dirname(os.path.abspath(__file__))
    84     aubio_dir = os.path.join(this_file_dir, '..', '..')
    85     aubio_dir = os.path.abspath(aubio_dir)
    86     if not os.path.exists(aubio_dir):
    87         raise SystemError("git / root folder not found")
    88     gitcmd = ['git','-C',aubio_dir ,'rev-parse']
    89     if short:
    90       gitcmd.append('--short')
    91     gitcmd.append('HEAD')
    92     return subprocess.check_output(gitcmd).strip()
     7from Version import get_aubio_version
    938
    949# inspired from https://gist.github.com/abergmeier/9488990
Note: See TracChangeset for help on using the changeset viewer.