kleinkram 0.40.0.dev20250226155726__py3-none-any.whl → 0.40.0.dev20250228081255__py3-none-any.whl
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.
Potentially problematic release.
This version of kleinkram might be problematic. Click here for more details.
- kleinkram/config.py +18 -2
- {kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/METADATA +1 -1
- {kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/RECORD +7 -7
- {kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/WHEEL +1 -1
- tests/test_config.py +19 -1
- {kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/entry_points.txt +0 -0
- {kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/top_level.txt +0 -0
kleinkram/config.py
CHANGED
|
@@ -24,6 +24,7 @@ from rich.text import Text
|
|
|
24
24
|
|
|
25
25
|
from kleinkram._version import __local__
|
|
26
26
|
from kleinkram._version import __version__
|
|
27
|
+
from kleinkram.utils import format_traceback
|
|
27
28
|
|
|
28
29
|
logger = logging.getLogger(__name__)
|
|
29
30
|
|
|
@@ -167,13 +168,28 @@ def _config_from_dict(dct: Dict[str, Any]) -> Config:
|
|
|
167
168
|
)
|
|
168
169
|
|
|
169
170
|
|
|
170
|
-
def
|
|
171
|
-
|
|
171
|
+
def _safe_config_write(
|
|
172
|
+
config: Config, path: Path, tmp_dir: Optional[Path] = None
|
|
173
|
+
) -> None:
|
|
174
|
+
fd, temp_path = tempfile.mkstemp(dir=tmp_dir)
|
|
172
175
|
with os.fdopen(fd, "w") as f:
|
|
173
176
|
json.dump(_config_to_dict(config), f)
|
|
174
177
|
os.replace(temp_path, path)
|
|
175
178
|
|
|
176
179
|
|
|
180
|
+
def _unsafe_config_write(config: Config, path: Path) -> None:
|
|
181
|
+
with open(path, "w") as f:
|
|
182
|
+
json.dump(_config_to_dict(config), f)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def save_config(config: Config, path: Path = CONFIG_PATH) -> None:
|
|
186
|
+
try:
|
|
187
|
+
_safe_config_write(config, path)
|
|
188
|
+
except Exception as e:
|
|
189
|
+
logger.warning(f"failed to safe write config {format_traceback(e)}")
|
|
190
|
+
_unsafe_config_write(config, path)
|
|
191
|
+
|
|
192
|
+
|
|
177
193
|
def _load_config_if_compatible(path: Path) -> Optional[Config]:
|
|
178
194
|
if not path.exists():
|
|
179
195
|
return None
|
{kleinkram-0.40.0.dev20250226155726.dist-info → kleinkram-0.40.0.dev20250228081255.dist-info}/RECORD
RENAMED
|
@@ -2,7 +2,7 @@ kleinkram/__init__.py,sha256=xIJqTJw2kbCGryGlCeAdpmtR1FTxmrW1MklUNQEaj74,1061
|
|
|
2
2
|
kleinkram/__main__.py,sha256=B9RiZxfO4jpCmWPUHyKJ7_EoZlEG4sPpH-nz7T_YhhQ,125
|
|
3
3
|
kleinkram/_version.py,sha256=QYJyRTcqFcJj4qWYpqs7WcoOP6jxDMqyvxLY-cD6KcE,129
|
|
4
4
|
kleinkram/auth.py,sha256=XD_rHOyJmYYfO7QJf3TLYH5qXA22gXGWi7PT3jujlVs,2968
|
|
5
|
-
kleinkram/config.py,sha256=
|
|
5
|
+
kleinkram/config.py,sha256=_ZfOSfEZaK8ZbgoNRZL2h3ozZfxHnKqmLJ9mUIYOxBU,7413
|
|
6
6
|
kleinkram/core.py,sha256=Q7OYIKPN9K6kxf9Eq7r5XRHPJ3RtT7SBZp_3_CS8yuY,8429
|
|
7
7
|
kleinkram/errors.py,sha256=4mygNxkf6IBgaiRWY95qu0v6z4TAXA3G6CUcXC9FU3s,772
|
|
8
8
|
kleinkram/main.py,sha256=BTE0mZN__xd46wBhFi6iBlK9eGGQvJ1LdUMsbnysLi0,172
|
|
@@ -34,7 +34,7 @@ testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
34
34
|
testing/backend_fixtures.py,sha256=t5QWwyezHUhxxAlbUuE_eFmpyRaGbnWNNcGPwrO17JM,1571
|
|
35
35
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
tests/conftest.py,sha256=5MLYQOtQoXWl0TRkYntYKNdqpd4hl9m0XTRi5OXanYI,104
|
|
37
|
-
tests/test_config.py,sha256=
|
|
37
|
+
tests/test_config.py,sha256=BGIXTX0XRF634_NMG-ya8v0zruw4PZCZtFGhYVK4DCM,5867
|
|
38
38
|
tests/test_core.py,sha256=JbzB05LWmaaP77uXeTOQtCJD2AJT0zO9zhDfcZ3GNH8,5139
|
|
39
39
|
tests/test_end_to_end.py,sha256=0W5pUES5hek-pXq4NZtpPZqKTORkGCRsDv5_D3rDMjY,3372
|
|
40
40
|
tests/test_error_handling.py,sha256=qPSMKF1qsAHyUME0-krxbIrk38iGKkhAyAah-KwN4NE,1300
|
|
@@ -43,8 +43,8 @@ tests/test_printing.py,sha256=Jz1AjqmqBRjp1JLm6H1oVJyvGaMPlahVXdKnd7UDQFc,2231
|
|
|
43
43
|
tests/test_query.py,sha256=fExmCKXLA7-9j2S2sF_sbvRX_2s6Cp3a7OTcqE25q9g,3864
|
|
44
44
|
tests/test_utils.py,sha256=eUBYrn3xrcgcaxm1X4fqZaX4tRvkbI6rh6BUbNbu9T0,4784
|
|
45
45
|
tests/test_wrappers.py,sha256=TbcTyO2L7fslbzgfDdcVZkencxNQ8cGPZm_iB6c9d6Q,2673
|
|
46
|
-
kleinkram-0.40.0.
|
|
47
|
-
kleinkram-0.40.0.
|
|
48
|
-
kleinkram-0.40.0.
|
|
49
|
-
kleinkram-0.40.0.
|
|
50
|
-
kleinkram-0.40.0.
|
|
46
|
+
kleinkram-0.40.0.dev20250228081255.dist-info/METADATA,sha256=y2qW3auu9kx4VTRvV20CKWZCisrZtWt9KYySkuGXpv0,2760
|
|
47
|
+
kleinkram-0.40.0.dev20250228081255.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
48
|
+
kleinkram-0.40.0.dev20250228081255.dist-info/entry_points.txt,sha256=SaB2l5aqhSr8gmaMw2kvQU90a8Bnl7PedU8cWYxkfYo,46
|
|
49
|
+
kleinkram-0.40.0.dev20250228081255.dist-info/top_level.txt,sha256=N3-sJagEHu1Tk1X6Dx1X1q0pLDNbDZpLzRxVftvepds,24
|
|
50
|
+
kleinkram-0.40.0.dev20250228081255.dist-info/RECORD,,
|
tests/test_config.py
CHANGED
|
@@ -7,6 +7,7 @@ from unittest import mock
|
|
|
7
7
|
|
|
8
8
|
import pytest
|
|
9
9
|
|
|
10
|
+
import kleinkram.config
|
|
10
11
|
from kleinkram.config import ACTION_API
|
|
11
12
|
from kleinkram.config import ACTION_API_KEY
|
|
12
13
|
from kleinkram.config import ACTION_S3
|
|
@@ -102,9 +103,26 @@ def test_save_and_load_config(config_path):
|
|
|
102
103
|
config = Config(version="foo")
|
|
103
104
|
|
|
104
105
|
assert not config_path.exists()
|
|
105
|
-
|
|
106
|
+
with mock.patch.object(kleinkram.config.logger, "warning") as mock_warning:
|
|
107
|
+
save_config(config, path=config_path)
|
|
108
|
+
mock_warning.assert_not_called()
|
|
109
|
+
|
|
106
110
|
assert config_path.exists()
|
|
111
|
+
loaded_config = _load_config(path=config_path)
|
|
112
|
+
assert loaded_config == config
|
|
113
|
+
|
|
107
114
|
|
|
115
|
+
def test_save_and_load_config_when_tmpfile_fails(config_path):
|
|
116
|
+
config = Config(version="foo")
|
|
117
|
+
|
|
118
|
+
assert not config_path.exists()
|
|
119
|
+
with mock.patch("tempfile.mkstemp", side_effect=Exception), mock.patch.object(
|
|
120
|
+
kleinkram.config.logger, "warning"
|
|
121
|
+
) as mock_warning:
|
|
122
|
+
save_config(config, path=config_path)
|
|
123
|
+
mock_warning.assert_called_once()
|
|
124
|
+
|
|
125
|
+
assert config_path.exists()
|
|
108
126
|
loaded_config = _load_config(path=config_path)
|
|
109
127
|
assert loaded_config == config
|
|
110
128
|
|
|
File without changes
|
|
File without changes
|