-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConstruct.py
69 lines (47 loc) · 1.85 KB
/
SConstruct.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
import subprocess
_CHECK_ONLY = 'check' in COMMAND_LINE_TARGETS
_CONTINUE = 'continue' in COMMAND_LINE_TARGETS
_SUBJECT = 'barentsz'
def _exec(cmd: str) -> None:
print(f'>>> {cmd}')
exit_code = subprocess.call(cmd, shell=True)
if exit_code != 0 and not _CONTINUE:
print(f'Exiting with {exit_code}')
Exit(exit_code)
# COMBINATIONS:
if 'all' in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ['format', 'quality']
if 'quality' in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ['test', 'doctest', 'coverage', 'pycodestyle', 'pylint', 'mypy', 'complexity']
if 'format' in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ['autoflake', 'isort']
# QUALITY:
if 'test' in COMMAND_LINE_TARGETS:
_exec('python -m unittest discover tests')
if 'doctest' in COMMAND_LINE_TARGETS:
_exec('python -m doctest README.md')
if 'coverage' in COMMAND_LINE_TARGETS:
_exec('coverage run -m unittest discover tests')
_exec('coverage report -m --fail-under=100')
if 'pycodestyle' in COMMAND_LINE_TARGETS:
_exec(f'pycodestyle {_SUBJECT} -v --config=setup.cfg')
if 'pylint' in COMMAND_LINE_TARGETS:
_exec(f'pylint --rcfile=setup.cfg {_SUBJECT}')
if 'mypy' in COMMAND_LINE_TARGETS:
_exec(f'mypy {_SUBJECT} --show-error-codes --disallow-untyped-defs')
if 'complexity' in COMMAND_LINE_TARGETS:
_exec(f'radon cc {_SUBJECT}')
_exec(f'radon cc {_SUBJECT} -nc --total-average')
_exec(f'xenon {_SUBJECT} --max-absolute B --max-modules A --max-average A')
# FORMAT:
if 'autoflake' in COMMAND_LINE_TARGETS:
cmd = f'autoflake {_SUBJECT}/_here.py --recursive --in-place --remove-unused-variables --expand-star-imports'
if _CHECK_ONLY:
cmd += ' --check'
_exec(cmd)
if 'isort' in COMMAND_LINE_TARGETS:
cmd = f'isort {_SUBJECT} --recursive --quiet'
if _CHECK_ONLY:
cmd += ' --check'
_exec(cmd)
Exit(0)