configaroo 0.5.1__tar.gz → 0.6.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.5.1/src/configaroo.egg-info → configaroo-0.6.0}/PKG-INFO +1 -1
  2. {configaroo-0.5.1 → configaroo-0.6.0}/pyproject.toml +1 -1
  3. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/__init__.py +1 -1
  4. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/configuration.py +16 -4
  5. {configaroo-0.5.1 → configaroo-0.6.0/src/configaroo.egg-info}/PKG-INFO +1 -1
  6. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_print.py +24 -0
  7. {configaroo-0.5.1 → configaroo-0.6.0}/LICENSE +0 -0
  8. {configaroo-0.5.1 → configaroo-0.6.0}/README.md +0 -0
  9. {configaroo-0.5.1 → configaroo-0.6.0}/setup.cfg +0 -0
  10. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/exceptions.py +0 -0
  11. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/loaders/__init__.py +0 -0
  12. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/loaders/json.py +0 -0
  13. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/loaders/toml.py +0 -0
  14. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo/py.typed +0 -0
  15. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo.egg-info/SOURCES.txt +0 -0
  16. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo.egg-info/dependency_links.txt +0 -0
  17. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo.egg-info/requires.txt +0 -0
  18. {configaroo-0.5.1 → configaroo-0.6.0}/src/configaroo.egg-info/top_level.txt +0 -0
  19. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_configuration.py +0 -0
  20. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_dynamic.py +0 -0
  21. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_environment.py +0 -0
  22. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_json.py +0 -0
  23. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_loaders.py +0 -0
  24. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_toml.py +0 -0
  25. {configaroo-0.5.1 → configaroo-0.6.0}/tests/test_validation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.5.1
3
+ Version: 0.6.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>
@@ -86,7 +86,7 @@ reportUnknownArgumentType = "none"
86
86
  reportUnknownMemberType = "none"
87
87
 
88
88
  [tool.bumpver]
89
- current_version = "v0.5.1"
89
+ current_version = "v0.6.0"
90
90
  version_pattern = "vMAJOR.MINOR.PATCH"
91
91
  commit_message = "bump version {old_version} -> {new_version}"
92
92
  tag_message = "{new_version}"
@@ -20,4 +20,4 @@ __all__ = [
20
20
  "print_configuration",
21
21
  ]
22
22
 
23
- __version__ = "0.5.1"
23
+ __version__ = "0.6.0"
@@ -221,7 +221,11 @@ class Configuration(UserDict[str, Any]):
221
221
 
222
222
 
223
223
  def print_configuration(
224
- config: Configuration | BaseModel, section: str | None = None, indent: int = 4
224
+ config: Configuration | BaseModel,
225
+ section: str | None = None,
226
+ *,
227
+ skip_none: bool = False,
228
+ indent: int = 4,
225
229
  ) -> None:
226
230
  """Pretty print a configuration.
227
231
 
@@ -232,7 +236,9 @@ def print_configuration(
232
236
  )
233
237
  if section is None:
234
238
  _print, _escape = _get_rich_print()
235
- return _print_dict_as_tree(cfg, indent=indent, _print=_print, _escape=_escape)
239
+ return _print_dict_as_tree(
240
+ cfg, skip_none=skip_none, indent=indent, _print=_print, _escape=_escape
241
+ )
236
242
 
237
243
  cfg_section = cfg.get(section)
238
244
  if cfg_section is None:
@@ -240,10 +246,12 @@ def print_configuration(
240
246
  raise KeyError(message) from None
241
247
 
242
248
  if isinstance(cfg_section, Configuration):
243
- return print_configuration(cfg_section, indent=indent)
249
+ return print_configuration(cfg_section, skip_none=skip_none, indent=indent)
244
250
 
245
251
  *_, key = section.split(".")
246
- return print_configuration(Configuration({key: cfg_section}), indent=indent)
252
+ return print_configuration(
253
+ Configuration({key: cfg_section}), skip_none=skip_none, indent=indent
254
+ )
247
255
 
248
256
 
249
257
  def _get_rich_print() -> tuple[
@@ -264,6 +272,8 @@ def _get_rich_print() -> tuple[
264
272
 
265
273
  def _print_dict_as_tree(
266
274
  data: dict[str, Any] | UserDict[str, Any] | Configuration,
275
+ *,
276
+ skip_none: bool = False,
267
277
  indent: int = 4,
268
278
  current_indent: int = 0,
269
279
  _print: Callable[[str], None] = print,
@@ -271,6 +281,8 @@ def _print_dict_as_tree(
271
281
  ) -> None:
272
282
  """Print a nested dictionary as a tree."""
273
283
  for key, value in data.items():
284
+ if skip_none and value is None:
285
+ continue
274
286
  if isinstance(value, dict | UserDict | Configuration):
275
287
  _print(" " * current_indent + f"- {key}")
276
288
  _print_dict_as_tree(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.5.1
3
+ Version: 0.6.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>
@@ -100,3 +100,27 @@ def test_printing_of_rich_markup() -> None:
100
100
  """Test that a config value containing malformed Rich markup can be printed."""
101
101
  config = Configuration({"markup": "[/]"})
102
102
  print_configuration(config)
103
+
104
+
105
+ def test_print_keeping_none(
106
+ capsys: pytest.CaptureFixture[str], config: Configuration
107
+ ) -> None:
108
+ """Test that None-values are kept in printout by default."""
109
+ print_configuration(config | {"none": None})
110
+ stdout = capsys.readouterr().out
111
+ lines = stdout.splitlines()
112
+
113
+ assert "- none: None" in lines
114
+ assert "- number: 42" in lines
115
+
116
+
117
+ def test_print_skipping_none(
118
+ capsys: pytest.CaptureFixture[str], config: Configuration
119
+ ) -> None:
120
+ """Test that None-values are skipped in printout if asked for."""
121
+ print_configuration(config | {"none": None}, skip_none=True)
122
+ stdout = capsys.readouterr().out
123
+ lines = stdout.splitlines()
124
+
125
+ assert "- none: None" not in lines
126
+ assert "- number: 42" in lines
File without changes
File without changes
File without changes