mooch.settings 0.0.1.dev1__tar.gz → 0.0.1.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mooch_settings-0.0.1.dev1/src/mooch.settings.egg-info → mooch_settings-0.0.1.dev2}/PKG-INFO +1 -1
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/pyproject.toml +1 -1
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch/settings/file.py +11 -9
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2/src/mooch.settings.egg-info}/PKG-INFO +1 -1
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/tests/test_settings.py +24 -14
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/.gitignore +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/LICENSE +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/README.md +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/settings.toml +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/setup.cfg +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch/__init__.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch/settings/__init__.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch/settings/settings.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch/settings/utils.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/SOURCES.txt +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/dependency_links.txt +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/requires.txt +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/top_level.txt +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/tests/test_file.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/tests/test_utils.py +0 -0
- {mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/uv.lock +0 -0
{mooch_settings-0.0.1.dev1/src/mooch.settings.egg-info → mooch_settings-0.0.1.dev2}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mooch.settings
|
3
|
-
Version: 0.0.1.
|
3
|
+
Version: 0.0.1.dev2
|
4
4
|
Summary: Python settings management package (mooch.settings). Uses a TOML file.
|
5
5
|
Author-email: Nick Stuer <nickstuer@duck.com>
|
6
6
|
Project-URL: Homepage, https://github.com/nickstuer/mooch.settings
|
@@ -17,17 +17,19 @@ UPDATED_KEY = "metadata.updated"
|
|
17
17
|
class File:
|
18
18
|
def __init__(self, settings_filepath: Path) -> None:
|
19
19
|
self._filepath = settings_filepath
|
20
|
-
self.create_file_if_not_exists()
|
21
|
-
|
22
|
-
def create_file_if_not_exists(self) -> None:
|
23
|
-
"""Create the settings file if it does not exist."""
|
24
20
|
if not self._filepath.exists():
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
self.create_file_and_directories()
|
22
|
+
|
23
|
+
def create_file_and_directories(self) -> None:
|
24
|
+
"""Create the settings file and directories."""
|
25
|
+
# Ensure the parent directory exists
|
26
|
+
self._filepath.parent.mkdir(parents=True, exist_ok=True)
|
27
|
+
data = {}
|
28
|
+
set_nested(data, NOTICE_KEY, NOTICE)
|
29
|
+
set_nested(data, CREATED_KEY, datetime.now(tz=timezone.utc).isoformat())
|
30
|
+
set_nested(data, UPDATED_KEY, datetime.now(tz=timezone.utc).isoformat())
|
29
31
|
|
30
|
-
|
32
|
+
self.save(data)
|
31
33
|
|
32
34
|
def load(self) -> dict[str, Any]:
|
33
35
|
"""Load the settings from the file."""
|
{mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2/src/mooch.settings.egg-info}/PKG-INFO
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mooch.settings
|
3
|
-
Version: 0.0.1.
|
3
|
+
Version: 0.0.1.dev2
|
4
4
|
Summary: Python settings management package (mooch.settings). Uses a TOML file.
|
5
5
|
Author-email: Nick Stuer <nickstuer@duck.com>
|
6
6
|
Project-URL: Homepage, https://github.com/nickstuer/mooch.settings
|
@@ -22,7 +22,7 @@ default_settings2 = {
|
|
22
22
|
@pytest.fixture
|
23
23
|
def settings_filepath(tmpdir_factory: pytest.TempdirFactory):
|
24
24
|
temp_dir = str(tmpdir_factory.mktemp("temp"))
|
25
|
-
filepath = temp_dir + "/settings.toml"
|
25
|
+
filepath = temp_dir + "/testing/settings.toml"
|
26
26
|
yield Path(filepath)
|
27
27
|
# yield Path("settings.toml")
|
28
28
|
shutil.rmtree(temp_dir)
|
@@ -45,7 +45,7 @@ def test_settings_initializes_with_default_settings(settings_filepath: Path):
|
|
45
45
|
assert settings.get("foo") is None
|
46
46
|
|
47
47
|
|
48
|
-
def test_settings_sets_default_settings_if_not_present(settings_filepath:
|
48
|
+
def test_settings_sets_default_settings_if_not_present(settings_filepath: Path):
|
49
49
|
settings = Settings(settings_filepath, default_settings)
|
50
50
|
assert settings.get("foo") is None
|
51
51
|
|
@@ -57,7 +57,7 @@ def test_settings_sets_default_settings_if_not_present(settings_filepath: str):
|
|
57
57
|
assert new_settings.get(k) == v
|
58
58
|
|
59
59
|
|
60
|
-
def test_settings_get_and_set_methods_success(settings_filepath:
|
60
|
+
def test_settings_get_and_set_methods_success(settings_filepath: Path):
|
61
61
|
settings = Settings(settings_filepath, default_settings)
|
62
62
|
|
63
63
|
settings.set("string", "string_value")
|
@@ -93,7 +93,7 @@ def test_settings_get_and_set_methods_success(settings_filepath: str):
|
|
93
93
|
assert settings.get("emoji") == "😊"
|
94
94
|
|
95
95
|
|
96
|
-
def test_settings_overrides_existing_settings(settings_filepath:
|
96
|
+
def test_settings_overrides_existing_settings(settings_filepath: Path):
|
97
97
|
settings = Settings(settings_filepath, default_settings)
|
98
98
|
|
99
99
|
# Set an initial value
|
@@ -105,14 +105,15 @@ def test_settings_overrides_existing_settings(settings_filepath: str):
|
|
105
105
|
assert settings.get("name") == "NewName"
|
106
106
|
|
107
107
|
|
108
|
-
def test_settings_handles_non_existent_keys(settings_filepath:
|
108
|
+
def test_settings_handles_non_existent_keys(settings_filepath: Path):
|
109
109
|
settings = Settings(settings_filepath, default_settings)
|
110
110
|
|
111
111
|
assert settings.get("non_existent_key") is None
|
112
112
|
|
113
113
|
|
114
|
-
def test_settings_handles_empty_settings_file(settings_filepath:
|
114
|
+
def test_settings_handles_empty_settings_file(settings_filepath: Path):
|
115
115
|
# Create an empty settings file
|
116
|
+
settings_filepath.parent.mkdir(parents=True, exist_ok=True)
|
116
117
|
with Path.open(settings_filepath, "w") as f:
|
117
118
|
f.write("")
|
118
119
|
settings = Settings(settings_filepath, default_settings)
|
@@ -121,7 +122,16 @@ def test_settings_handles_empty_settings_file(settings_filepath: str):
|
|
121
122
|
assert settings.get(k) == v
|
122
123
|
|
123
124
|
|
124
|
-
def
|
125
|
+
def test_settings_handles_creating_directories_for_new_files(settings_filepath: Path):
|
126
|
+
parent_dir = settings_filepath.parent
|
127
|
+
|
128
|
+
assert not parent_dir.exists(), "Parent directory should not exist before test"
|
129
|
+
|
130
|
+
settings = Settings(settings_filepath, default_settings)
|
131
|
+
assert parent_dir.exists(), "Parent directory should be created by Settings class"
|
132
|
+
|
133
|
+
|
134
|
+
def test_settings_saves_settings_to_file(settings_filepath: Path):
|
125
135
|
settings = Settings(settings_filepath, default_settings)
|
126
136
|
|
127
137
|
# Set some values
|
@@ -134,7 +144,7 @@ def test_settings_saves_settings_to_file(settings_filepath: str):
|
|
134
144
|
assert new_settings.get("mood") == "TestMood"
|
135
145
|
|
136
146
|
|
137
|
-
def test_settings_no_default_settings(settings_filepath:
|
147
|
+
def test_settings_no_default_settings(settings_filepath: Path):
|
138
148
|
# Test with no default settings
|
139
149
|
settings = Settings(settings_filepath)
|
140
150
|
|
@@ -151,7 +161,7 @@ def test_settings_no_default_settings(settings_filepath: str):
|
|
151
161
|
assert new_settings.get("name") == "NoDefaultName"
|
152
162
|
|
153
163
|
|
154
|
-
def test_settings_with_getitem_and_setitem(settings_filepath:
|
164
|
+
def test_settings_with_getitem_and_setitem(settings_filepath: Path):
|
155
165
|
settings = Settings(settings_filepath, default_settings)
|
156
166
|
|
157
167
|
# Test __getitem__
|
@@ -167,7 +177,7 @@ def test_settings_with_getitem_and_setitem(settings_filepath: str):
|
|
167
177
|
assert settings["new_key"] == "new_value"
|
168
178
|
|
169
179
|
|
170
|
-
def test_settings_updates_defaults_with_nested_dict(settings_filepath:
|
180
|
+
def test_settings_updates_defaults_with_nested_dict(settings_filepath: Path):
|
171
181
|
settings = Settings(settings_filepath, default_settings)
|
172
182
|
assert settings.get("dictionary.subdictionary.key3") is None
|
173
183
|
assert settings["dictionary.subdictionary.key3"] is None
|
@@ -180,7 +190,7 @@ def test_settings_updates_defaults_with_nested_dict(settings_filepath: str):
|
|
180
190
|
assert new_settings["dictionary"]["subdictionary"]["key3"] == "subvalue3"
|
181
191
|
|
182
192
|
|
183
|
-
def test_settings_initializes_defaults_with_nested_dict(settings_filepath:
|
193
|
+
def test_settings_initializes_defaults_with_nested_dict(settings_filepath: Path):
|
184
194
|
settings = Settings(settings_filepath, default_settings2)
|
185
195
|
assert settings.get("settings.name") == "MyName"
|
186
196
|
assert settings.get("settings.mood") == "MyMood"
|
@@ -197,7 +207,7 @@ def test_settings_initializes_defaults_with_nested_dict(settings_filepath: str):
|
|
197
207
|
assert settings.get("settings") == {"gui": {"theme": {"ios": "dark"}}, "mood": "MyMood", "name": "MyName"}
|
198
208
|
|
199
209
|
|
200
|
-
def test_settings_sets_default_settings_of_nested_dictionaries_if_not_present(settings_filepath:
|
210
|
+
def test_settings_sets_default_settings_of_nested_dictionaries_if_not_present(settings_filepath: Path):
|
201
211
|
settings = Settings(settings_filepath, default_settings2)
|
202
212
|
assert settings.get("settings.gui.theme.ios") == "dark"
|
203
213
|
assert settings.get("settings.gui.theme.android") is None
|
@@ -221,7 +231,7 @@ def test_settings_home_directory():
|
|
221
231
|
assert home_dir == Path.home() # Ensure it matches the actual home directory
|
222
232
|
|
223
233
|
|
224
|
-
def test_settings_dynamic_reload_true(settings_filepath:
|
234
|
+
def test_settings_dynamic_reload_true(settings_filepath: Path):
|
225
235
|
settings = Settings(settings_filepath, default_settings)
|
226
236
|
|
227
237
|
assert settings.get("settings.name") == "MyName"
|
@@ -234,7 +244,7 @@ def test_settings_dynamic_reload_true(settings_filepath: str):
|
|
234
244
|
assert settings.get("settings.name") == "NewName"
|
235
245
|
|
236
246
|
|
237
|
-
def test_settings_dynamic_reload_false(settings_filepath:
|
247
|
+
def test_settings_dynamic_reload_false(settings_filepath: Path):
|
238
248
|
settings = Settings(settings_filepath, default_settings)
|
239
249
|
settings.dynamic_reload = False
|
240
250
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/SOURCES.txt
RENAMED
File without changes
|
File without changes
|
{mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/requires.txt
RENAMED
File without changes
|
{mooch_settings-0.0.1.dev1 → mooch_settings-0.0.1.dev2}/src/mooch.settings.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|