-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConstruct.py
71 lines (52 loc) · 1.93 KB
/
SConstruct.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
61
62
63
64
65
66
67
68
69
70
71
import os
import subprocess
import sys
from typing import Mapping
from SCons.Script import COMMAND_LINE_TARGETS
_SUBJECT = "aid"
_TEST_SUBJECT = "tests"
# Remember if a target has been found, to warn if not.
_target_found: bool = False
def _exec(command: str, env: Mapping | None = None) -> int:
global _target_found # noqa: PLW0603 yes, global, I know
_target_found = True
print(f">>> {command}")
exit_code = subprocess.call(command, shell=True, env=env)
if exit_code != 0:
print(f"Exiting with {exit_code}")
sys.exit(exit_code)
return exit_code
# Generic targets, which will extend the COMMAND_LINE_TARGETS array.
# Makes sure that generic commands run the tests last, as they are the most likely to fail.
if "all" in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ["fix", "format", "quality"]
if "quality" in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ["lint", "lock", "type", "test", "sec"]
# Individual targets
# Fixing
if "fix" in COMMAND_LINE_TARGETS:
cmd = f"ruff check SConstruct.py {_SUBJECT} {_TEST_SUBJECT} --fix --show-fixes"
_exec(cmd)
# Formatting
if "format" in COMMAND_LINE_TARGETS:
cmd = f"ruff format SConstruct.py {_SUBJECT} {_TEST_SUBJECT}"
_exec(cmd)
# Quality - linting
if "lint" in COMMAND_LINE_TARGETS:
cmd = f"ruff check SConstruct.py {_SUBJECT} {_TEST_SUBJECT}"
_exec(cmd)
# Quality - lock file integrity
if "lock" in COMMAND_LINE_TARGETS:
_exec("poetry check --lock")
# Quality - static type checking
if "type" in COMMAND_LINE_TARGETS:
_exec(f"mypy {_SUBJECT}", env=os.environ)
# Quality - unit tests
if "test" in COMMAND_LINE_TARGETS:
_exec(f"python -m pytest {_TEST_SUBJECT}", env=os.environ)
# Quality - security
if "sec" in COMMAND_LINE_TARGETS:
_exec(f"bandit -r {_SUBJECT} -ll -iii", env=os.environ)
if not _target_found:
print(f"No valid target in {COMMAND_LINE_TARGETS}. Look at SConstruct.py for what is allowed.")
sys.exit(0)