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 CHANGED
@@ -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>
@@ -1,12 +1,12 @@
1
- configaroo/__init__.py,sha256=yTD0mUdvhepcJSiLEBKTPDuQh8BWjrKnTB1QSfmjHRw,412
2
- configaroo/configuration.py,sha256=1tGBLkyz703txcaGx49kWHMiVYgjTcERnikVQ69Pusc,10928
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.4.1.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
9
- configaroo-0.4.1.dist-info/METADATA,sha256=U_sK60hkeYLqI5gEjv6UoG1l1r3w3pKhhADB4kfXqDQ,2672
10
- configaroo-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- configaroo-0.4.1.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
12
- configaroo-0.4.1.dist-info/RECORD,,
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,,