Skill Tracer
Skills › Scientific Agent Skills › fluidsim › solver_config_validator.py

solver_config_validator.py

70 lines · skills/fluidsim/scripts/solver_config_validator.py at 5f2bc03

1#!/usr/bin/env python3
2"""Validate a bounded FluidSim 0.9 JSON simulation plan."""
3
4from __future__ import annotations
5
6import argparse
7
8try:
9 from ._common import ToolError, checked_input, emit_json, fail_json, load_json
10 from ._schema import example_config, validate_config
11except ImportError: # Direct script execution.
12 from _common import ToolError, checked_input, emit_json, fail_json, load_json
13 from _schema import example_config, validate_config
16TOOL = "fluidsim-solver-config-validator"
19def build_parser() -> argparse.ArgumentParser:
20 parser = argparse.ArgumentParser(
21 description=(
22 "Validate strict local JSON against the static FluidSim 0.9 CFD "
23 "configuration profile. No FluidSim package is imported and nothing runs."
24 )
25 )
26 source = parser.add_mutually_exclusive_group(required=True)
27 source.add_argument("--config", help="Configuration JSON within --root.")
28 source.add_argument(
29 "--example",
30 action="store_true",
31 help="Emit a bounded example configuration as strict JSON.",
32 )
33 parser.add_argument(
34 "--root",
35 default=".",
36 help="Local I/O boundary (default: current directory).",
37 )
38 return parser
41def main(argv: list[str] | None = None) -> int:
42 args = build_parser().parse_args(argv)
43 try:
44 if args.example:
45 emit_json(example_config())
46 return 0
47 path = checked_input(
48 args.config,
49 root=args.root,
50 kind="file",
51 suffixes={".json"},
52 )
53 report = validate_config(load_json(path))
54 report.update(
55 {
56 "commands_executed": False,
57 "dynamic_imports_used": False,
58 "network_used": False,
59 "source": path.name,
60 "tool": TOOL,
61 }
62 )
63 emit_json(report)
64 return 0 if report["ok"] else 2
65 except (OSError, ToolError, UnicodeError) as exc:
66 return fail_json(TOOL, exc)
69if __name__ == "__main__":
70 raise SystemExit(main())