-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpre_push.py
executable file
·60 lines (44 loc) · 1.28 KB
/
pre_push.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
#!/usr/bin/env python3
"""
Pre-push static analysis utility.
Running this script performs all tests and static analysis. This is useful
prior to pushing or submitting a PR.
"""
import sys
from subprocess import CalledProcessError, check_call
def run(program):
"""Runs a program."""
print(f"Running: {' '.join(program)}")
try:
check_call(program, shell=False)
except CalledProcessError:
print(f"Failed to run {program}")
return False
except Exception as e:
sys.stderr.write(f"{str(e)}\n")
sys.exit(1)
return True
def run_linters():
"""Runs all linters."""
success = True
success &= run(["black", "--check", "."])
success &= run(["flake8", "--exclude", "docs", "prsw", "tests"])
success &= run(["pydocstyle", "prsw"])
return success
def run_unit_tests():
"""Runs all unit tests."""
success = True
success &= run(["pytest"])
return success
def main():
success = True
try:
success &= run_unit_tests()
success &= run_linters()
except KeyboardInterrupt:
return int(not success)
return int(not success)
if __name__ == "__main__":
exit_code = main()
print("\npre_push.py: Success!" if not exit_code else "\npre_push.py: Fail")
sys.exit(exit_code)