Coverage for health / utils / env_loader.py: 93%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-02 17:44 +0800

1import os 

2import logging 

3from dotenv import load_dotenv 

4 

5logger = logging.getLogger(__name__) 

6 

7def load_env_with_extras(): 

8 """ 

9 Load environment variables from .env file, and optionally from an extra file 

10 specified by GEMINI_CONFIG_PATH enviroment variable. 

11  

12 The extra file will override values in .env. 

13 """ 

14 # 1. Load standard .env (DO NOT override existing env vars if they are set in shell) 

15 # Actually, standard behavior of load_dotenv is not to override. 

16 load_dotenv() 

17 

18 # 2. Check for GEMINI_CONFIG_PATH 

19 config_path = os.environ.get("GEMINI_CONFIG_PATH") 

20 

21 if config_path: 

22 # Resolve path 

23 if not os.path.isabs(config_path): 

24 config_path = os.path.abspath(config_path) 

25 

26 if os.path.exists(config_path): 

27 logger.info(f"Loading extra configuration from: {config_path}") 

28 # Override=True because we specifically want this file to take precedence 

29 # over the already loaded .env values (or previous values) 

30 load_dotenv(dotenv_path=config_path, override=True) 

31 else: 

32 logger.warning(f"GEMINI_CONFIG_PATH was set to '{config_path}' but file does not exist.")