Repository navigation
Expand file tree
/
Copy pathcheck_code_quality.py
More file actions
executable file
·69 lines (56 loc) · 2.01 KB
/
Copy pathcheck_code_quality.py
File metadata and controls
executable file
·69 lines (56 loc) · 2.01 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
#!/usr/bin/env python
"""Check code quality before creating a code request."""
import os
import subprocess
import webbrowser
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 formatter (ruff)."""
print("========================================")
_run_and_print(["ruff", "format", "."])
def run_linter() -> None: # pragma: no cover
"""Run code quality review (ruff)."""
print("========================================")
print("Code Quality Review (ruff)")
_run_and_print(["ruff", "check", "--fix", "src"])
def run_static_type_checker() -> None: # pragma: no cover
"""Run static typing checker (mypy)."""
print("========================================")
print("Checking Static Types (mypy)")
_run_and_print(["mypy", "src"])
def run_unit_tests() -> None: # pragma: no cover
"""Run all unit tests."""
print("========================================")
print("Running Unit Tests (coverage/pytest)")
_run_and_print(
[
"coverage",
"run",
"--source",
"src",
"-m",
"pytest",
]
)
subprocess.call(["coverage", "html", "-d", "reports/coverage"])
webbrowser.open_new_tab(
"file://" + os.path.abspath("reports/coverage/index.html")
)
if __name__ == "__main__": # pragma: no cover
run_style_formatter()
run_linter()
run_static_type_checker()
run_unit_tests()
print("========================================")
print("Completed.")
print("Do not forget to merge main into your")
print("branch and run these checks again.")
print("========================================")