dycw-utilities 0.166.6__py3-none-any.whl → 0.166.8__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.6
3
+ Version: 0.166.8
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=jnzehUZENuJc0jPB4e9Pclf6K2P3C9PnRF8pxKW7pSk,60
1
+ utilities/__init__.py,sha256=fFrEL9EmgV3dY4nJSDcboyi12XOnBn3cAj916HNt6W8,60
2
2
  utilities/aeventkit.py,sha256=ddoleSwW9zdc2tjX5Ge0pMKtYwV_JMxhHYOxnWX2AGM,12609
3
3
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
4
4
  utilities/asyncio.py,sha256=PUedzQ5deqlSECQ33sam9cRzI9TnygHz3FdOqWJWPTM,15288
@@ -19,6 +19,7 @@ utilities/fpdf2.py,sha256=dSiYz0FJTD2sQuxpxqFWwwIe2-p6Y7oTB9Tv0Jajit0,1866
19
19
  utilities/functions.py,sha256=82qCAaPIB0JmZ5wsQurA3MTYl7fh8LHcoBFkxPs7Zeg,21478
20
20
  utilities/functools.py,sha256=I00ru2gQPakZw2SHVeKIKXfTv741655s6HI0lUoE0D4,1552
21
21
  utilities/getpass.py,sha256=DfN5UgMAtFCqS3dSfFHUfqIMZX2shXvwphOz_6J6f6A,103
22
+ utilities/git.py,sha256=U1RFvCTANGENgx9wVBDvllioqBQZM2ns12ivKhOsaO4,414
22
23
  utilities/gzip.py,sha256=fkGP3KdsBfXlstodT4wtlp-PwNyUsogpbDCVVVGdsm4,781
23
24
  utilities/hashlib.py,sha256=SVTgtguur0P4elppvzOBbLEjVM3Pea0eWB61yg2ilxo,309
24
25
  utilities/http.py,sha256=TsavEfHlRtlLaeV21Z6KZh0qbPw-kvD1zsQdZ7Kep5Q,977
@@ -52,6 +53,8 @@ utilities/pottery.py,sha256=ggMN72Y7wx7Js8VN6eyNyodpm8TIYqZHGghkDPXIVWk,3949
52
53
  utilities/pqdm.py,sha256=idv2seRVP2f6NeSfpeEnT5A-tQezaHZKDyeu16g2-0E,3091
53
54
  utilities/psutil.py,sha256=KUlu4lrUw9Zg1V7ZGetpWpGb9DB8l_SSDWGbANFNCPU,2104
54
55
  utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
+ utilities/pydantic_settings.py,sha256=tn14i1_plfSy6VG62wLiJylOiccE4_UIcvyhGeRp-fk,1700
57
+ utilities/pydantic_settings_sops.py,sha256=3RGZbRgfJjAxveMUNpdf7TNBtGuEBYZZ5_TkIxf1mNE,1194
55
58
  utilities/pyinstrument.py,sha256=hnXaL-4HE7wWBI5JKaPfYTpsrXe68YiuZKahHV0VJn8,841
56
59
  utilities/pytest.py,sha256=M-Om6b3hpF9W_bEB7UFY2IzBCubSxzVQleGrgRXHtxY,7741
57
60
  utilities/pytest_regressions.py,sha256=ocjHTtfOeiGfQAKIei8pKNd61sxN9dawrJJ9gPt2wzA,4097
@@ -88,8 +91,8 @@ utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
88
91
  utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
89
92
  utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
90
93
  utilities/pytest_plugins/pytest_regressions.py,sha256=9v8kAXDM2ycIXJBimoiF4EgrwbUvxTycFWJiGR_GHhM,1466
91
- dycw_utilities-0.166.6.dist-info/METADATA,sha256=gNHhNw7oKEF697GuPgRQuCeflcOuFFFnvUIRz0bdQyo,1696
92
- dycw_utilities-0.166.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- dycw_utilities-0.166.6.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
94
- dycw_utilities-0.166.6.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.166.6.dist-info/RECORD,,
94
+ dycw_utilities-0.166.8.dist-info/METADATA,sha256=4bXWGHpDAouQIDRhGpd8kgM_NErCZJI8AmiUgLeR4HQ,1696
95
+ dycw_utilities-0.166.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
96
+ dycw_utilities-0.166.8.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
97
+ dycw_utilities-0.166.8.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
98
+ dycw_utilities-0.166.8.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.166.6"
3
+ __version__ = "0.166.8"
utilities/git.py ADDED
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import TYPE_CHECKING
5
+
6
+ from git import Repo
7
+
8
+ from utilities.pathlib import to_path
9
+
10
+ if TYPE_CHECKING:
11
+ from utilities.types import MaybeCallablePathLike
12
+
13
+
14
+ def get_repo(path: MaybeCallablePathLike = Path.cwd, /) -> Repo:
15
+ """Get the repo object."""
16
+ return Repo(to_path(path), search_parent_directories=True)
17
+
18
+
19
+ __all__ = ["get_repo"]
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, ClassVar, override
4
+
5
+ from pydantic_settings import (
6
+ BaseSettings,
7
+ JsonConfigSettingsSource,
8
+ PydanticBaseSettingsSource,
9
+ SettingsConfigDict,
10
+ )
11
+
12
+ from utilities.iterables import always_iterable
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Iterator
16
+
17
+ from utilities.types import MaybeIterable, PathLike
18
+
19
+
20
+ class CustomBaseSettings(BaseSettings):
21
+ """Base settings for loading JSON files."""
22
+
23
+ # paths
24
+ json_files: ClassVar[MaybeIterable[PathLike]] = ()
25
+
26
+ # config
27
+ model_config = SettingsConfigDict(env_nested_delimiter="__")
28
+
29
+ @classmethod
30
+ @override
31
+ def settings_customise_sources(
32
+ cls,
33
+ settings_cls: type[BaseSettings],
34
+ init_settings: PydanticBaseSettingsSource,
35
+ env_settings: PydanticBaseSettingsSource,
36
+ dotenv_settings: PydanticBaseSettingsSource,
37
+ file_secret_settings: PydanticBaseSettingsSource,
38
+ ) -> tuple[PydanticBaseSettingsSource, ...]:
39
+ _ = (init_settings, dotenv_settings, file_secret_settings)
40
+ return tuple(cls._yield_base_settings_sources(settings_cls, env_settings))
41
+
42
+ @classmethod
43
+ def _yield_base_settings_sources(
44
+ cls,
45
+ settings_cls: type[BaseSettings],
46
+ env_settings: PydanticBaseSettingsSource,
47
+ /,
48
+ ) -> Iterator[PydanticBaseSettingsSource]:
49
+ yield env_settings
50
+ for file in always_iterable(cls.json_files):
51
+ yield JsonConfigSettingsSource(settings_cls, json_file=file)
52
+
53
+
54
+ def load_settings[T: BaseSettings](cls: type[T], /) -> T:
55
+ """Load a set of settings."""
56
+ return cls()
57
+
58
+
59
+ __all__ = ["CustomBaseSettings", "load_settings"]
@@ -0,0 +1,40 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, ClassVar, override
4
+
5
+ from pydantic_settings_sops import SOPSConfigSettingsSource
6
+
7
+ from utilities.iterables import always_iterable
8
+ from utilities.pydantic_settings import CustomBaseSettings
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import Iterator
12
+
13
+ from pydantic_settings import BaseSettings, PydanticBaseSettingsSource
14
+
15
+ from utilities.types import MaybeIterable, PathLike
16
+
17
+
18
+ class SopsBaseSettings(CustomBaseSettings):
19
+ """Base settings for loading secrets using `sops/age`."""
20
+
21
+ # paths
22
+ secret_files: ClassVar[MaybeIterable[PathLike]] = ()
23
+
24
+ @classmethod
25
+ @override
26
+ def _yield_base_settings_sources(
27
+ cls,
28
+ settings_cls: type[BaseSettings],
29
+ env_settings: PydanticBaseSettingsSource,
30
+ /,
31
+ ) -> Iterator[PydanticBaseSettingsSource]:
32
+ yield from super()._yield_base_settings_sources(settings_cls, env_settings)
33
+ for file in always_iterable(cls.secret_files):
34
+ yield SOPSConfigSettingsSource(
35
+ settings_cls, # pyright: ignore[reportArgumentType],
36
+ json_file=file,
37
+ )
38
+
39
+
40
+ __all__ = ["SopsBaseSettings"]