75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
DOC_SUFFIXES = {".md", ".pdf", ".ppt", ".pptx", ".txt", ".rst"}
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description="Check FemLite example folder layout.")
|
|
parser.add_argument("repo_root")
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> int:
|
|
args = parse_args()
|
|
repo_root = Path(args.repo_root).resolve()
|
|
examples_dir = repo_root / "examples"
|
|
violations: list[str] = []
|
|
|
|
if not examples_dir.exists():
|
|
print(f"examples directory does not exist: {examples_dir}")
|
|
return 1
|
|
|
|
for folder in sorted(path for path in examples_dir.iterdir() if path.is_dir()):
|
|
files = [path for path in folder.iterdir() if path.is_file()]
|
|
inputs = sorted(path.name for path in files if path.suffix.lower() == ".inp")
|
|
docs = sorted(path.name for path in files if path.suffix.lower() in DOC_SUFFIXES)
|
|
run_case = folder / "run_case.bat"
|
|
|
|
if docs and not inputs:
|
|
violations.append(
|
|
f"{folder.relative_to(repo_root)} has documentation but no .inp case"
|
|
)
|
|
if inputs and not run_case.exists():
|
|
violations.append(
|
|
f"{folder.relative_to(repo_root)} has .inp cases but no run_case.bat"
|
|
)
|
|
if run_case.exists():
|
|
text = run_case.read_text(encoding="utf-8", errors="replace").lower()
|
|
if "femlite" not in text and "run_example_case.bat" not in text:
|
|
violations.append(
|
|
f"{run_case.relative_to(repo_root)} does not appear to launch FemLite"
|
|
)
|
|
for raw_line in text.splitlines():
|
|
if "run_example_case.bat" not in raw_line:
|
|
continue
|
|
quoted = re.findall(r'"([^"]+)"', raw_line)
|
|
if len(quoted) < 5:
|
|
violations.append(
|
|
f"{run_case.relative_to(repo_root)} has a malformed helper call"
|
|
)
|
|
continue
|
|
input_name = quoted[4]
|
|
if not (folder / input_name).exists():
|
|
violations.append(
|
|
f"{run_case.relative_to(repo_root)} points to missing input {input_name}"
|
|
)
|
|
|
|
if violations:
|
|
print("Example layout violations:")
|
|
for violation in violations:
|
|
print(f" {violation}")
|
|
return 1
|
|
|
|
print("Example layout passed: documented folders have .inp cases and runnable scripts.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|