Repository navigation
Expand file tree
/
Copy pathcheck_code_quality.py
More file actions
executable file
·73 lines (59 loc) · 2.07 KB
/
Copy pathcheck_code_quality.py
File metadata and controls
executable file
·73 lines (59 loc) · 2.07 KB
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
#!/usr/bin/env python
"""
Check code quality before creating a code request.
You must install gdtoolkit beforehand:
pip install gdtoolkit
"""
import subprocess
import json
def _run_and_print(command: list[str]) -> None:
"""Run command and print the result in console."""
try:
output = subprocess.check_output(command).decode()
print(output)
except subprocess.CalledProcessError as e:
error_output: str = (e.output or b"").decode()
for line in error_output.split("\n"):
print(line)
def run_style_formatter() -> None: # pragma: no cover
"""Run style formatter (gdformat)."""
print("========================================")
print("Running gdformat...")
_run_and_print(["gdformat", "src"])
def run_linter() -> None: # pragma: no cover
"""Run code quality review (gdlint)."""
print("========================================")
print("Code Quality Review (gdlint)")
_run_and_print(["gdlint", "src"])
def run_tests() -> None: # pragma: no cover
"""Run unit tests (GUT)."""
print("========================================")
print("Running unit tests (GUT)")
print(" If a file dialog window opens, select your Godot executable.")
print(" Now running the tests...")
_run_and_print(["python", "dev_config.py"])
with open("dev_config.json", "r") as fid:
dev_config = json.load(fid)
_run_and_print(
[
dev_config["godot_executable"],
"-d",
"-s",
# "--headless",
"--path",
"./src",
"addons/gut/gut_cmdln.gd",
"-gdir",
"tests",
"-gexit_on_success",
]
)
if __name__ == "__main__": # pragma: no cover
run_style_formatter()
run_linter()
run_tests()
print("========================================")
print("Completed.")
print("Do not forget to merge main into your")
print("branch and run these checks again.")
print("========================================")