-
Notifications
You must be signed in to change notification settings - Fork 37
/
buildandrun
executable file
·88 lines (70 loc) · 2.5 KB
/
buildandrun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import logging
import os
import os.path
import shutil
import subprocess
import sys
from optparse import OptionParser
if os.getenv('DEBUG'):
logging.basicConfig(level=logging.DEBUG)
def recursiverm(d):
for root, dirs, files in os.walk(d):
for f in files:
f = root + os.path.sep + f
logging.debug('Removing file: %s' % f)
os.unlink(f)
def main():
op = OptionParser()
op.add_option('-c', '--clean', dest='clean', action='store_true',
help='Remove the contents of the build directory')
opts, args = op.parse_args()
if not args:
print('Specify a test script')
sys.exit(1)
if opts.clean:
logging.debug('Removing build/')
recursiverm('build')
logging.debug('Building Cheetah')
rc = subprocess.call((sys.executable, 'setup.py', 'build'))
if rc:
logging.debug('Build failed!')
sys.exit(rc)
logging.debug('Adjusting PATH and PYTHONPATH')
cwd = os.getcwd()
libdir = None
scriptdir = None
py_ver = '-' + '.'.join([str(v) for v in sys.version_info[:2]])
for sub in os.listdir('build'):
if not sub.endswith(py_ver):
continue
if sub.startswith('scripts'):
scriptdir = os.path.sep.join((cwd, 'build', sub))
if sub.startswith('lib'):
libdir = os.path.sep.join((cwd, 'build', sub))
# Copy test templates to the ``build/lib`` directory
tmpldir = os.path.join('Cheetah', 'Tests', 'ImportHooksTemplates')
libtmpldir = os.path.join(libdir, tmpldir)
if not os.path.exists(os.path.join(libtmpldir, 'index.tmpl')):
if os.path.exists(libtmpldir):
shutil.rmtree(libtmpldir)
shutil.copytree(tmpldir, libtmpldir)
newpath = '%s:%s' % (scriptdir, os.getenv('PATH'))
logging.debug('Setting PATH to: %s' % newpath)
os.putenv('PATH', newpath)
logging.debug('Setting PYTHONPATH to: %s' % libdir)
os.putenv('PYTHONPATH', libdir)
script = args[0]
if os.access(script, os.X_OK):
rc = subprocess.call([sys.executable] + args)
else:
script = os.path.splitext(script)[0]
module = script.replace(os.sep, '.')
args[0] = module
os.chdir(libdir) # To avoid importing ``Cheetah`` from the current dir
rc = subprocess.call([sys.executable, '-m', 'unittest'] + args)
if rc == -11:
logging.error('Segmentation fault in test process. Test failed.')
sys.exit(rc)
if __name__ == '__main__':
main()