Coverage for src/local_deep_research/settings/base.py: 70%
30 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-06 15:42 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-06 15:42 +0000
1"""
2Base interface for settings management.
4This module defines the abstract base class that all settings managers
5must implement, ensuring a consistent interface.
6"""
8from abc import ABC, abstractmethod
9from typing import Any, Dict, Optional, Union
12class ISettingsManager(ABC):
13 """Abstract base class for settings managers."""
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.
22 Args:
23 key: Setting key
24 default: Default value if setting is not found
25 check_env: If true, check environment variables first
27 Returns:
28 Setting value or default if not found
29 """
30 pass
32 @abstractmethod
33 def set_setting(self, key: str, value: Any, commit: bool = True) -> bool:
34 """
35 Set a setting value.
37 Args:
38 key: Setting key
39 value: Setting value
40 commit: Whether to commit the change
42 Returns:
43 True if successful, False otherwise
44 """
45 pass
47 @abstractmethod
48 def get_all_settings(
49 self,
50 bypass_cache: bool = False,
51 include_environment_overrides: bool = True,
52 strict: bool = False,
53 ) -> Dict[str, Any]:
54 """
55 Get all settings.
57 Args:
58 bypass_cache: If true, bypass any implementation cache.
59 include_environment_overrides: If true, overlay current LDR_* values.
60 strict: If true, propagate database and enum query failures.
62 Returns:
63 Dictionary of all settings with metadata
64 """
65 pass
67 @abstractmethod
68 def create_or_update_setting(
69 self, setting: Union[Dict[str, Any], Any], commit: bool = True
70 ) -> Optional[Any]:
71 """
72 Create or update a setting.
74 Args:
75 setting: Setting object or dictionary
76 commit: Whether to commit the change
78 Returns:
79 The created or updated Setting model, or None if failed
80 """
81 pass
83 @abstractmethod
84 def delete_setting(self, key: str, commit: bool = True) -> bool:
85 """
86 Delete a setting.
88 Args:
89 key: Setting key
90 commit: Whether to commit the change
92 Returns:
93 True if successful, False otherwise
94 """
95 pass
97 @abstractmethod
98 def get_bool_setting(
99 self, key: str, default: bool = False, check_env: bool = True
100 ) -> bool:
101 """
102 Get a setting value as a boolean.
104 Args:
105 key: Setting key
106 default: Default boolean value if setting is not found
107 check_env: If true, check environment variables first
109 Returns:
110 Boolean value of the setting
111 """
112 pass
114 @abstractmethod
115 def get_settings_snapshot(self, strict: bool = False) -> Dict[str, Any]:
116 """
117 Get a simplified settings snapshot with just key-value pairs.
119 Args:
120 strict: If true, propagate database and enum query failures.
122 Returns:
123 Dictionary with setting keys mapped to their values
124 """
125 pass
127 @abstractmethod
128 def load_from_defaults_file(
129 self, commit: bool = True, **kwargs: Any
130 ) -> None:
131 """
132 Import settings from the defaults settings file.
134 Args:
135 commit: Whether to commit changes to database
136 **kwargs: Additional arguments for import_settings
137 """
138 pass
140 @abstractmethod
141 def import_settings(
142 self,
143 settings_data: Dict[str, Any],
144 commit: bool = True,
145 overwrite: bool = True,
146 delete_extra: bool = False,
147 preserve_environment_locked: bool = False,
148 ) -> None:
149 """
150 Import settings from a dictionary.
152 Args:
153 settings_data: The raw settings data to import
154 commit: Whether to commit the DB after loading
155 overwrite: If true, overwrite existing settings
156 delete_extra: If true, delete settings not in settings_data
157 preserve_environment_locked: If true, preserve the stored value
158 for settings with active environment overrides while imported
159 metadata may refresh
160 """
161 pass