Source code for torx.specializations.flare.module_import_m

"""Lazy import helper for the optional FLARE library."""
from functools import lru_cache

[docs] @lru_cache(maxsize=1) def import_flare(): """ Import FLARE modules if FLARE is installed. Returns ------- tuple The ``flare.model``, ``flare.analysis.bfield`` and ``flare.analysis`` modules. Raises ------ RuntimeError If the FLARE library cannot be imported. """ try: import flare.model as model from flare.analysis import bfield import flare.analysis as analysis except ImportError as err: raise RuntimeError( "FLARE module not found.\n" "This usually means either:\n" " 1. The python environment it was installed to isn't sourced.\n" " 2. It hasn't been installed. " "See: <torx_home>/install.sh -h\n" f"Original error: {err}" ) from err return model, bfield, analysis