-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_compliance.py
More file actions
33 lines (28 loc) · 1.15 KB
/
Copy pathcode_compliance.py
File metadata and controls
33 lines (28 loc) · 1.15 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
"""Fail-closed source checks kept at the historical Jules entry path."""
from __future__ import annotations
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent
TARGETS = [ROOT / "CODE", ROOT / "tests"]
RULES = {
"unstable builtin hash": re.compile(r"(?<![\w.])hash\("),
"wall-clock epoch": re.compile(r"\btime\.time\("),
"exception detail leak": re.compile(r"\bstr\(\s*(?:e|exc|error)\s*\)"),
"global logging configuration": re.compile(r"logging\.basicConfig\("),
"simulated transition sleep": re.compile(r"asyncio\.sleep\("),
}
def violations() -> list[str]:
found: list[str] = []
for directory in TARGETS:
for path in sorted(directory.rglob("*.py")):
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
for label, pattern in RULES.items():
if pattern.search(line):
found.append(f"{path.relative_to(ROOT)}:{number}: {label}")
return found
if __name__ == "__main__":
errors = violations()
if errors:
print("\n".join(errors))
raise SystemExit(1)
print("code compliance: passed")