Skip to content

Commit 3569138

Browse files
sbryngelsonclaude
andcommitted
Export schema symbols and auto-generate validation hints
- __init__.py: re-export CONSTRAINTS, DEPENDENCIES, get_value_label from the params package (needed by gen_case_constraints_docs.py) - case_validator.py: replace hardcoded error hints with data-driven loop over CONSTRAINTS value_labels - CMakeLists.txt: add definitions.py to DEPENDS for doc generation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3799728 commit 3569138

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ if (MFC_DOCUMENTATION)
665665
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md"
666666
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/gen_case_constraints_docs.py"
667667
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
668+
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/params/definitions.py"
668669
"${examples_DOCs}"
669670
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_constraints.sh"
670671
"${CMAKE_CURRENT_SOURCE_DIR}"

toolchain/mfc/case_validator.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Dict, Any, List, Set
1818
from functools import lru_cache
1919
from .common import MFCException
20+
from .params.definitions import CONSTRAINTS
2021

2122

2223
@lru_cache(maxsize=1)
@@ -1911,14 +1912,27 @@ def _format_errors(self) -> str:
19111912
err_lower = err.lower()
19121913
if "must be positive" in err_lower or "must be set" in err_lower:
19131914
lines.append(" [dim]Check that this required parameter is defined in your case file[/dim]")
1914-
elif "weno_order" in err_lower:
1915-
lines.append(" [dim]Valid values: 1, 3, 5, or 7[/dim]")
1916-
elif "riemann_solver" in err_lower:
1917-
lines.append(" [dim]Valid values: 1 (HLL), 2 (HLLC), 3 (Exact), etc.[/dim]")
1918-
elif "model_eqns" in err_lower:
1919-
lines.append(" [dim]Valid values: 1, 2 (5-eq), 3 (6-eq), or 4[/dim]")
1920-
elif "boundary" in err_lower or "bc_" in err_lower:
1915+
continue
1916+
if "boundary" in err_lower or "bc_" in err_lower:
19211917
lines.append(" [dim]Common BC values: -1 (periodic), -2 (reflective), -3 (extrapolation)[/dim]")
1918+
continue
1919+
1920+
# Auto-generate hints from CONSTRAINTS with value_labels
1921+
for param_name, constraint in CONSTRAINTS.items():
1922+
if param_name not in err_lower:
1923+
continue
1924+
choices = constraint.get("choices")
1925+
if not choices:
1926+
continue
1927+
labels = constraint.get("value_labels", {})
1928+
if labels:
1929+
items = [f"{v} ({labels[v]})" if v in labels else str(v)
1930+
for v in choices]
1931+
hint = f"Valid values: {', '.join(items)}"
1932+
else:
1933+
hint = f"Valid values: {choices}"
1934+
lines.append(f" [dim]{hint}[/dim]")
1935+
break
19221936

19231937
lines.append("")
19241938
lines.append("[dim]Tip: Run './mfc.sh validate case.py' for detailed validation[/dim]")

toolchain/mfc/params/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@
2525
# IMPORTANT: This import populates REGISTRY with all parameter definitions
2626
# and freezes it. It must come after REGISTRY is imported and must not be removed.
2727
from . import definitions # noqa: F401 pylint: disable=unused-import
28+
from .definitions import CONSTRAINTS, DEPENDENCIES, get_value_label
2829

29-
__all__ = ['REGISTRY', 'RegistryFrozenError', 'ParamDef', 'ParamType']
30+
__all__ = [
31+
'REGISTRY', 'RegistryFrozenError', 'ParamDef', 'ParamType',
32+
'CONSTRAINTS', 'DEPENDENCIES', 'get_value_label',
33+
]

0 commit comments

Comments
 (0)