Coverage for opt/mealie/lib/python3.12/site-packages/mealie/core/config.py: 87%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 15:48 +0000

1import os 1a

2from functools import lru_cache 1a

3from pathlib import Path 1a

4 

5import dotenv 1a

6 

7from mealie.core.settings import ( 1a

8 AppDirectories, 

9 AppLoggingSettings, 

10 AppSettings, 

11 app_settings_constructor, 

12) 

13 

14CWD = Path(__file__).parent 1a

15BASE_DIR = CWD.parent.parent 1a

16ENV = BASE_DIR.joinpath(".env") 1a

17 

18dotenv.load_dotenv(ENV) 1a

19PRODUCTION = os.getenv("PRODUCTION", "True").lower() in ["true", "1"] 1a

20TESTING = os.getenv("TESTING", "False").lower() in ["true", "1"] 1a

21DATA_DIR = os.getenv("DATA_DIR") 1a

22 

23 

24def determine_data_dir() -> Path: 1a

25 global PRODUCTION, TESTING, BASE_DIR, DATA_DIR 

26 

27 if TESTING: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true1a

28 return BASE_DIR.joinpath(DATA_DIR if DATA_DIR else "tests/.temp") 

29 

30 if PRODUCTION: 30 ↛ 33line 30 didn't jump to line 33 because the condition on line 30 was always true1a

31 return Path(DATA_DIR if DATA_DIR else "/app/data") 1a

32 

33 return BASE_DIR.joinpath("dev", "data") 

34 

35 

36@lru_cache 1a

37def get_app_dirs() -> AppDirectories: 1a

38 return AppDirectories(determine_data_dir()) 1a

39 

40 

41@lru_cache 1a

42def get_app_settings() -> AppSettings: 1a

43 return app_settings_constructor(env_file=ENV, production=PRODUCTION, data_dir=determine_data_dir()) 1a

44 

45 

46@lru_cache 1a

47def get_logging_settings() -> AppLoggingSettings: 1a

48 return AppLoggingSettings(PRODUCTION=PRODUCTION) 1a