Skip to content

Commit 7ca3631

Browse files
committed
Add code check
1 parent f4a6a18 commit 7ca3631

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

code_check.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import subprocess
5+
6+
import colorama
7+
8+
parser = argparse.ArgumentParser(description="Code checks")
9+
parser.add_argument("--debug", action="store_true")
10+
args = parser.parse_args()
11+
12+
DEBUG = args.debug
13+
14+
15+
def cmd(line):
16+
if DEBUG:
17+
print(colorama.Style.DIM + "% " + line + colorama.Style.RESET_ALL)
18+
try:
19+
output = subprocess.check_output(line, shell=True).decode("utf-8")
20+
if DEBUG:
21+
print(colorama.Style.DIM + output + colorama.Style.RESET_ALL)
22+
return output
23+
except subprocess.CalledProcessError as e:
24+
print(colorama.Fore.RED + e.stdout.decode("utf-8") + colorama.Style.RESET_ALL)
25+
exit(1)
26+
27+
28+
def status(line):
29+
print(colorama.Fore.GREEN + f">>> {line}..." + colorama.Style.RESET_ALL)
30+
31+
32+
if __name__ == "__main__":
33+
colorama.init()
34+
35+
status("Make any missing migrations")
36+
cmd("python manage.py makemigrations")
37+
38+
status("Running black")
39+
cmd("black smartmin test_runner")
40+
41+
status("Running ruff")
42+
cmd("ruff smartmin")
43+
44+
status("Running isort")
45+
cmd("isort smartmin")
46+
47+
# if any code changes were made, exit with error
48+
if cmd("git diff smartmin test_runner"):
49+
print("👎 " + colorama.Fore.RED + "Changes to be committed")
50+
exit(1)
51+
else:
52+
print("👍 " + colorama.Fore.GREEN + "Code looks good. Make that PR!")

0 commit comments

Comments
 (0)