configaroo 0.2.3__py3-none-any.whl → 0.3.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
@@ -15,4 +15,4 @@ __all__ = [
15
15
  "print_configuration",
16
16
  ]
17
17
 
18
- __version__ = "0.2.3"
18
+ __version__ = "0.3.0"
@@ -112,8 +112,22 @@ class Configuration(UserDict[str, Any]):
112
112
  cls = type(self)
113
113
  return self | {prefix: cls(self.setdefault(prefix, {})).add(rest, value)}
114
114
 
115
- def add_envs(self, envs: dict[str, str], prefix: str = "") -> Self:
116
- """Add environment variables to configuration."""
115
+ def add_envs(self, envs: dict[str, str] | None = None, prefix: str = "") -> Self:
116
+ """Add environment variables to configuration.
117
+
118
+ If you don't specify which environment variables to read, you'll
119
+ automatically add any that matches a top-level value of the
120
+ configuration.
121
+ """
122
+ if envs is None:
123
+ # Automatically add top-level configuration items
124
+ envs = {
125
+ re.sub(r"\W", "_", key).upper(): key
126
+ for key, value in self.data.items()
127
+ if isinstance(value, str | int | float)
128
+ }
129
+
130
+ # Read environment variables
117
131
  for env, key in envs.items():
118
132
  env_key = f"{prefix}{env}"
119
133
  if env_value := os.getenv(env_key):
@@ -129,7 +143,7 @@ class Configuration(UserDict[str, Any]):
129
143
  cls = type(self)
130
144
  variables = (
131
145
  (self.to_flat_dict() if _include_self else {})
132
- | {"project_path": _find_pyproject_toml()}
146
+ | {"project_path": find_pyproject_toml()}
133
147
  | ({} if extra is None else extra)
134
148
  )
135
149
  parsed = cls(
@@ -196,7 +210,7 @@ def print_configuration(config: Configuration | BaseModel, indent: int = 4) -> N
196
210
  )
197
211
 
198
212
 
199
- def _get_rich_print() -> Callable[[str], None]:
213
+ def _get_rich_print() -> Callable[[str], None]: # pragma: no cover
200
214
  """Initialize a Rich console if Rich is installed, otherwise use built-in print."""
201
215
  try:
202
216
  from rich.console import Console # noqa: PLC0415
@@ -222,13 +236,13 @@ def _print_dict_as_tree(
222
236
  value,
223
237
  indent=indent,
224
238
  current_indent=current_indent + indent,
225
- _print=print,
239
+ _print=_print,
226
240
  )
227
241
  else:
228
242
  _print(" " * current_indent + f"- {key}: {value!r}")
229
243
 
230
244
 
231
- def _find_pyproject_toml(
245
+ def find_pyproject_toml(
232
246
  path: Path | None = None, _file_name: str = "pyproject.toml"
233
247
  ) -> Path:
234
248
  """Find a directory that contains a pyproject.toml file.
@@ -241,7 +255,7 @@ def _find_pyproject_toml(
241
255
  if (path / _file_name).exists() or path == path.parent:
242
256
  return path.resolve()
243
257
 
244
- return _find_pyproject_toml(path.parent, _file_name=_file_name)
258
+ return find_pyproject_toml(path.parent, _file_name=_file_name)
245
259
 
246
260
 
247
261
  def _get_foreign_path() -> Path:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.2.3
3
+ Version: 0.3.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>
@@ -8,7 +8,7 @@ License-Expression: MIT
8
8
  Project-URL: homepage, https://github.com/gahjelle/configaroo
9
9
  Project-URL: github, https://github.com/gahjelle/configaroo
10
10
  Project-URL: issues, https://github.com/gahjelle/configaroo/issues
11
- Project-URL: changelog, https://github.com/gahjelle/configaroo/blob/main/CHANGELOG.md
11
+ Project-URL: changelog, https://github.com/gahjelle/configaroo/releases
12
12
  Keywords: configuration,configuration-management,toml,json
13
13
  Classifier: Development Status :: 5 - Production/Stable
14
14
  Classifier: Intended Audience :: Developers
@@ -1,12 +1,12 @@
1
- configaroo/__init__.py,sha256=Ed1V019MUJ0Kac5NOY43u83axSsl7I1xE5j1DpAKXeI,412
2
- configaroo/configuration.py,sha256=CzKS9zy3VCaCDexF5_DuYIhRIyBs8EVst6full9zM34,9728
1
+ configaroo/__init__.py,sha256=yNF3fDQx9xXJEXHtJmeYMdqy-Dnk0mHz2-EL590A858,412
2
+ configaroo/configuration.py,sha256=phBUk_hHRFQb4vCcn6WHfNOnovEmdV6hnotRJkPSz2E,10255
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=l2pHeD9PJ3ZQA5xUCq9nfFqw2YhAHLeTe50wvhMmTYA,977
6
6
  configaroo/loaders/json.py,sha256=fT2Lg4hPM2BuwqrDsP7bcJlepAdmEh2iKU-YVK4KmIA,306
7
7
  configaroo/loaders/toml.py,sha256=jw9U78Lf-GMA8QmGIM8xMBqOhPaa8ITSMAhhN1ZNyng,256
8
- configaroo-0.2.3.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
9
- configaroo-0.2.3.dist-info/METADATA,sha256=Y9N_zcN5p1jO4pHt1sI_BPX2qT_w9S_2UmdhKj87uyM,2686
10
- configaroo-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- configaroo-0.2.3.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
12
- configaroo-0.2.3.dist-info/RECORD,,
8
+ configaroo-0.3.0.dist-info/licenses/LICENSE,sha256=rdeT6Y5bm0MUaERso7HRWpPj37Y1RD5li2lIQaMNJjc,1090
9
+ configaroo-0.3.0.dist-info/METADATA,sha256=spH6HtB45ksEBsjuCJIADFjWabsQQfzTPZvCuMfV8Fk,2672
10
+ configaroo-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ configaroo-0.3.0.dist-info/top_level.txt,sha256=JVYICl1cWSjvSOZuZMYm976z9lnZaWtHVRSt373QCxg,11
12
+ configaroo-0.3.0.dist-info/RECORD,,