configaroo 0.5.0__py3-none-any.whl → 0.6.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 CHANGED
@@ -20,4 +20,4 @@ __all__ = [
20
20
  "print_configuration",
21
21
  ]
22
22
 
23
- __version__ = "0.5.0"
23
+ __version__ = "0.6.0"
@@ -155,7 +155,7 @@ class Configuration(UserDict[str, Any]):
155
155
  self,
156
156
  model: type[BaseModel],
157
157
  prefix: str = "",
158
- types: type | UnionType = str | bool | int | float,
158
+ types: type | UnionType = str | bool | int | float, # pyright: ignore[reportArgumentType]
159
159
  ) -> Self:
160
160
  """Add environment variables to configuration based on the given model.
161
161
 
@@ -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
 
@@ -231,7 +235,10 @@ def print_configuration(
231
235
  Configuration(config.model_dump()) if isinstance(config, BaseModel) else config
232
236
  )
233
237
  if section is None:
234
- return _print_dict_as_tree(cfg, indent=indent, _print=_get_rich_print())
238
+ _print, _escape = _get_rich_print()
239
+ return _print_dict_as_tree(
240
+ cfg, skip_none=skip_none, indent=indent, _print=_print, _escape=_escape
241
+ )
235
242
 
236
243
  cfg_section = cfg.get(section)
237
244
  if cfg_section is None:
@@ -239,30 +246,43 @@ def print_configuration(
239
246
  raise KeyError(message) from None
240
247
 
241
248
  if isinstance(cfg_section, Configuration):
242
- return print_configuration(cfg_section, indent=indent)
249
+ return print_configuration(cfg_section, skip_none=skip_none, indent=indent)
243
250
 
244
251
  *_, key = section.split(".")
245
- 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
+ )
246
255
 
247
256
 
248
- def _get_rich_print() -> Callable[[str], None]: # pragma: no cover
249
- """Initialize a Rich console if Rich is installed, otherwise use built-in print."""
257
+ def _get_rich_print() -> tuple[
258
+ Callable[[str], None], Callable[[str], str]
259
+ ]: # pragma: no cover
260
+ """Initialize a Rich console if Rich is installed, otherwise use built-in print.
261
+
262
+ Include a function that can be used to escape markup.
263
+ """
250
264
  try:
251
265
  from rich.console import Console # noqa: PLC0415
266
+ from rich.markup import escape # noqa: PLC0415
252
267
 
253
- return Console().print
268
+ return Console().print, escape
254
269
  except ImportError:
255
- return print
270
+ return print, str
256
271
 
257
272
 
258
273
  def _print_dict_as_tree(
259
274
  data: dict[str, Any] | UserDict[str, Any] | Configuration,
275
+ *,
276
+ skip_none: bool = False,
260
277
  indent: int = 4,
261
278
  current_indent: int = 0,
262
279
  _print: Callable[[str], None] = print,
280
+ _escape: Callable[[str], str] = str,
263
281
  ) -> None:
264
282
  """Print a nested dictionary as a tree."""
265
283
  for key, value in data.items():
284
+ if skip_none and value is None:
285
+ continue
266
286
  if isinstance(value, dict | UserDict | Configuration):
267
287
  _print(" " * current_indent + f"- {key}")
268
288
  _print_dict_as_tree(
@@ -270,9 +290,11 @@ def _print_dict_as_tree(
270
290
  indent=indent,
271
291
  current_indent=current_indent + indent,
272
292
  _print=_print,
293
+ _escape=_escape,
273
294
  )
274
295
  else:
275
- _print(" " * current_indent + f"- {key}: {value!r}")
296
+ escaped_repr = _escape(repr(value))
297
+ _print(" " * current_indent + f"- {key}: {escaped_repr}")
276
298
 
277
299
 
278
300
  def find_pyproject_toml(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.5.0
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>
@@ -33,9 +33,9 @@ Dynamic: license-file
33
33
  [![Python versions](https://img.shields.io/pypi/pyversions/configaroo.svg)](https://pypi.org/project/configaroo/)
34
34
  [![License](https://img.shields.io/pypi/l/configaroo.svg)](https://github.com/gahjelle/configaroo/blob/main/LICENSE)
35
35
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
36
- [![Linted](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml)
36
+ [![Linted with Ruff](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/lint.yml)
37
37
  [![Tested with Pytest](https://github.com/gahjelle/configaroo/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/gahjelle/configaroo/actions/workflows/test.yml)
38
- [![Type checked with mypy](https://img.shields.io/badge/type%20checked-mypy-green)](http://mypy-lang.org/)
38
+ [![Type checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
39
39
 
40
40
  Configaroo is a light configuration package for Python that offers the following features:
41
41
 
@@ -1,12 +1,12 @@
1
- configaroo/__init__.py,sha256=l22-9ToQKNztSwKyyGs_jUIDJVqS7QoFPwUBrk9vKdg,477
2
- configaroo/configuration.py,sha256=1iUFB1hq8423rbz8VPzv7on0s3tTt89d6Ff3o_YcPL0,11407
1
+ configaroo/__init__.py,sha256=6DOyBxg4xOCjHc9qVERA9NZ3VZD0rnKBPPoXaXFKSjY,477
2
+ configaroo/configuration.py,sha256=z8zcdcAONtIE9M1xppf40iOVHfkp4x-TdTzmAUlpt-o,12032
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.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,,
8
+ configaroo-0.6.0.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
9
+ configaroo-0.6.0.dist-info/METADATA,sha256=X4GSPIJMqNWSPufdbS2jgQ5Dma_WJ08ubKP57MsZ6l0,2703
10
+ configaroo-0.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ configaroo-0.6.0.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
12
+ configaroo-0.6.0.dist-info/RECORD,,