Changeset aab682e


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

unify version parsing in Version.py

Files:
1 added
3 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
  • setup.py

    r79ef3b3 raab682e  
    66# function to generate gen/*.{c,h}
    77from python.lib.gen_external import generate_external, header, output_path
     8from Version import get_aubio_version, get_aubio_pyversion
    89
    910__version__ = get_aubio_version()
  • wscript

    r79ef3b3 raab682e  
    1616
    1717# source VERSION
    18 for l in open('VERSION').readlines(): exec (l.strip())
    19 
    20 def get_git_revision_hash( short=True):
    21     import os
    22     def which(program):
    23         def is_exe(fpath):
    24             return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    25 
    26         fpath, fname = os.path.split(program)
    27         if fpath:
    28             if is_exe(program):
    29                 return program
    30         else:
    31             for path in os.environ["PATH"].split(os.pathsep):
    32                 path = path.strip('"')
    33                 exe_file = os.path.join(path, program)
    34                 if is_exe(exe_file):
    35                     return exe_file
    36         return None
    37 
    38     if not which('git'):
    39         print('no git found on this system : can\'t get sha')
    40         return ""
    41 
    42     import subprocess
    43     aubio_dir = os.path.abspath(os.curdir)
    44     if not os.path.exists(aubio_dir):
    45         raise SystemError("git / root folder not found")
    46     gitcmd = ['git','-C',aubio_dir ,'rev-parse']
    47     if short:
    48       gitcmd.append('--short')
    49     gitcmd.append('HEAD')
    50     return str(subprocess.check_output(gitcmd).strip())
    51 
    52 
    53 # append sha to version in alpha release
    54 if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
    55     AUBIO_GIT_SHA = get_git_revision_hash()
    56     if AUBIO_GIT_SHA:
    57         AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
    58 
    59 
     18
     19
     20from Version import *
    6021
    6122
     
    179140    ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)
    180141    ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)
    181     # ctx.define('AUBIO_GIT_SHA',AUBIO_GIT_SHA)
     142   
    182143    if ctx.options.build_type == "debug":
    183144        ctx.define('DEBUG', 1)
Note: See TracChangeset for help on using the changeset viewer.