Source code for laborchestrator.start_up.config_loader

"""
Utility to load orchestrator startup parameters from a config file.
The provided config file might contain only some of the parameters.
Defaults from default_config will be used for those.
"""
import importlib.util
from pathlib import Path
from dataclasses import fields
from .default_config import LabOrchestratorConfig


[docs] def load_config(path: str | None) -> LabOrchestratorConfig: config = LabOrchestratorConfig() if not path: return config path = Path(path).resolve() if not path.exists(): raise FileNotFoundError(f"Config file not found: {path}") spec = importlib.util.spec_from_file_location("laborchestrator_user_config", path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) for field in fields(config): if hasattr(module, field.name): setattr(config, field.name, getattr(module, field.name)) return config