-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·134 lines (100 loc) · 3.65 KB
/
run
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
import argparse
import glob
import os
import subprocess
import sys
import webbrowser
verbose = False
def call(cmd, verbose):
if verbose:
print(' '.join(cmd))
ret = subprocess.call(cmd)
if ret != 0:
sys.exit(ret)
def main(argv):
parser = argparse.ArgumentParser(prog='run')
parser.add_argument('-v', '--verbose', action='store_true')
subps = parser.add_subparsers()
subp = subps.add_parser('build', help='build the package')
subp.set_defaults(func=run_build)
subp = subps.add_parser('clean', help='Remove any local files.')
subp.set_defaults(func=run_clean)
subp = subps.add_parser('coverage',
help='Run tests and report code coverage.')
subp.add_argument('--html', action='store_true',
help='Generate an HTML report after running '
'and open it in a browser window')
subp.set_defaults(func=run_coverage)
subp = subps.add_parser('help',
help='Get help on a subcommand.')
subp.add_argument(nargs='?', action='store', dest='subcommand',
help='The command to get help for.')
subp.set_defaults(func=run_help)
subp = subps.add_parser('lint',
help='run lint over the source')
subp.set_defaults(func=run_lint)
subp = subps.add_parser('regen',
help='regenerate parser code')
subp.set_defaults(func=run_regen)
subp = subps.add_parser('tests',
help='run the tests')
subp.set_defaults(func=run_tests)
subp = subps.add_parser('install',
help='build the package and install locally.')
subp.set_defaults(func=run_install)
subp.add_argument('--system', action='store_true',
help=('Install to the system site-package dir '
'rather than the user\'s (requires root).'))
args = parser.parse_args(argv)
args.func(args)
def run_build(args):
call([sys.executable, '-m', 'build'], args.verbose)
def run_clean(args):
call(['git', 'clean', '-fxd'], args.verbose)
def run_coverage(args):
call([sys.executable,
'-m', 'coverage',
'run',
'--omit=*/_distutils_hack/*',
'-m', 'unittest',
'discover', '-p', '*_test.py'],
args.verbose)
call([sys.executable, '-m', 'coverage', 'report', '--show-missing'],
args.verbose)
if args.html:
call([sys.executable, '-m', 'coverage', 'html'],
args.verbose)
page = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'htmlcov', 'index.html')
print(page)
webbrowser.open('file://' + page)
def run_help(args):
if args.subcommand:
main([args.subcommand, '--help'])
main(['--help'])
def run_install(args):
if args.system:
argv = []
else:
argv = ['--user']
call(['sys.executable', 'setup.py', 'install'] + argv,
args.verbose)
def run_lint(args):
files = glob.glob('json5/*.py') + glob.glob('tests/*.py')
call([sys.executable,
'-m' 'pylint',
'--rcfile=pylintrc'] + files,
args.verbose)
def run_regen(args):
call([sys.executable, '-m', 'glop', '-o', 'new_parser.py',
'-c', 'grammars/glop.g'], args.verbose)
os.rename('new_parser.py', 'glop/parser.py')
def run_tests(args):
cmd = [sys.executable, '-m', 'unittest', 'discover',
'-p', '*_test.py']
if args.verbose:
cmd += ['--verbose']
call(cmd, args.verbose)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))