dycw-utilities 0.166.18__py3-none-any.whl → 0.166.20__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.
- {dycw_utilities-0.166.18.dist-info → dycw_utilities-0.166.20.dist-info}/METADATA +1 -1
- {dycw_utilities-0.166.18.dist-info → dycw_utilities-0.166.20.dist-info}/RECORD +8 -8
- utilities/__init__.py +1 -1
- utilities/pydantic_settings.py +33 -46
- utilities/pydantic_settings_sops.py +33 -9
- {dycw_utilities-0.166.18.dist-info → dycw_utilities-0.166.20.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.166.18.dist-info → dycw_utilities-0.166.20.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.166.18.dist-info → dycw_utilities-0.166.20.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=wFLNw_MUiq5E5vrdStiHh7DVtvzDz9og48O0o8oqaew,61
|
2
2
|
utilities/aeventkit.py,sha256=ddoleSwW9zdc2tjX5Ge0pMKtYwV_JMxhHYOxnWX2AGM,12609
|
3
3
|
utilities/altair.py,sha256=nHdpWt8ZwdUwRQN970MvHd5bRWokNqzHcZQEdSHKRuE,9033
|
4
4
|
utilities/asyncio.py,sha256=PUedzQ5deqlSECQ33sam9cRzI9TnygHz3FdOqWJWPTM,15288
|
@@ -53,8 +53,8 @@ utilities/pottery.py,sha256=ggMN72Y7wx7Js8VN6eyNyodpm8TIYqZHGghkDPXIVWk,3949
|
|
53
53
|
utilities/pqdm.py,sha256=idv2seRVP2f6NeSfpeEnT5A-tQezaHZKDyeu16g2-0E,3091
|
54
54
|
utilities/psutil.py,sha256=KUlu4lrUw9Zg1V7ZGetpWpGb9DB8l_SSDWGbANFNCPU,2104
|
55
55
|
utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
56
|
-
utilities/pydantic_settings.py,sha256=
|
57
|
-
utilities/pydantic_settings_sops.py,sha256=
|
56
|
+
utilities/pydantic_settings.py,sha256=bFr9UDrVhdqTl7O_TPutCLdsQ5rUp--nO76-_F8z0bs,5102
|
57
|
+
utilities/pydantic_settings_sops.py,sha256=m2uB9wDw1PU2CiSL7KwxulDXT0STjOZTu3Ctc2q7jc0,1943
|
58
58
|
utilities/pyinstrument.py,sha256=hnXaL-4HE7wWBI5JKaPfYTpsrXe68YiuZKahHV0VJn8,841
|
59
59
|
utilities/pytest.py,sha256=Pu8jmeNQq659uQmZsmFj6lb0sHMDsNN3fcd6M21J-ww,7723
|
60
60
|
utilities/pytest_regressions.py,sha256=ocjHTtfOeiGfQAKIei8pKNd61sxN9dawrJJ9gPt2wzA,4097
|
@@ -91,8 +91,8 @@ utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
|
|
91
91
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
92
92
|
utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
|
93
93
|
utilities/pytest_plugins/pytest_regressions.py,sha256=9v8kAXDM2ycIXJBimoiF4EgrwbUvxTycFWJiGR_GHhM,1466
|
94
|
-
dycw_utilities-0.166.
|
95
|
-
dycw_utilities-0.166.
|
96
|
-
dycw_utilities-0.166.
|
97
|
-
dycw_utilities-0.166.
|
98
|
-
dycw_utilities-0.166.
|
94
|
+
dycw_utilities-0.166.20.dist-info/METADATA,sha256=3JiFhAm75CwYgZNGBSHz8eGLiY7oUcWdnCiu_T_6XqI,1702
|
95
|
+
dycw_utilities-0.166.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
96
|
+
dycw_utilities-0.166.20.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
97
|
+
dycw_utilities-0.166.20.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
98
|
+
dycw_utilities-0.166.20.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/pydantic_settings.py
CHANGED
@@ -24,7 +24,8 @@ if TYPE_CHECKING:
|
|
24
24
|
from utilities.types import MaybeSequenceStr, PathLike
|
25
25
|
|
26
26
|
|
27
|
-
type
|
27
|
+
type PathLikeWithSection = tuple[PathLike, MaybeSequenceStr]
|
28
|
+
type PathLikeOrWithSection = PathLike | PathLikeWithSection
|
28
29
|
|
29
30
|
|
30
31
|
class CustomBaseSettings(BaseSettings):
|
@@ -61,36 +62,18 @@ class CustomBaseSettings(BaseSettings):
|
|
61
62
|
/,
|
62
63
|
) -> Iterator[PydanticBaseSettingsSource]:
|
63
64
|
yield env_settings
|
64
|
-
for
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
case Path() | str():
|
77
|
-
yield TomlConfigSettingsSource(settings_cls, toml_file=toml)
|
78
|
-
case Path() | str() as file, str() | list() | tuple() as section:
|
79
|
-
yield TomlConfigSectionSettingsSource(
|
80
|
-
settings_cls, toml_file=file, section=section
|
81
|
-
)
|
82
|
-
case never:
|
83
|
-
assert_never(never)
|
84
|
-
for yaml in cls.yaml_files:
|
85
|
-
match yaml:
|
86
|
-
case Path() | str():
|
87
|
-
yield YamlConfigSettingsSource(settings_cls, yaml_file=yaml)
|
88
|
-
case Path() | str() as file, str() | list() | tuple() as section:
|
89
|
-
yield YamlConfigSectionSettingsSource(
|
90
|
-
settings_cls, yaml_file=file, section=section
|
91
|
-
)
|
92
|
-
case never:
|
93
|
-
assert_never(never)
|
65
|
+
for file, section in map(_ensure_section, cls.json_files):
|
66
|
+
yield JsonConfigSectionSettingsSource(
|
67
|
+
settings_cls, json_file=file, section=section
|
68
|
+
)
|
69
|
+
for file, section in map(_ensure_section, cls.toml_files):
|
70
|
+
yield TomlConfigSectionSettingsSource(
|
71
|
+
settings_cls, toml_file=file, section=section
|
72
|
+
)
|
73
|
+
for file, section in map(_ensure_section, cls.yaml_files):
|
74
|
+
yield YamlConfigSectionSettingsSource(
|
75
|
+
settings_cls, yaml_file=file, section=section
|
76
|
+
)
|
94
77
|
|
95
78
|
|
96
79
|
def load_settings[T: BaseSettings](cls: type[T], /) -> T:
|
@@ -115,11 +98,7 @@ class JsonConfigSectionSettingsSource(JsonConfigSettingsSource):
|
|
115
98
|
|
116
99
|
@override
|
117
100
|
def __call__(self) -> dict[str, Any]:
|
118
|
-
return
|
119
|
-
lambda acc, el: acc.get(el, {}),
|
120
|
-
always_iterable(self.section),
|
121
|
-
super().__call__(),
|
122
|
-
)
|
101
|
+
return _get_section(super().__call__(), self.section)
|
123
102
|
|
124
103
|
|
125
104
|
class TomlConfigSectionSettingsSource(TomlConfigSettingsSource):
|
@@ -136,11 +115,7 @@ class TomlConfigSectionSettingsSource(TomlConfigSettingsSource):
|
|
136
115
|
|
137
116
|
@override
|
138
117
|
def __call__(self) -> dict[str, Any]:
|
139
|
-
return
|
140
|
-
lambda acc, el: acc.get(el, {}),
|
141
|
-
always_iterable(self.section),
|
142
|
-
super().__call__(),
|
143
|
-
)
|
118
|
+
return _get_section(super().__call__(), self.section)
|
144
119
|
|
145
120
|
|
146
121
|
class YamlConfigSectionSettingsSource(YamlConfigSettingsSource):
|
@@ -164,11 +139,23 @@ class YamlConfigSectionSettingsSource(YamlConfigSettingsSource):
|
|
164
139
|
|
165
140
|
@override
|
166
141
|
def __call__(self) -> dict[str, Any]:
|
167
|
-
return
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
142
|
+
return _get_section(super().__call__(), self.section)
|
143
|
+
|
144
|
+
|
145
|
+
def _ensure_section(file: PathLikeOrWithSection, /) -> PathLikeWithSection:
|
146
|
+
match file:
|
147
|
+
case Path() | str():
|
148
|
+
return file, []
|
149
|
+
case Path() | str() as path, str() | list() | tuple() as section:
|
150
|
+
return path, section
|
151
|
+
case never:
|
152
|
+
assert_never(never)
|
153
|
+
|
154
|
+
|
155
|
+
def _get_section(
|
156
|
+
mapping: dict[str, Any], section: MaybeSequenceStr, /
|
157
|
+
) -> dict[str, Any]:
|
158
|
+
return reduce(lambda acc, el: acc.get(el, {}), always_iterable(section), mapping)
|
172
159
|
|
173
160
|
|
174
161
|
__all__ = [
|
@@ -1,24 +1,31 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import TYPE_CHECKING, ClassVar, override
|
3
|
+
from typing import TYPE_CHECKING, Any, ClassVar, override
|
4
4
|
|
5
|
+
from pydantic_settings.sources import DEFAULT_PATH
|
5
6
|
from pydantic_settings_sops import SOPSConfigSettingsSource
|
6
7
|
|
7
|
-
from utilities.pydantic_settings import
|
8
|
+
from utilities.pydantic_settings import (
|
9
|
+
CustomBaseSettings,
|
10
|
+
PathLikeOrWithSection,
|
11
|
+
_ensure_section,
|
12
|
+
_get_section,
|
13
|
+
)
|
8
14
|
|
9
15
|
if TYPE_CHECKING:
|
10
16
|
from collections.abc import Iterator, Sequence
|
11
17
|
|
12
18
|
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource
|
19
|
+
from pydantic_settings.sources import PathType
|
13
20
|
|
14
|
-
from utilities.types import
|
21
|
+
from utilities.types import MaybeSequenceStr
|
15
22
|
|
16
23
|
|
17
24
|
class SopsBaseSettings(CustomBaseSettings):
|
18
25
|
"""Base settings for loading secrets using `sops/age`."""
|
19
26
|
|
20
27
|
# paths
|
21
|
-
secret_files: ClassVar[Sequence[
|
28
|
+
secret_files: ClassVar[Sequence[PathLikeOrWithSection]] = []
|
22
29
|
|
23
30
|
@classmethod
|
24
31
|
@override
|
@@ -29,11 +36,28 @@ class SopsBaseSettings(CustomBaseSettings):
|
|
29
36
|
/,
|
30
37
|
) -> Iterator[PydanticBaseSettingsSource]:
|
31
38
|
yield from super()._yield_base_settings_sources(settings_cls, env_settings)
|
32
|
-
for file in cls.secret_files:
|
33
|
-
yield
|
34
|
-
settings_cls,
|
35
|
-
json_file=file,
|
39
|
+
for file, section in map(_ensure_section, cls.secret_files):
|
40
|
+
yield SOPSConfigSectionSettingsSource(
|
41
|
+
settings_cls, json_file=file, section=section
|
36
42
|
)
|
37
43
|
|
38
44
|
|
39
|
-
|
45
|
+
class SOPSConfigSectionSettingsSource(SOPSConfigSettingsSource):
|
46
|
+
@override
|
47
|
+
def __init__(
|
48
|
+
self,
|
49
|
+
settings_cls: type[BaseSettings],
|
50
|
+
json_file: PathType | None = DEFAULT_PATH,
|
51
|
+
yaml_file: PathType | None = DEFAULT_PATH,
|
52
|
+
*,
|
53
|
+
section: MaybeSequenceStr,
|
54
|
+
) -> None:
|
55
|
+
super().__init__(settings_cls, json_file=json_file, yaml_file=yaml_file) # pyright: ignore[reportArgumentType]
|
56
|
+
self.section = section
|
57
|
+
|
58
|
+
@override
|
59
|
+
def __call__(self) -> dict[str, Any]:
|
60
|
+
return _get_section(super().__call__(), self.section)
|
61
|
+
|
62
|
+
|
63
|
+
__all__ = ["SOPSConfigSectionSettingsSource", "SopsBaseSettings"]
|
File without changes
|
File without changes
|
File without changes
|