History

unify version parsing in Version.py

Martin Hermant committed 9 years ago

Commit aab682e1 parent 79ef3b34 files · +141 −127Browse files

Unified · Split

4 files
  1. Version.py +137 −0
  2. python/lib/moresetuptools.py +1 −86
  3. setup.py +1 −0
  4. wscript +2 −41
Version.py+137−0
@@ -0,0 +1,137 @@
1
2import os
3for l in open('VERSION').readlines(): exec (l.strip())
4
5# def get_git_revision_hash( short=True):
6# import os
7# def which(program):
8# def is_exe(fpath):
9# return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
10
11# fpath, fname = os.path.split(program)
12# if fpath:
13# if is_exe(program):
14# return program
15# else:
16# for path in os.environ["PATH"].split(os.pathsep):
17# path = path.strip('"')
18# exe_file = os.path.join(path, program)
19# if is_exe(exe_file):
20# return exe_file
21# return None
22
23# if not which('git') :
24# # print('no git found on this system : can\'t get sha')
25# return ""
26# if not os.path.isdir('.git'):
27# # print('Version : not in git repository : can\'t get sha')
28# return ""
29
30# import subprocess
31# aubio_dir = os.path.abspath(os.curdir)
32# if not os.path.exists(aubio_dir):
33# raise SystemError("git / root folder not found")
34# gitcmd = ['git','-C',aubio_dir ,'rev-parse']
35# if short:
36# gitcmd.append('--short')
37# gitcmd.append('HEAD')
38# outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
39# return outCmd
40
41
42def get_aubio_version():
43 # read from VERSION
44 this_file_dir = os.path.dirname(os.path.abspath(__file__))
45 version_file = os.path.join(this_file_dir, 'VERSION')
46
47 if not os.path.isfile(version_file):
48 raise SystemError("VERSION file not found.")
49
50 for l in open(version_file).readlines():
51 #exec (l.strip())
52 if l.startswith('AUBIO_MAJOR_VERSION'):
53 AUBIO_MAJOR_VERSION = int(l.split('=')[1])
54 if l.startswith('AUBIO_MINOR_VERSION'):
55 AUBIO_MINOR_VERSION = int(l.split('=')[1])
56 if l.startswith('AUBIO_PATCH_VERSION'):
57 AUBIO_PATCH_VERSION = int(l.split('=')[1])
58 if l.startswith('AUBIO_VERSION_STATUS'):
59 AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1]
60
61 if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \
62 or AUBIO_PATCH_VERSION is None:
63 raise SystemError("Failed parsing VERSION file.")
64
65 verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION,
66 AUBIO_MINOR_VERSION,
67 AUBIO_PATCH_VERSION]))
68
69
70 # append sha to version in alpha release
71 # MAJ.MIN.PATCH.{~git<sha> , ''}
72 if '~alpha' in AUBIO_VERSION_STATUS :
73 AUBIO_GIT_SHA = get_git_revision_hash()
74 if AUBIO_GIT_SHA:
75 AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
76
77 if AUBIO_VERSION_STATUS is not None :
78 verstr += AUBIO_VERSION_STATUS
79 return verstr
80
81def get_aubio_pyversion():
82 # convert to version for python according to pep 440
83 # see https://www.python.org/dev/peps/pep-0440/
84 verstr = get_aubio_version()
85 spl = verstr.split('~')
86 if len(spl)==2:
87 verstr = spl[0] + '+a1.'+spl[1]
88
89 # TODO: add rc, .dev, and .post suffixes, add numbering
90 return verstr
91
92
93
94def get_git_revision_hash( short=True):
95 def which(program):
96
97 def is_exe(fpath):
98 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
99
100 fpath, fname = os.path.split(program)
101 if fpath:
102 if is_exe(program):
103 return program
104 else:
105 for path in os.environ["PATH"].split(os.pathsep):
106 path = path.strip('"')
107 exe_file = os.path.join(path, program)
108 if is_exe(exe_file):
109 return exe_file
110
111 return None
112
113 if not which('git') :
114 # print('no git found on this system : can\'t get sha')
115 return ""
116 if not os.path.isdir('.git'):
117 # print('Version : not in git repository : can\'t get sha')
118 return ""
119
120 import subprocess
121 aubio_dir = os.path.dirname(os.path.abspath(__file__))
122 if not os.path.exists(aubio_dir):
123 raise SystemError("git / root folder not found")
124 gitcmd = ['git','-C',aubio_dir ,'rev-parse']
125 if short:
126 gitcmd.append('--short')
127 gitcmd.append('HEAD')
128 outCmd = subprocess.check_output(gitcmd).strip().decode('utf8')
129 return outCmd
130
131
132
133# append sha to version in alpha release
134if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
135 AUBIO_GIT_SHA = get_git_revision_hash()
136 if AUBIO_GIT_SHA:
137 AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
python/lib/moresetuptools.py+1−86
@@ -4,92 +4,7 @@ import sys, os, glob, subprocess · 3 unmodified lines
4import distutils, distutils.command.clean, distutils.dir_util4import distutils, distutils.command.clean, distutils.dir_util
5from .gen_external import generate_external, header, output_path5from .gen_external import generate_external, header, output_path
6 6
7def get_aubio_version():7from Version import 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
46def 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
60def 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()
93 8
94# inspired from https://gist.github.com/abergmeier/94889909# inspired from https://gist.github.com/abergmeier/9488990
95def add_packages(packages, ext=None, **kw):10def add_packages(packages, ext=None, **kw):
setup.py+1−0
@@ -5,6 +5,7 @@ from setuptools import setup, Extension · 4 unmodified lines
5from python.lib.moresetuptools import *5from python.lib.moresetuptools import *
6# function to generate gen/*.{c,h}6# function to generate gen/*.{c,h}
7from python.lib.gen_external import generate_external, header, output_path7from python.lib.gen_external import generate_external, header, output_path
8from Version import get_aubio_version, get_aubio_pyversion
8 9
9__version__ = get_aubio_version()10__version__ = get_aubio_version()
10__pip_version__ = get_aubio_pyversion()11__pip_version__ = get_aubio_pyversion()
wscript+2−41
@@ -15,48 +15,9 @@ import sys · 14 unmodified lines
15APPNAME = 'aubio'15APPNAME = 'aubio'
16 16
17# source VERSION17# source VERSION
18for l in open('VERSION').readlines(): exec (l.strip())
19
20def 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
54if 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 18
59 19
20from Version import *
60 21
61 22
62VERSION = '.'.join ([str(x) for x in [23VERSION = '.'.join ([str(x) for x in [
@@ -178,7 +139,7 @@ def configure(ctx): · 115 unmodified lines
178 ctx.define('AUBIO_MINOR_VERSION',AUBIO_MINOR_VERSION)139 ctx.define('AUBIO_MINOR_VERSION',AUBIO_MINOR_VERSION)
179 ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)140 ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)
180 ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)141 ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)
181 # ctx.define('AUBIO_GIT_SHA',AUBIO_GIT_SHA)142
182 if ctx.options.build_type == "debug":143 if ctx.options.build_type == "debug":
183 ctx.define('DEBUG', 1)144 ctx.define('DEBUG', 1)
184 else:145 else:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t