forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 11
/
code_check.py
executable file
·52 lines (37 loc) · 1.31 KB
/
code_check.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
#!/usr/bin/env python3
import argparse
import subprocess
import colorama
parser = argparse.ArgumentParser(description="Code checks")
parser.add_argument("--debug", action="store_true")
args = parser.parse_args()
DEBUG = args.debug
def cmd(line):
if DEBUG:
print(colorama.Style.DIM + "% " + line + colorama.Style.RESET_ALL)
try:
output = subprocess.check_output(line, shell=True).decode("utf-8")
if DEBUG:
print(colorama.Style.DIM + output + colorama.Style.RESET_ALL)
return output
except subprocess.CalledProcessError as e:
print(colorama.Fore.RED + e.stdout.decode("utf-8") + colorama.Style.RESET_ALL)
exit(1)
def status(line):
print(colorama.Fore.GREEN + f">>> {line}..." + colorama.Style.RESET_ALL)
if __name__ == "__main__":
colorama.init()
status("Make any missing migrations")
cmd("python manage.py makemigrations")
status("Running isort")
cmd("isort temba")
status("Running black")
cmd("black temba")
status("Running ruff")
cmd("ruff temba")
# if any code changes were made, exit with error
if cmd("git diff temba locale"):
print("👎 " + colorama.Fore.RED + "Changes to be committed")
exit(1)
else:
print("👍 " + colorama.Fore.GREEN + "Code looks good. Make that PR!")