configaroo 0.4.1__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.
Files changed (25) hide show
  1. {configaroo-0.4.1/src/configaroo.egg-info → configaroo-0.5.0}/PKG-INFO +1 -1
  2. {configaroo-0.4.1 → configaroo-0.5.0}/pyproject.toml +1 -1
  3. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/__init__.py +7 -2
  4. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/configuration.py +18 -5
  5. {configaroo-0.4.1 → configaroo-0.5.0/src/configaroo.egg-info}/PKG-INFO +1 -1
  6. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_print.py +40 -0
  7. {configaroo-0.4.1 → configaroo-0.5.0}/LICENSE +0 -0
  8. {configaroo-0.4.1 → configaroo-0.5.0}/README.md +0 -0
  9. {configaroo-0.4.1 → configaroo-0.5.0}/setup.cfg +0 -0
  10. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/exceptions.py +0 -0
  11. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/loaders/__init__.py +0 -0
  12. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/loaders/json.py +0 -0
  13. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/loaders/toml.py +0 -0
  14. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo/py.typed +0 -0
  15. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo.egg-info/SOURCES.txt +0 -0
  16. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo.egg-info/dependency_links.txt +0 -0
  17. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo.egg-info/requires.txt +0 -0
  18. {configaroo-0.4.1 → configaroo-0.5.0}/src/configaroo.egg-info/top_level.txt +0 -0
  19. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_configuration.py +0 -0
  20. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_dynamic.py +0 -0
  21. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_environment.py +0 -0
  22. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_json.py +0 -0
  23. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_loaders.py +0 -0
  24. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_toml.py +0 -0
  25. {configaroo-0.4.1 → configaroo-0.5.0}/tests/test_validation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Bouncy handling of configuration files
5
5
  Author-email: Geir Arne Hjelle <geirarne@gmail.com>
6
6
  Maintainer-email: Geir Arne Hjelle <geirarne@gmail.com>
@@ -79,7 +79,7 @@ python_version = "3.11"
79
79
  strict = true
80
80
 
81
81
  [tool.bumpver]
82
- current_version = "v0.4.1"
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}"
@@ -1,6 +1,10 @@
1
1
  """Bouncy configuration handling."""
2
2
 
3
- from configaroo.configuration import Configuration, print_configuration
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.4.1"
23
+ __version__ = "0.5.0"
@@ -220,16 +220,29 @@ class Configuration(UserDict[str, Any]):
220
220
  }
221
221
 
222
222
 
223
- def print_configuration(config: Configuration | BaseModel, indent: int = 4) -> None:
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
- return _print_dict_as_tree(
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Bouncy handling of configuration files
5
5
  Author-email: Geir Arne Hjelle <geirarne@gmail.com>
6
6
  Maintainer-email: Geir Arne Hjelle <geirarne@gmail.com>
@@ -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