Debian Codegraph @

buildandrun

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