configaroo 0.3.0__py3-none-any.whl → 0.4.0__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.
- configaroo/__init__.py +1 -1
- configaroo/configuration.py +15 -26
- configaroo/loaders/__init__.py +6 -1
- {configaroo-0.3.0.dist-info → configaroo-0.4.0.dist-info}/METADATA +1 -1
- configaroo-0.4.0.dist-info/RECORD +12 -0
- configaroo-0.3.0.dist-info/RECORD +0 -12
- {configaroo-0.3.0.dist-info → configaroo-0.4.0.dist-info}/WHEEL +0 -0
- {configaroo-0.3.0.dist-info → configaroo-0.4.0.dist-info}/licenses/LICENSE +0 -0
- {configaroo-0.3.0.dist-info → configaroo-0.4.0.dist-info}/top_level.txt +0 -0
configaroo/__init__.py
CHANGED
configaroo/configuration.py
CHANGED
@@ -36,33 +36,20 @@ class Configuration(UserDict[str, Any]):
|
|
36
36
|
def from_file(
|
37
37
|
cls,
|
38
38
|
file_path: str | Path,
|
39
|
+
*,
|
39
40
|
loader: str | None = None,
|
40
|
-
|
41
|
-
env_prefix: str = "",
|
42
|
-
extra_dynamic: dict[str, Any] | None = None,
|
41
|
+
not_exist_ok: bool = False,
|
43
42
|
) -> Self:
|
44
|
-
"""Read a Configuration from a file.
|
45
|
-
config_dict = loaders.from_file(file_path, loader=loader)
|
46
|
-
return cls(config_dict).initialize(
|
47
|
-
envs=envs, env_prefix=env_prefix, extra_dynamic=extra_dynamic
|
48
|
-
)
|
49
|
-
|
50
|
-
def initialize(
|
51
|
-
self,
|
52
|
-
envs: dict[str, str] | None = None,
|
53
|
-
env_prefix: str = "",
|
54
|
-
extra_dynamic: dict[str, Any] | None = None,
|
55
|
-
) -> Self:
|
56
|
-
"""Initialize a configuration.
|
43
|
+
"""Read a Configuration from a file.
|
57
44
|
|
58
|
-
|
45
|
+
If not_exist_ok is True, then a missing file returns an empty
|
46
|
+
configuration. This may be useful if the configuration is potentially
|
47
|
+
populated by environment variables.
|
59
48
|
"""
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
"""Apply a pydantic model to a configuration."""
|
65
|
-
return self.validate_model(model).convert_model(model)
|
49
|
+
config_dict = loaders.from_file(
|
50
|
+
file_path, loader=loader, not_exist_ok=not_exist_ok
|
51
|
+
)
|
52
|
+
return cls(config_dict)
|
66
53
|
|
67
54
|
def __getitem__(self, key: str) -> Any: # noqa: ANN401
|
68
55
|
"""Make sure nested sections have type Configuration."""
|
@@ -172,6 +159,10 @@ class Configuration(UserDict[str, Any]):
|
|
172
159
|
"""Convert data types to match the given model."""
|
173
160
|
return model(**self.data)
|
174
161
|
|
162
|
+
def with_model(self, model: type[ModelT]) -> ModelT:
|
163
|
+
"""Apply a pydantic model to a configuration."""
|
164
|
+
return self.validate_model(model).convert_model(model)
|
165
|
+
|
175
166
|
def to_dict(self) -> dict[str, Any]:
|
176
167
|
"""Dump the configuration into a Python dictionary."""
|
177
168
|
return {
|
@@ -217,9 +208,7 @@ def _get_rich_print() -> Callable[[str], None]: # pragma: no cover
|
|
217
208
|
|
218
209
|
return Console().print
|
219
210
|
except ImportError:
|
220
|
-
|
221
|
-
|
222
|
-
return builtins.print
|
211
|
+
return print
|
223
212
|
|
224
213
|
|
225
214
|
def _print_dict_as_tree(
|
configaroo/loaders/__init__.py
CHANGED
@@ -26,9 +26,14 @@ def loader_names() -> list[str]:
|
|
26
26
|
return sorted(pyplugs.names(PACKAGE))
|
27
27
|
|
28
28
|
|
29
|
-
def from_file(
|
29
|
+
def from_file(
|
30
|
+
path: str | Path, *, loader: str | None = None, not_exist_ok: bool = False
|
31
|
+
) -> dict[str, Any]:
|
30
32
|
"""Load a file using a loader defined by the suffix if necessary."""
|
31
33
|
path = Path(path)
|
34
|
+
if not path.exists() and not_exist_ok:
|
35
|
+
return {}
|
36
|
+
|
32
37
|
loader = path.suffix.lstrip(".") if loader is None else loader
|
33
38
|
try:
|
34
39
|
return load(loader, path=path)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
configaroo/__init__.py,sha256=zlCtdtE7UWy7SWKYq_NfGX0uUvO8l5-xRj1mB1Bn3Ac,412
|
2
|
+
configaroo/configuration.py,sha256=hMo9INlvD3OwjYeK0PJpun8T8x6wfAl8t1ZM2_EaqvY,9823
|
3
|
+
configaroo/exceptions.py,sha256=GfLf3CLfHStiQjvdS7ZAtrKF9gmGL_8biFLayue6J0M,772
|
4
|
+
configaroo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
configaroo/loaders/__init__.py,sha256=XQrFwCMWzQ71ykaZFPmYysDz12y_elPqxWhUMQCsq3s,1076
|
6
|
+
configaroo/loaders/json.py,sha256=fT2Lg4hPM2BuwqrDsP7bcJlepAdmEh2iKU-YVK4KmIA,306
|
7
|
+
configaroo/loaders/toml.py,sha256=jw9U78Lf-GMA8QmGIM8xMBqOhPaa8ITSMAhhN1ZNyng,256
|
8
|
+
configaroo-0.4.0.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
|
9
|
+
configaroo-0.4.0.dist-info/METADATA,sha256=6527XCdJ8w6eo3v693VifE-AzR1ZUw4tCGeSEXAomUs,2672
|
10
|
+
configaroo-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
configaroo-0.4.0.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
|
12
|
+
configaroo-0.4.0.dist-info/RECORD,,
|
@@ -1,12 +0,0 @@
|
|
1
|
-
configaroo/__init__.py,sha256=yNF3fDQx9xXJEXHtJmeYMdqy-Dnk0mHz2-EL590A858,412
|
2
|
-
configaroo/configuration.py,sha256=phBUk_hHRFQb4vCcn6WHfNOnovEmdV6hnotRJkPSz2E,10255
|
3
|
-
configaroo/exceptions.py,sha256=GfLf3CLfHStiQjvdS7ZAtrKF9gmGL_8biFLayue6J0M,772
|
4
|
-
configaroo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
configaroo/loaders/__init__.py,sha256=l2pHeD9PJ3ZQA5xUCq9nfFqw2YhAHLeTe50wvhMmTYA,977
|
6
|
-
configaroo/loaders/json.py,sha256=fT2Lg4hPM2BuwqrDsP7bcJlepAdmEh2iKU-YVK4KmIA,306
|
7
|
-
configaroo/loaders/toml.py,sha256=jw9U78Lf-GMA8QmGIM8xMBqOhPaa8ITSMAhhN1ZNyng,256
|
8
|
-
configaroo-0.3.0.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
|
9
|
-
configaroo-0.3.0.dist-info/METADATA,sha256=spH6HtB45ksEBsjuCJIADFjWabsQQfzTPZvCuMfV8Fk,2672
|
10
|
-
configaroo-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
-
configaroo-0.3.0.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
|
12
|
-
configaroo-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|