mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
fix(docs_check): make rich import optional for CI
The docs validation workflow runs python docs_check.py with no pip install step, so rich is not available. Wrap the rich import in a try/except ModuleNotFoundError and fall back to plain print() calls so the script works in both environments: - With rich installed: coloured pass/FAIL output - Without rich (CI): plain text pass/FAIL output, same exit codes
This commit is contained in:
+38
-10
@@ -8,13 +8,46 @@ import re
|
||||
import sys
|
||||
from typing import Any, Callable, cast
|
||||
|
||||
from rich.console import Console
|
||||
try:
|
||||
from rich.console import Console as _Console
|
||||
_console = _Console()
|
||||
|
||||
def _print_pass(label: str) -> None:
|
||||
_console.print(f"[bold green]pass[/bold green] {label}")
|
||||
|
||||
def _print_fail(label: str, msgs: list[str]) -> None:
|
||||
_console.print(f"[bold red]FAIL[/bold red] {label}")
|
||||
for m in msgs:
|
||||
_console.print(f"[dim] - {m}[/dim]")
|
||||
|
||||
def _print_summary(failures: list[str]) -> None:
|
||||
_console.print()
|
||||
if failures:
|
||||
_console.print(f"[bold red]FAILED[/bold red] {len(failures)} issue(s) found")
|
||||
else:
|
||||
_console.print("[bold green]All checks passed[/bold green]")
|
||||
|
||||
except ModuleNotFoundError:
|
||||
def _print_pass(label: str) -> None: # type: ignore[misc]
|
||||
print(f"pass {label}")
|
||||
|
||||
def _print_fail(label: str, msgs: list[str]) -> None: # type: ignore[misc]
|
||||
print(f"FAIL {label}")
|
||||
for m in msgs:
|
||||
print(f" - {m}")
|
||||
|
||||
def _print_summary(failures: list[str]) -> None: # type: ignore[misc]
|
||||
print()
|
||||
if failures:
|
||||
print(f"FAILED {len(failures)} issue(s) found")
|
||||
else:
|
||||
print("All checks passed")
|
||||
|
||||
|
||||
DOCS = "docs"
|
||||
ALL_MD: list[str] = glob.glob(f"{DOCS}/**/*.md", recursive=True)
|
||||
|
||||
failures: list[str] = []
|
||||
console = Console()
|
||||
|
||||
|
||||
def check(label: str) -> Callable[[Callable[[], list[str]]], None]:
|
||||
@@ -22,12 +55,10 @@ def check(label: str) -> Callable[[Callable[[], list[str]]], None]:
|
||||
def decorator(fn: Callable[[], list[str]]) -> None:
|
||||
issues = fn()
|
||||
if issues:
|
||||
console.print(f"[bold red]FAIL[/bold red] {label}")
|
||||
for msg in issues:
|
||||
console.print(f"[dim] - {msg}[/dim]")
|
||||
_print_fail(label, issues)
|
||||
failures.extend(issues)
|
||||
else:
|
||||
console.print(f"[bold green]pass[/bold green] {label}")
|
||||
_print_pass(label)
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -165,9 +196,6 @@ def _() -> list[str]:
|
||||
|
||||
|
||||
# ── Summary ───────────────────────────────────────────────────────────────────
|
||||
console.print()
|
||||
_print_summary(failures)
|
||||
if failures:
|
||||
console.print(f"[bold red]FAILED[/bold red] {len(failures)} issue(s) found")
|
||||
sys.exit(1)
|
||||
else:
|
||||
console.print("[bold green]All checks passed[/bold green]")
|
||||
|
||||
Reference in New Issue
Block a user