INNER CODE UNIT · Python
_load_model_module
3dg1luk43/ha_washdata · custom_components/ha_washdata/ml/engine.py:68
def _load_model_module(module_name: str) -> Any | None:
"""Return the embedded model module, importing it at most once.
Safe to call from the event loop *after* :func:`preload_models` has run (the
import is then already satisfied from ``sys.modules``); the first call should
happen in an executor thread.
"""
if module_name in _MODULE_CACHE:
return _MODULE_CACHE[module_name]
try:
module = importlib.import_module(f"{__package__}.{module_name}")
except Exception as exc: # noqa: BLE001 - a missing model must not break setup
_LOGGER.warning(
"Failed to load embedded model module %r: %s", module_name, exc
)
module = None
_MODULE_CACHE[module_name] = module
return module