forked from TUNE-Archive/customs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
89 lines (68 loc) · 2.08 KB
/
build.py
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
89
#!/usr/bin/env python
from __future__ import unicode_literals
from subprocess import call
import os
import sys
import argparse
from nose.core import run
def lint():
"""
run linter on our code base.
"""
path = os.path.realpath(os.getcwd())
cmd = 'flake8 %s' % path
opt = ''
print(">>> Linting codebase with the following command: %s %s" % (cmd, opt))
try:
return_code = call([cmd, opt], shell=True)
if return_code < 0:
print >> sys.stderr, ">>> Terminated by signal", -return_code
elif return_code != 0:
sys.exit('>>> Lint checks failed')
else:
print >> sys.stderr, ">>> Lint checks passed", return_code
except OSError as e:
print >> sys.stderr, ">>> Execution failed:", e
def unit_test(extra_args=[]):
"""
run unit tests for this code base. Pass any arguments that nose accepts.
"""
path = os.path.realpath(os.path.join(os.getcwd(), 'tests/unit'))
args = [
path, '-x', '-v', '--with-coverage', '--cover-erase',
'--cover-package=./build/lib/freight_forwarder',
'--cover-package=./freight_forwarder'
]
if extra_args:
args.extend(extra_args)
if run(argv=args):
return 0
else:
return 1
def test_suite():
"""
run both unit test and lint with default args
Need to come back to add flags to allow multiple arugments to each
unit_test and lint
"""
lint()
unit_test()
def main():
"""
need to add http://sphinx-doc.org/
"""
parser = argparse.ArgumentParser()
sub_parser = parser.add_subparsers()
lint_parser = sub_parser.add_parser('lint')
lint_parser.set_defaults(func=lint)
unit_test_parser = sub_parser.add_parser('unit-test')
unit_test_parser.set_defaults(func=unit_test)
test_suite_parser = sub_parser.add_parser('test-suite')
test_suite_parser.set_defaults(func=test_suite)
args, extra_args = parser.parse_known_args()
if extra_args:
args.func(extra_args)
else:
args.func()
if __name__ == '__main__':
main()