configaroo 0.4.1__py3-none-any.whl → 0.5.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 +7 -2
- configaroo/configuration.py +18 -5
- {configaroo-0.4.1.dist-info → configaroo-0.5.0.dist-info}/METADATA +1 -1
- {configaroo-0.4.1.dist-info → configaroo-0.5.0.dist-info}/RECORD +7 -7
- {configaroo-0.4.1.dist-info → configaroo-0.5.0.dist-info}/WHEEL +0 -0
- {configaroo-0.4.1.dist-info → configaroo-0.5.0.dist-info}/licenses/LICENSE +0 -0
- {configaroo-0.4.1.dist-info → configaroo-0.5.0.dist-info}/top_level.txt +0 -0
configaroo/__init__.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
"""Bouncy configuration handling."""
|
2
2
|
|
3
|
-
from configaroo.configuration import
|
3
|
+
from configaroo.configuration import (
|
4
|
+
Configuration,
|
5
|
+
find_pyproject_toml,
|
6
|
+
print_configuration,
|
7
|
+
)
|
4
8
|
from configaroo.exceptions import (
|
5
9
|
ConfigarooError,
|
6
10
|
MissingEnvironmentVariableError,
|
@@ -12,7 +16,8 @@ __all__ = [
|
|
12
16
|
"Configuration",
|
13
17
|
"MissingEnvironmentVariableError",
|
14
18
|
"UnsupportedLoaderError",
|
19
|
+
"find_pyproject_toml",
|
15
20
|
"print_configuration",
|
16
21
|
]
|
17
22
|
|
18
|
-
__version__ = "0.
|
23
|
+
__version__ = "0.5.0"
|
configaroo/configuration.py
CHANGED
@@ -220,16 +220,29 @@ class Configuration(UserDict[str, Any]):
|
|
220
220
|
}
|
221
221
|
|
222
222
|
|
223
|
-
def print_configuration(
|
223
|
+
def print_configuration(
|
224
|
+
config: Configuration | BaseModel, section: str | None = None, indent: int = 4
|
225
|
+
) -> None:
|
224
226
|
"""Pretty print a configuration.
|
225
227
|
|
226
228
|
If rich is installed, then a rich console is used for the printing.
|
227
229
|
"""
|
228
|
-
|
229
|
-
config.model_dump() if isinstance(config, BaseModel) else config
|
230
|
-
indent=indent,
|
231
|
-
_print=_get_rich_print(),
|
230
|
+
cfg = (
|
231
|
+
Configuration(config.model_dump()) if isinstance(config, BaseModel) else config
|
232
232
|
)
|
233
|
+
if section is None:
|
234
|
+
return _print_dict_as_tree(cfg, indent=indent, _print=_get_rich_print())
|
235
|
+
|
236
|
+
cfg_section = cfg.get(section)
|
237
|
+
if cfg_section is None:
|
238
|
+
message = f"'{type(cfg).__name__}' has no section '{section}'"
|
239
|
+
raise KeyError(message) from None
|
240
|
+
|
241
|
+
if isinstance(cfg_section, Configuration):
|
242
|
+
return print_configuration(cfg_section, indent=indent)
|
243
|
+
|
244
|
+
*_, key = section.split(".")
|
245
|
+
return print_configuration(Configuration({key: cfg_section}), indent=indent)
|
233
246
|
|
234
247
|
|
235
248
|
def _get_rich_print() -> Callable[[str], None]: # pragma: no cover
|
@@ -1,12 +1,12 @@
|
|
1
|
-
configaroo/__init__.py,sha256=
|
2
|
-
configaroo/configuration.py,sha256=
|
1
|
+
configaroo/__init__.py,sha256=l22-9ToQKNztSwKyyGs_jUIDJVqS7QoFPwUBrk9vKdg,477
|
2
|
+
configaroo/configuration.py,sha256=1iUFB1hq8423rbz8VPzv7on0s3tTt89d6Ff3o_YcPL0,11407
|
3
3
|
configaroo/exceptions.py,sha256=GfLf3CLfHStiQjvdS7ZAtrKF9gmGL_8biFLayue6J0M,772
|
4
4
|
configaroo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
configaroo/loaders/__init__.py,sha256=XQrFwCMWzQ71ykaZFPmYysDz12y_elPqxWhUMQCsq3s,1076
|
6
6
|
configaroo/loaders/json.py,sha256=fT2Lg4hPM2BuwqrDsP7bcJlepAdmEh2iKU-YVK4KmIA,306
|
7
7
|
configaroo/loaders/toml.py,sha256=jw9U78Lf-GMA8QmGIM8xMBqOhPaa8ITSMAhhN1ZNyng,256
|
8
|
-
configaroo-0.
|
9
|
-
configaroo-0.
|
10
|
-
configaroo-0.
|
11
|
-
configaroo-0.
|
12
|
-
configaroo-0.
|
8
|
+
configaroo-0.5.0.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
|
9
|
+
configaroo-0.5.0.dist-info/METADATA,sha256=GjTfNdCzx3HuH4-WFszmW4kau5_4aXXz5YE2YLV1T5w,2672
|
10
|
+
configaroo-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
configaroo-0.5.0.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
|
12
|
+
configaroo-0.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|