Coverage for src / local_deep_research / settings / base.py: 71%

24 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-01-11 00:51 +0000

1""" 

2Base interface for settings management. 

3 

4This module defines the abstract base class that all settings managers 

5must implement, ensuring a consistent interface. 

6""" 

7 

8from abc import ABC, abstractmethod 

9from typing import Any, Dict, Optional, Union 

10 

11 

12class ISettingsManager(ABC): 

13 """Abstract base class for settings managers.""" 

14 

15 @abstractmethod 

16 def get_setting( 

17 self, key: str, default: Any = None, check_env: bool = True 

18 ) -> Any: 

19 """ 

20 Get a setting value. 

21 

22 Args: 

23 key: Setting key 

24 default: Default value if setting is not found 

25 check_env: If true, check environment variables first 

26 

27 Returns: 

28 Setting value or default if not found 

29 """ 

30 pass 

31 

32 @abstractmethod 

33 def set_setting(self, key: str, value: Any, commit: bool = True) -> bool: 

34 """ 

35 Set a setting value. 

36 

37 Args: 

38 key: Setting key 

39 value: Setting value 

40 commit: Whether to commit the change 

41 

42 Returns: 

43 True if successful, False otherwise 

44 """ 

45 pass 

46 

47 @abstractmethod 

48 def get_all_settings(self) -> Dict[str, Any]: 

49 """ 

50 Get all settings. 

51 

52 Returns: 

53 Dictionary of all settings with metadata 

54 """ 

55 pass 

56 

57 @abstractmethod 

58 def create_or_update_setting( 

59 self, setting: Union[Dict[str, Any], Any], commit: bool = True 

60 ) -> Optional[Any]: 

61 """ 

62 Create or update a setting. 

63 

64 Args: 

65 setting: Setting object or dictionary 

66 commit: Whether to commit the change 

67 

68 Returns: 

69 The created or updated Setting model, or None if failed 

70 """ 

71 pass 

72 

73 @abstractmethod 

74 def delete_setting(self, key: str, commit: bool = True) -> bool: 

75 """ 

76 Delete a setting. 

77 

78 Args: 

79 key: Setting key 

80 commit: Whether to commit the change 

81 

82 Returns: 

83 True if successful, False otherwise 

84 """ 

85 pass 

86 

87 @abstractmethod 

88 def load_from_defaults_file( 

89 self, commit: bool = True, **kwargs: Any 

90 ) -> None: 

91 """ 

92 Import settings from the defaults settings file. 

93 

94 Args: 

95 commit: Whether to commit changes to database 

96 **kwargs: Additional arguments for import_settings 

97 """ 

98 pass 

99 

100 @abstractmethod 

101 def import_settings( 

102 self, 

103 settings_data: Dict[str, Any], 

104 commit: bool = True, 

105 overwrite: bool = True, 

106 delete_extra: bool = False, 

107 ) -> None: 

108 """ 

109 Import settings from a dictionary. 

110 

111 Args: 

112 settings_data: The raw settings data to import 

113 commit: Whether to commit the DB after loading 

114 overwrite: If true, overwrite existing settings 

115 delete_extra: If true, delete settings not in settings_data 

116 """ 

117 pass