dycw-utilities 0.166.18__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.166.18
3
+ Version: 0.166.19
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=eLNz3cP1mG4UANDG5gmXTTw10EMSDNNxdbNlerf7XNk,61
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=CWrTtzupGxpSsImjDCuVtQ2HcGmF8nHA4W4hGq8WvXY,5688
57
- utilities/pydantic_settings_sops.py,sha256=LWI3NTQP8hSaGkoRbahyqaalF0HuBg7o63-p7boHgpQ,1119
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.18.dist-info/METADATA,sha256=NPBYGvJB7ozKQT3NMI0xHlTtFcCcchzIBb5YmxnoptU,1702
95
- dycw_utilities-0.166.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
96
- dycw_utilities-0.166.18.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
97
- dycw_utilities-0.166.18.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
98
- dycw_utilities-0.166.18.dist-info/RECORD,,
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
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.166.18"
3
+ __version__ = "0.166.19"
@@ -24,7 +24,8 @@ if TYPE_CHECKING:
24
24
  from utilities.types import MaybeSequenceStr, PathLike
25
25
 
26
26
 
27
- type PathLikeOrWithSection = PathLike | tuple[PathLike, MaybeSequenceStr]
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 json in cls.json_files:
65
- match json:
66
- case Path() | str():
67
- yield JsonConfigSettingsSource(settings_cls, json_file=json)
68
- case Path() | str() as file, str() | list() | tuple() as section:
69
- yield JsonConfigSectionSettingsSource(
70
- settings_cls, json_file=file, section=section
71
- )
72
- case never:
73
- assert_never(never)
74
- for toml in cls.toml_files:
75
- match toml:
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 reduce(
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 reduce(
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 reduce(
168
- lambda acc, el: acc.get(el, {}),
169
- always_iterable(self.section),
170
- super().__call__(),
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,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 CustomBaseSettings
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 SOPSConfigSettingsSource(
34
- settings_cls, # pyright: ignore[reportArgumentType],
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
- __all__ = ["SopsBaseSettings"]
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"]