Reject oncology, cancer, drug, and target imports in the UI.
CONTENT-WP-0002-T07 checks every import statement and the navigation labels of both fixtures. Assistant: grok Assistant-Session: 01a1346c-fdff-7741-b1af-b7283661554b
This commit is contained in:
parent
08a9a787a7
commit
f434773fd0
4 changed files with 116 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Reject oncology vocabulary on UI import lines, and require the MIT notice."""
|
||||
"""Reject oncology, cancer, drug, and target imports in the generic UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
@ -9,33 +9,51 @@ from pathlib import Path
|
|||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
UI = ROOT / "ui"
|
||||
IMPORT_LINE = re.compile(r"""^\s*(import|export)\b.*\bfrom\b|^\s*import\s*\(""")
|
||||
FORBIDDEN = re.compile(r"oncology|cancers?|drugs?|targets?", re.IGNORECASE)
|
||||
SOURCE_SUFFIXES = {".ts", ".tsx", ".css", ".mjs"}
|
||||
IMPORT_STATEMENT = re.compile(
|
||||
r"""(?:^|\n)\s*import\b[\s\S]*?\bfrom\s+['"][^'"]+['"]"""
|
||||
r"""|(?:^|\n)\s*import\s+['"][^'"]+['"]"""
|
||||
r"""|import\s*\(\s*['"][^'"]+['"]\s*\)"""
|
||||
r"""|require\s*\(\s*['"][^'"]+['"]\s*\)"""
|
||||
r"""|@import\s+['"][^'"]+['"]""",
|
||||
)
|
||||
# The token may start an identifier such as CancerIcon or targetThumb.
|
||||
FORBIDDEN = re.compile(r"\b(?:oncology|cancers?|drugs?|targets?)", re.IGNORECASE)
|
||||
|
||||
|
||||
def import_lines(path: Path) -> list[str]:
|
||||
hits: list[str] = []
|
||||
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
|
||||
if IMPORT_LINE.search(line) and FORBIDDEN.search(line):
|
||||
hits.append(f"{path.relative_to(ROOT)}:{number}: {line.strip()}")
|
||||
return hits
|
||||
def import_problems(text: str, label: str) -> list[str]:
|
||||
problems: list[str] = []
|
||||
for match in IMPORT_STATEMENT.finditer(text):
|
||||
statement = " ".join(match.group(0).split())
|
||||
if FORBIDDEN.search(statement):
|
||||
problems.append(f"{label}: {statement}")
|
||||
return problems
|
||||
|
||||
|
||||
def tree_problems(root: Path = UI) -> list[str]:
|
||||
problems: list[str] = []
|
||||
for path in sorted(root.rglob("*")):
|
||||
if not path.is_file() or "node_modules" in path.parts or ".next" in path.parts:
|
||||
continue
|
||||
if path.suffix not in SOURCE_SUFFIXES:
|
||||
continue
|
||||
problems.extend(import_problems(path.read_text(encoding="utf-8"), str(path.relative_to(ROOT))))
|
||||
notice = root / "NOTICE"
|
||||
if not notice.is_file():
|
||||
problems.append("ui/NOTICE is missing")
|
||||
else:
|
||||
text = notice.read_text(encoding="utf-8")
|
||||
if "Copyright (c) 2026 OnCo" not in text or "MIT License" not in text:
|
||||
problems.append("ui/NOTICE is missing the OnCo MIT copyright and permission notice")
|
||||
return problems
|
||||
|
||||
|
||||
def main() -> int:
|
||||
problems: list[str] = []
|
||||
for path in sorted(UI.rglob("*")):
|
||||
if not path.is_file() or "node_modules" in path.parts or ".next" in path.parts:
|
||||
continue
|
||||
if path.suffix in SOURCE_SUFFIXES:
|
||||
problems.extend(import_lines(path))
|
||||
notice = (UI / "NOTICE").read_text(encoding="utf-8")
|
||||
if "Copyright (c) 2026 OnCo" not in notice or "MIT License" not in notice:
|
||||
problems.append("ui/NOTICE is missing the OnCo MIT copyright and permission notice")
|
||||
problems = tree_problems()
|
||||
if problems:
|
||||
print("\n".join(problems))
|
||||
return 1
|
||||
print("ui boundary: no oncology imports; NOTICE retains the OnCo MIT text")
|
||||
print("ui boundary: no oncology, cancer, drug, or target imports; NOTICE retains the OnCo MIT text")
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue