dycw-utilities 0.166.17__py3-none-any.whl → 0.166.19__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.17.dist-info → dycw_utilities-0.166.19.dist-info}/METADATA +1 -1
- {dycw_utilities-0.166.17.dist-info → dycw_utilities-0.166.19.dist-info}/RECORD +8 -8
- utilities/__init__.py +1 -1
- utilities/pydantic_settings.py +83 -22
- utilities/pydantic_settings_sops.py +31 -8
- {dycw_utilities-0.166.17.dist-info → dycw_utilities-0.166.19.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.166.17.dist-info → dycw_utilities-0.166.19.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.166.17.dist-info → dycw_utilities-0.166.19.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=k8myIMc86meItIQjAhmQS8ML5HKIpWmNGFvwEy-C31M,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=lQc0ltEbQvxXoV0GgHZRYsXJh3VZFbk7x6o_lqFmvoU,1913
|
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.19.dist-info/METADATA,sha256=TUp3VLjdjotA6WA4T1UwBqRzudU6iYlKU-5FV0359AQ,1702
|
95
|
+
dycw_utilities-0.166.19.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
96
|
+
dycw_utilities-0.166.19.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
97
|
+
dycw_utilities-0.166.19.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
98
|
+
dycw_utilities-0.166.19.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/pydantic_settings.py
CHANGED
@@ -24,16 +24,17 @@ 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):
|
31
32
|
"""Base settings for loading JSON files."""
|
32
33
|
|
33
34
|
# paths
|
34
|
-
json_files: ClassVar[Sequence[
|
35
|
+
json_files: ClassVar[Sequence[PathLikeOrWithSection]] = []
|
35
36
|
toml_files: ClassVar[Sequence[PathLikeOrWithSection]] = []
|
36
|
-
yaml_files: ClassVar[Sequence[
|
37
|
+
yaml_files: ClassVar[Sequence[PathLikeOrWithSection]] = []
|
37
38
|
|
38
39
|
# config
|
39
40
|
model_config: ClassVar[SettingsConfigDict] = SettingsConfigDict(
|
@@ -61,20 +62,18 @@ class CustomBaseSettings(BaseSettings):
|
|
61
62
|
/,
|
62
63
|
) -> Iterator[PydanticBaseSettingsSource]:
|
63
64
|
yield env_settings
|
64
|
-
for file in cls.json_files:
|
65
|
-
yield
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
for file in cls.yaml_files:
|
77
|
-
yield YamlConfigSettingsSource(settings_cls, yaml_file=file)
|
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
|
+
)
|
78
77
|
|
79
78
|
|
80
79
|
def load_settings[T: BaseSettings](cls: type[T], /) -> T:
|
@@ -82,6 +81,26 @@ def load_settings[T: BaseSettings](cls: type[T], /) -> T:
|
|
82
81
|
return cls()
|
83
82
|
|
84
83
|
|
84
|
+
class JsonConfigSectionSettingsSource(JsonConfigSettingsSource):
|
85
|
+
@override
|
86
|
+
def __init__(
|
87
|
+
self,
|
88
|
+
settings_cls: type[BaseSettings],
|
89
|
+
json_file: PathType | None = DEFAULT_PATH,
|
90
|
+
json_file_encoding: str | None = None,
|
91
|
+
*,
|
92
|
+
section: MaybeSequenceStr,
|
93
|
+
) -> None:
|
94
|
+
super().__init__(
|
95
|
+
settings_cls, json_file=json_file, json_file_encoding=json_file_encoding
|
96
|
+
)
|
97
|
+
self.section = section
|
98
|
+
|
99
|
+
@override
|
100
|
+
def __call__(self) -> dict[str, Any]:
|
101
|
+
return _get_section(super().__call__(), self.section)
|
102
|
+
|
103
|
+
|
85
104
|
class TomlConfigSectionSettingsSource(TomlConfigSettingsSource):
|
86
105
|
@override
|
87
106
|
def __init__(
|
@@ -96,11 +115,53 @@ class TomlConfigSectionSettingsSource(TomlConfigSettingsSource):
|
|
96
115
|
|
97
116
|
@override
|
98
117
|
def __call__(self) -> dict[str, Any]:
|
99
|
-
return
|
100
|
-
|
101
|
-
|
102
|
-
|
118
|
+
return _get_section(super().__call__(), self.section)
|
119
|
+
|
120
|
+
|
121
|
+
class YamlConfigSectionSettingsSource(YamlConfigSettingsSource):
|
122
|
+
@override
|
123
|
+
def __init__(
|
124
|
+
self,
|
125
|
+
settings_cls: type[BaseSettings],
|
126
|
+
yaml_file: PathType | None = DEFAULT_PATH,
|
127
|
+
yaml_file_encoding: str | None = None,
|
128
|
+
yaml_config_section: str | None = None,
|
129
|
+
*,
|
130
|
+
section: MaybeSequenceStr,
|
131
|
+
) -> None:
|
132
|
+
super().__init__(
|
133
|
+
settings_cls,
|
134
|
+
yaml_file=yaml_file,
|
135
|
+
yaml_file_encoding=yaml_file_encoding,
|
136
|
+
yaml_config_section=yaml_config_section,
|
103
137
|
)
|
138
|
+
self.section = section
|
139
|
+
|
140
|
+
@override
|
141
|
+
def __call__(self) -> dict[str, Any]:
|
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)
|
104
159
|
|
105
160
|
|
106
|
-
__all__ = [
|
161
|
+
__all__ = [
|
162
|
+
"CustomBaseSettings",
|
163
|
+
"JsonConfigSectionSettingsSource",
|
164
|
+
"TomlConfigSectionSettingsSource",
|
165
|
+
"YamlConfigSectionSettingsSource",
|
166
|
+
"load_settings",
|
167
|
+
]
|
@@ -1,17 +1,23 @@
|
|
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
|
+
_ensure_section,
|
11
|
+
_get_section,
|
12
|
+
)
|
8
13
|
|
9
14
|
if TYPE_CHECKING:
|
10
15
|
from collections.abc import Iterator, Sequence
|
11
16
|
|
12
17
|
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource
|
18
|
+
from pydantic_settings.sources import PathType
|
13
19
|
|
14
|
-
from utilities.types import PathLike
|
20
|
+
from utilities.types import MaybeSequenceStr, PathLike
|
15
21
|
|
16
22
|
|
17
23
|
class SopsBaseSettings(CustomBaseSettings):
|
@@ -29,11 +35,28 @@ class SopsBaseSettings(CustomBaseSettings):
|
|
29
35
|
/,
|
30
36
|
) -> Iterator[PydanticBaseSettingsSource]:
|
31
37
|
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,
|
38
|
+
for file, section in map(_ensure_section, cls.secret_files):
|
39
|
+
yield SOPSConfigSectionSettingsSource(
|
40
|
+
settings_cls, json_file=file, section=section
|
36
41
|
)
|
37
42
|
|
38
43
|
|
39
|
-
|
44
|
+
class SOPSConfigSectionSettingsSource(SOPSConfigSettingsSource):
|
45
|
+
@override
|
46
|
+
def __init__(
|
47
|
+
self,
|
48
|
+
settings_cls: type[BaseSettings],
|
49
|
+
json_file: PathType | None = DEFAULT_PATH,
|
50
|
+
yaml_file: PathType | None = DEFAULT_PATH,
|
51
|
+
*,
|
52
|
+
section: MaybeSequenceStr,
|
53
|
+
) -> None:
|
54
|
+
super().__init__(settings_cls, json_file=json_file, yaml_file=yaml_file) # pyright: ignore[reportArgumentType]
|
55
|
+
self.section = section
|
56
|
+
|
57
|
+
@override
|
58
|
+
def __call__(self) -> dict[str, Any]:
|
59
|
+
return _get_section(super().__call__(), self.section)
|
60
|
+
|
61
|
+
|
62
|
+
__all__ = ["SOPSConfigSectionSettingsSource", "SopsBaseSettings"]
|
File without changes
|
File without changes
|
File without changes
|