File indexing completed on 2026-08-12 08:24:56
0001 """Base environment configuration model
0002
0003 Defines generic base model for configuring environment variables.
0004
0005 Project: AID2E v0.0.0 - AI assisted Detector Design for EIC
0006 Homepage: https://aid2e.github.io/aid2e-framework
0007 Repository: https://github.com/aid2e/AID2E-framework.git
0008 """
0009
0010 from abc import ABC, abstractmethod
0011 from pydantic import BaseModel
0012 from typing import Any, Dict
0013
0014
0015 class EnvironmentConfig(ABC, BaseModel):
0016 """Configures environment variables
0017
0018 Generic base model for configuring environment variables. Must
0019 be specialized for specific for specifc contexts such as
0020 EpicConfiguration.
0021
0022 Example:
0023 >>> class MyEnvConfig(EnvironmentConfiguration):
0024 ... geometry_install: str
0025 ... def activate(self) -> None:
0026 ... os.environ['GEOMETRY_INSTALL'] = self.geometry_install
0027 ... print(f"[INFO] Set $GEOMETRY_INSTALL to {self.geometry_install}")
0028 """
0029 @property
0030 @abstractmethod
0031 def key(self) -> str:
0032 """YAML key associated with model (e.g. epic_environment_config)
0033 """
0034 pass
0035
0036 @abstractmethod
0037 def activate(self) -> None:
0038 """
0039 Activate environment variables. Must be implemented
0040 by subclasses.
0041 """
0042 pass
0043
0044
0045 class EnvironmentConfigLoader(ABC):
0046 """Loader for environment variables
0047
0048 Generic base class for loading environment config
0049 models. Must be specialized for specific contexts
0050 like EnvironmentConfig.
0051
0052 Example:
0053 >>> class MyEnvConfigLoader(EnvironmentConfigLoader[MyEnvConfig]):
0054 ... @staticmethod
0055 ... def load(file_path: str) -> MyEnvConfigLoader:
0056 ... with open(file_path, 'r') as file:
0057 ... data = yaml.safe_load(file)
0058 ... return MyEnvConfigLoader(**data)
0059 """
0060
0061 @staticmethod
0062 @abstractmethod
0063 def load(env_data: Dict[str, Any] = None, file_path: str = None) -> "EnvironmentConfig":
0064 """
0065 Load an environment configuration from a YAML file.
0066 Must instantiate and return a subclass of
0067 EnvironmentConfig.
0068 """
0069 pass