dycw-utilities 0.109.4__py3-none-any.whl → 0.109.5__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.109.4.dist-info → dycw_utilities-0.109.5.dist-info}/METADATA +1 -1
- {dycw_utilities-0.109.4.dist-info → dycw_utilities-0.109.5.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/dataclasses.py +12 -5
- utilities/python_dotenv.py +8 -3
- {dycw_utilities-0.109.4.dist-info → dycw_utilities-0.109.5.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.109.4.dist-info → dycw_utilities-0.109.5.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=WUcAfLjgcNNeAm9q3alKWOcT4CjZ3liYuA1SFSky9Ng,60
|
2
2
|
utilities/altair.py,sha256=NSyDsm8QlkAGmsGdxVwCkHnPxt_35yJBa9Lg7bz9Ays,9054
|
3
3
|
utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
|
4
4
|
utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
|
@@ -11,7 +11,7 @@ utilities/contextlib.py,sha256=OOIIEa5lXKGzFAnauaul40nlQnQko6Na4ryiMJcHkIg,478
|
|
11
11
|
utilities/contextvars.py,sha256=RsSGGrbQqqZ67rOydnM7WWIsM2lIE31UHJLejnHJPWY,505
|
12
12
|
utilities/cryptography.py,sha256=HyOewI20cl3uRXsKivhIaeLVDInQdzgXZGaly7hS5dE,771
|
13
13
|
utilities/cvxpy.py,sha256=Rv1-fD-XYerosCavRF8Pohop2DBkU3AlFaGTfD8AEAA,13776
|
14
|
-
utilities/dataclasses.py,sha256=
|
14
|
+
utilities/dataclasses.py,sha256=Rh5QajjwyXGpQqndeOFRT-VnPJXF0jWI515GjCSprS0,23326
|
15
15
|
utilities/datetime.py,sha256=GOs-MIEW_A49kzqa1yhIoeNeSqqPVgGO-h2AThtgTDk,37326
|
16
16
|
utilities/enum.py,sha256=HoRwVCWzsnH0vpO9ZEcAAIZLMv0Sn2vJxxA4sYMQgDs,5793
|
17
17
|
utilities/errors.py,sha256=BtSNP0JC3ik536ddPyTerLomCRJV9f6kdMe6POz0QHM,361
|
@@ -53,7 +53,7 @@ utilities/pyinstrument.py,sha256=ROq2txPwbe2ZUuYJ2IDNbfT97lu2ca0v5_C_yn6sSlM,800
|
|
53
53
|
utilities/pyrsistent.py,sha256=TLJfiiKO4cKNU_pCoM3zDqmSM421qpuoaeaBNnyC_Ac,2489
|
54
54
|
utilities/pytest.py,sha256=85QUax4g2VBBAqAHtM9wekcSLB7_9O8AKFTaCshztL8,7989
|
55
55
|
utilities/pytest_regressions.py,sha256=-SVT9647Dg6-JcdsiaDKXe3NdOmmrvGevLKWwGjxq3c,5088
|
56
|
-
utilities/python_dotenv.py,sha256=
|
56
|
+
utilities/python_dotenv.py,sha256=ZIz45FjpwoMs5fdYr9kRM6f4qEp2GNM5rKLnrRe8_7c,3218
|
57
57
|
utilities/random.py,sha256=lYdjgxB7GCfU_fwFVl5U-BIM_HV3q6_urL9byjrwDM8,4157
|
58
58
|
utilities/re.py,sha256=5J4d8VwIPFVrX2Eb8zfoxImDv7IwiN_U7mJ07wR2Wvs,3958
|
59
59
|
utilities/redis.py,sha256=CsDQqc9V6ASLzLQwtbQXZQEndyG9pJiCOhPlPeszt7Y,21203
|
@@ -84,7 +84,7 @@ utilities/warnings.py,sha256=yUgjnmkCRf6QhdyAXzl7u0qQFejhQG3PrjoSwxpbHrs,1819
|
|
84
84
|
utilities/whenever.py,sha256=5x2t47VJmJRWcd_NLFy54NkB3uom-XQYxEbLtEfL1bs,17775
|
85
85
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
86
86
|
utilities/zoneinfo.py,sha256=-DQz5a0Ikw9jfSZtL0BEQkXOMC9yGn_xiJYNCLMiqEc,1989
|
87
|
-
dycw_utilities-0.109.
|
88
|
-
dycw_utilities-0.109.
|
89
|
-
dycw_utilities-0.109.
|
90
|
-
dycw_utilities-0.109.
|
87
|
+
dycw_utilities-0.109.5.dist-info/METADATA,sha256=MlQJX_ZNWyT78qMBJR7P1Evz8nzMaBTjTR3PYh2v07A,13004
|
88
|
+
dycw_utilities-0.109.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
89
|
+
dycw_utilities-0.109.5.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
90
|
+
dycw_utilities-0.109.5.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/dataclasses.py
CHANGED
@@ -453,7 +453,8 @@ def text_to_dataclass(
|
|
453
453
|
warn_name_errors: bool = False,
|
454
454
|
head: bool = False,
|
455
455
|
case_sensitive: bool = False,
|
456
|
-
|
456
|
+
allow_extra_keys: bool = False,
|
457
|
+
extra_parsers: Mapping[type[_T], Callable[[str], _T]] | None = None,
|
457
458
|
) -> TDataclass:
|
458
459
|
"""Construct a dataclass from a string or a mapping or strings."""
|
459
460
|
match text_or_mapping:
|
@@ -477,10 +478,12 @@ def text_to_dataclass(
|
|
477
478
|
warn_name_errors=warn_name_errors,
|
478
479
|
head=head,
|
479
480
|
case_sensitive=case_sensitive,
|
480
|
-
allow_extra=
|
481
|
+
allow_extra=allow_extra_keys,
|
481
482
|
)
|
482
483
|
field_names_to_values = {
|
483
|
-
f.name: _text_to_dataclass_parse(
|
484
|
+
f.name: _text_to_dataclass_parse(
|
485
|
+
f, t, cls, head=head, case_sensitive=case_sensitive, extra=extra_parsers
|
486
|
+
)
|
484
487
|
for f, t in fields_to_serializes.items()
|
485
488
|
}
|
486
489
|
return mapping_to_dataclass(
|
@@ -492,7 +495,7 @@ def text_to_dataclass(
|
|
492
495
|
warn_name_errors=warn_name_errors,
|
493
496
|
head=head,
|
494
497
|
case_sensitive=case_sensitive,
|
495
|
-
allow_extra=
|
498
|
+
allow_extra=allow_extra_keys,
|
496
499
|
)
|
497
500
|
|
498
501
|
|
@@ -519,10 +522,14 @@ def _text_to_dataclass_parse(
|
|
519
522
|
cls: type[Dataclass],
|
520
523
|
/,
|
521
524
|
*,
|
525
|
+
head: bool = False,
|
522
526
|
case_sensitive: bool = False,
|
527
|
+
extra: Mapping[type[_T], Callable[[str], _T]] | None = None,
|
523
528
|
) -> Any:
|
524
529
|
try:
|
525
|
-
return parse_text(
|
530
|
+
return parse_text(
|
531
|
+
field.type_, text, head=head, case_sensitive=case_sensitive, extra=extra
|
532
|
+
)
|
526
533
|
except ParseTextError:
|
527
534
|
raise _TextToDataClassParseValueError(cls=cls, field=field, text=text) from None
|
528
535
|
|
utilities/python_dotenv.py
CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
from dataclasses import dataclass
|
4
4
|
from os import environ
|
5
|
-
from typing import TYPE_CHECKING, override
|
5
|
+
from typing import TYPE_CHECKING, TypeVar, override
|
6
6
|
|
7
7
|
from dotenv import dotenv_values
|
8
8
|
|
@@ -13,13 +13,16 @@ from utilities.pathlib import PWD
|
|
13
13
|
from utilities.reprlib import get_repr
|
14
14
|
|
15
15
|
if TYPE_CHECKING:
|
16
|
-
from collections.abc import Mapping
|
16
|
+
from collections.abc import Callable, Mapping
|
17
17
|
from collections.abc import Set as AbstractSet
|
18
18
|
from pathlib import Path
|
19
19
|
|
20
20
|
from utilities.types import PathLike, StrMapping, TDataclass
|
21
21
|
|
22
22
|
|
23
|
+
_T = TypeVar("_T")
|
24
|
+
|
25
|
+
|
23
26
|
def load_settings(
|
24
27
|
cls: type[TDataclass],
|
25
28
|
/,
|
@@ -30,6 +33,7 @@ def load_settings(
|
|
30
33
|
warn_name_errors: bool = False,
|
31
34
|
head: bool = False,
|
32
35
|
case_sensitive: bool = False,
|
36
|
+
extra_parsers: Mapping[type[_T], Callable[[str], _T]] | None = None,
|
33
37
|
) -> TDataclass:
|
34
38
|
"""Load a set of settings from the `.env` file."""
|
35
39
|
path = get_repo_root(cwd=cwd).joinpath(".env")
|
@@ -57,7 +61,8 @@ def load_settings(
|
|
57
61
|
warn_name_errors=warn_name_errors,
|
58
62
|
head=head,
|
59
63
|
case_sensitive=case_sensitive,
|
60
|
-
|
64
|
+
allow_extra_keys=True,
|
65
|
+
extra_parsers=extra_parsers,
|
61
66
|
)
|
62
67
|
except MappingToDataclassError as error:
|
63
68
|
raise _LoadSettingsMissingKeysError(path=path, fields=error.fields) from None
|
File without changes
|
File without changes
|