shithub: aubio

Download patch

ref: 638be5f0c72123a42c999388404b7c7d6a96e8c8
parent: d24b5c7bbdf296f16c3eb01e63cd37ef3d1e7224
author: Martin Hermant <martin.hermant@gmail.com>
date: Mon Mar 13 17:20:38 EDT 2017

Version.py :
* clean comments
* use try catch instead of which

--- a/Version.py
+++ b/Version.py
@@ -1,44 +1,11 @@
 
 import os
-for l in open('VERSION').readlines(): exec (l.strip())
 
-# def get_git_revision_hash( short=True):
-#     import os
-#     def which(program):
-#         def is_exe(fpath):
-#             return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
 
-#         fpath, fname = os.path.split(program)
-#         if fpath:
-#             if is_exe(program):
-#                 return program
-#         else:
-#             for path in os.environ["PATH"].split(os.pathsep):
-#                 path = path.strip('"')
-#                 exe_file = os.path.join(path, program)
-#                 if is_exe(exe_file):
-#                     return exe_file
-#         return None
+for l in open('VERSION').readlines(): exec (l.strip())
 
-#     if not which('git') :
-#         # print('no git found on this system : can\'t get sha')
-#         return ""
-#     if not os.path.isdir('.git'):
-#         # print('Version : not in git repository : can\'t get sha')
-#         return ""
 
-#     import subprocess
-#     aubio_dir = os.path.abspath(os.curdir)
-#     if not os.path.exists(aubio_dir):
-#         raise SystemError("git / root folder not found")
-#     gitcmd = ['git','-C',aubio_dir ,'rev-parse']
-#     if short:
-#       gitcmd.append('--short')
-#     gitcmd.append('HEAD')
-#     outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
-#     return outCmd
 
-
 def get_aubio_version():
     # read from VERSION
     this_file_dir = os.path.dirname(os.path.abspath(__file__))
@@ -84,7 +51,7 @@
     verstr = get_aubio_version()
     spl = verstr.split('~')
     if len(spl)==2:
-        verstr = spl[0] + '+a1.'+spl[1]
+        verstr = spl[0] + '+a0.'+spl[1]
 
     # TODO: add rc, .dev, and .post suffixes, add numbering
     return verstr
@@ -92,30 +59,10 @@
 
 
 def get_git_revision_hash( short=True):
-    def which(program):
-    
-        def is_exe(fpath):
-            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
 
-        fpath, fname = os.path.split(program)
-        if fpath:
-            if is_exe(program):
-                return program
-        else:
-            for path in os.environ["PATH"].split(os.pathsep):
-                path = path.strip('"')
-                exe_file = os.path.join(path, program)
-                if is_exe(exe_file):
-                    return exe_file
-
-        return None
-
-    if not which('git') :
-        # print('no git found on this system : can\'t get sha')
-        return ""
     if not os.path.isdir('.git'):
         # print('Version : not in git repository : can\'t get sha')
-        return ""
+        return None
 
     import subprocess
     aubio_dir = os.path.dirname(os.path.abspath(__file__))
@@ -125,7 +72,11 @@
     if short:
       gitcmd.append('--short')
     gitcmd.append('HEAD')
-    outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
+    try:
+      outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
+    except Exception as e:
+      print ('git command error :%s'%e)
+      return None
     return outCmd
 
 
--