From a9e489a17bd7be41be151420a2773f814caf0a93 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Sun, 5 Apr 2026 11:54:25 -0400 Subject: [PATCH] Fix Homebrew install: add fallback constants when m_constants.fpp is unavailable The Homebrew formula only ships toolchain/ and examples/ but not src/. The toolchain reads Fortran constants from src/common/m_constants.fpp at import time, causing a RuntimeError in Homebrew installs. Add fallback values for the 4 required constants so the toolchain works without the Fortran source tree. --- toolchain/mfc/params/namelist_parser.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/toolchain/mfc/params/namelist_parser.py b/toolchain/mfc/params/namelist_parser.py index 5ac3913499..8e4aa48c09 100644 --- a/toolchain/mfc/params/namelist_parser.py +++ b/toolchain/mfc/params/namelist_parser.py @@ -490,16 +490,29 @@ def get_fortran_constants() -> Dict[str, int]: """ Get Fortran compile-time constants from m_constants.fpp. - Cached after first call. Returns empty dict if source unavailable. + Cached after first call. Falls back to built-in defaults when the Fortran + source is unavailable (e.g. Homebrew installs where src/ is not shipped). """ global _FORTRAN_CONSTANTS_CACHE # noqa: PLW0603 if _FORTRAN_CONSTANTS_CACHE is None: root = get_mfc_root() path = root / "src" / "common" / "m_constants.fpp" _FORTRAN_CONSTANTS_CACHE = parse_fortran_constants(path) + if not _FORTRAN_CONSTANTS_CACHE: + _FORTRAN_CONSTANTS_CACHE = _FALLBACK_CONSTANTS.copy() return _FORTRAN_CONSTANTS_CACHE +# Fallback values for when m_constants.fpp is not available at runtime. +# Keep in sync with src/common/m_constants.fpp. +_FALLBACK_CONSTANTS: Dict[str, int] = { + "num_fluids_max": 10, + "num_probes_max": 10, + "num_patches_max": 1000, + "num_bc_patches_max": 10, +} + + def get_mfc_root() -> Path: """Get the MFC root directory from this file's location.""" # This file is at toolchain/mfc/params/namelist_parser.py