configaroo 0.2.4__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 +1 -1
- configaroo/configuration.py +20 -6
- {configaroo-0.2.4.dist-info → configaroo-0.3.0.dist-info}/METADATA +1 -1
- {configaroo-0.2.4.dist-info → configaroo-0.3.0.dist-info}/RECORD +7 -7
- {configaroo-0.2.4.dist-info → configaroo-0.3.0.dist-info}/WHEEL +0 -0
- {configaroo-0.2.4.dist-info → configaroo-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {configaroo-0.2.4.dist-info → configaroo-0.3.0.dist-info}/top_level.txt +0 -0
configaroo/__init__.py
CHANGED
configaroo/configuration.py
CHANGED
@@ -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":
|
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
|
@@ -228,7 +242,7 @@ def _print_dict_as_tree(
|
|
228
242
|
_print(" " * current_indent + f"- {key}: {value!r}")
|
229
243
|
|
230
244
|
|
231
|
-
def
|
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
|
258
|
+
return find_pyproject_toml(path.parent, _file_name=_file_name)
|
245
259
|
|
246
260
|
|
247
261
|
def _get_foreign_path() -> Path:
|
@@ -1,12 +1,12 @@
|
|
1
|
-
configaroo/__init__.py,sha256=
|
2
|
-
configaroo/configuration.py,sha256=
|
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.
|
9
|
-
configaroo-0.
|
10
|
-
configaroo-0.
|
11
|
-
configaroo-0.
|
12
|
-
configaroo-0.
|
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,,
|
File without changes
|
File without changes
|
File without changes
|