Coverage for functions \ flipdare \ app_config_loader.py: 89%

27 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13from __future__ import annotations 

14 

15__all__ = ["AppConfigLoader"] 

16 

17 

18class AppConfigLoader: 

19 base_env = ".env" 

20 prod_env = ".env.flipdare-73df9" 

21 test_env = ".env.flipdare-test" 

22 

23 def __init__(self) -> None: 

24 pass 

25 

26 @staticmethod 

27 def load(in_cloud: bool) -> None: 

28 load_preference: list[str] 

29 

30 if in_cloud: 

31 load_preference = [AppConfigLoader.prod_env, AppConfigLoader.base_env] 

32 else: 

33 load_preference = [AppConfigLoader.test_env, AppConfigLoader.base_env] 

34 

35 for env_name in load_preference: 

36 AppConfigLoader._try_load_dotenv(env_name) 

37 

38 @staticmethod 

39 def _try_load_dotenv(env_name: str) -> None: 

40 

41 from pathlib import Path 

42 from dotenv import load_dotenv 

43 

44 from flipdare.app_log import LOG 

45 

46 script_dir = Path(__file__).parent 

47 dotenv_path = script_dir / ".." / env_name 

48 if not dotenv_path.exists(): 

49 LOG().warning(f"Dotenv file not found: {dotenv_path}") 

50 return 

51 

52 LOG().info(f"Loading dotenv config from: {dotenv_path}") 

53 load_dotenv(dotenv_path, override=False)