configaroo 0.4.2__tar.gz → 0.5.0__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.
- {configaroo-0.4.2/src/configaroo.egg-info → configaroo-0.5.0}/PKG-INFO +1 -1
- {configaroo-0.4.2 → configaroo-0.5.0}/pyproject.toml +1 -1
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/__init__.py +1 -1
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/configuration.py +18 -5
- {configaroo-0.4.2 → configaroo-0.5.0/src/configaroo.egg-info}/PKG-INFO +1 -1
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_print.py +40 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/LICENSE +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/README.md +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/setup.cfg +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/exceptions.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/loaders/__init__.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/loaders/json.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/loaders/toml.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo/py.typed +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo.egg-info/SOURCES.txt +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo.egg-info/dependency_links.txt +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo.egg-info/requires.txt +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/src/configaroo.egg-info/top_level.txt +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_configuration.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_dynamic.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_environment.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_json.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_loaders.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_toml.py +0 -0
- {configaroo-0.4.2 → configaroo-0.5.0}/tests/test_validation.py +0 -0
@@ -79,7 +79,7 @@ python_version = "3.11"
|
|
79
79
|
strict = true
|
80
80
|
|
81
81
|
[tool.bumpver]
|
82
|
-
current_version = "v0.
|
82
|
+
current_version = "v0.5.0"
|
83
83
|
version_pattern = "vMAJOR.MINOR.PATCH"
|
84
84
|
commit_message = "bump version {old_version} -> {new_version}"
|
85
85
|
tag_message = "{new_version}"
|
@@ -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
|
@@ -54,3 +54,43 @@ def test_printing_of_dynamic_values(
|
|
54
54
|
assert "- number: 42" in lines
|
55
55
|
assert "- phrase: 'The meaning of life is 42'" in lines
|
56
56
|
assert " - format: '<level>{level:<8} testing configaroo</level>'" in lines
|
57
|
+
|
58
|
+
|
59
|
+
def test_printing_of_existing_section(
|
60
|
+
capsys: pytest.CaptureFixture[str], config: Configuration
|
61
|
+
) -> None:
|
62
|
+
"""Test that sections can be printed."""
|
63
|
+
print_configuration(config, section="paths")
|
64
|
+
stdout = capsys.readouterr().out
|
65
|
+
lines = stdout.splitlines()
|
66
|
+
|
67
|
+
assert "- absolute: '/home/configaroo'" in lines
|
68
|
+
assert "- number: 42" not in lines
|
69
|
+
|
70
|
+
|
71
|
+
def test_printing_of_nonexisting_section(config: Configuration) -> None:
|
72
|
+
"""Test that non-existing sections raise an error."""
|
73
|
+
with pytest.raises(KeyError):
|
74
|
+
print_configuration(config, section="nonexisting")
|
75
|
+
|
76
|
+
|
77
|
+
def test_printing_of_values(
|
78
|
+
capsys: pytest.CaptureFixture[str], config: Configuration
|
79
|
+
) -> None:
|
80
|
+
"""Test that individual values can be printed."""
|
81
|
+
print_configuration(config, section="number")
|
82
|
+
stdout = capsys.readouterr().out
|
83
|
+
lines = stdout.splitlines()
|
84
|
+
|
85
|
+
assert lines == ["- number: 42"]
|
86
|
+
|
87
|
+
|
88
|
+
def test_printing_of_nested_sections(
|
89
|
+
capsys: pytest.CaptureFixture[str], config: Configuration
|
90
|
+
) -> None:
|
91
|
+
"""Test that nested sections can be printed."""
|
92
|
+
print_configuration(config, section="nested.deep")
|
93
|
+
stdout = capsys.readouterr().out
|
94
|
+
lines = stdout.splitlines()
|
95
|
+
|
96
|
+
assert lines == ["- sea: 'Marianer'"]
|
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
|
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
|
File without changes
|