Config Loader
lean_automator.config.loader
¶
Loads and manages application configuration from multiple sources.
This module provides functions to load configuration settings from YAML files
(defaults), JSON files (e.g., costs), and environment variables (overrides, secrets).
It automatically determines the paths for the default configuration files
(config.yml
, model_costs.json
) by:
1. Checking specific environment variables (LEAN_AUTOMATOR_CONFIG_FILE
,
LEAN_AUTOMATOR_COSTS_FILE
).
2. Searching upwards from this file's location for a project root marker
(pyproject.toml
) and looking for the files in that root directory.
3. As a fallback, looking in the current working directory (with a warning).
It exposes the loaded configuration via a singleton dictionary APP_CONFIG
and provides helper functions to access specific sensitive values directly
from the environment.
Functions¶
load_configuration(dotenv_path: Optional[str] = None, env_override_map: List[Tuple[str, List[str], Type]] = ENV_OVERRIDES) -> Dict[str, Any]
¶
Loads configuration layers: YAML defaults, JSON costs, and env overrides.
Determines the paths for the default configuration file (config.yml
)
and costs file (model_costs.json
) using the following priority:
1. Environment variables: LEAN_AUTOMATOR_CONFIG_FILE
and
LEAN_AUTOMATOR_COSTS_FILE
.
2. Project Root Search: Looks for pyproject.toml
upwards from this loader's
directory and constructs paths relative to that root.
3. Current Working Directory (Fallback): If neither of the above yields a path,
it tries the CWD (logging a warning).
After determining paths, it reads the base configuration from the YAML file,
merges data from the JSON costs file into the 'costs' key, loads environment
variables from a .env file (if specified or found), and finally applies
overrides defined in env_override_map
using values from environment variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dotenv_path
|
Optional[str]
|
Explicit path to the .env file. If None, |
None
|
env_override_map
|
List[Tuple[str, List[str], Type]]
|
The mapping defining which environment variables override which configuration keys and their types. |
ENV_OVERRIDES
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary containing the fully merged configuration. Returns an |
Dict[str, Any]
|
empty dictionary if the determined base config file cannot be found or parsed. |
Dict[str, Any]
|
Cost data or overrides might be missing if respective files/variables are |
Dict[str, Any]
|
absent or invalid. |
Source code in lean_automator/config/loader.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
get_gemini_api_key() -> Optional[str]
¶
Retrieves the Gemini API Key directly from environment variables.
Returns:
Type | Description |
---|---|
Optional[str]
|
The Gemini API key string if the 'GEMINI_API_KEY' environment |
Optional[str]
|
variable is set, otherwise None. |
Source code in lean_automator/config/loader.py
get_lean_automator_shared_lib_path() -> Optional[str]
¶
Retrieves the Lean Automator Shared Lib Path from environment variables.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path string if the 'LEAN_AUTOMATOR_SHARED_LIB_PATH' environment |
Optional[str]
|
variable is set, otherwise None. |