Files

26 lines
1.0 KiB
Python

"""CLI input adapter shared with HTTP; numerical execution accepts SI XML only."""
from __future__ import annotations
import json
from pathlib import Path
import warnings
from app.project_parameters import expression_value as arithmetic_value, prepare_project, version_warning
from app.system_xml import validate_system_xml_document
def project_xml(data: dict) -> bytes:
from app.main import ReactFlowProjectPayload, build_reactflow_system_xml
normalized, notices = prepare_project(ReactFlowProjectPayload.model_validate(data))
if notices:
warnings.warn(json.dumps(version_warning(notices), ensure_ascii=False), UserWarning, stacklevel=2)
return build_reactflow_system_xml(normalized)
def load_input(path: Path):
xml = project_xml(json.loads(path.read_text(encoding="utf-8"))) if path.suffix.lower() == ".json" else path.read_bytes()
report = validate_system_xml_document(xml)
if not report.valid or report.document is None:
raise ValueError(f"Invalid simulation XML: {report.as_dict()}")
return xml, report.document