dycw-utilities 0.129.10__py3-none-any.whl → 0.175.17__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.175.17.dist-info/METADATA +34 -0
- dycw_utilities-0.175.17.dist-info/RECORD +103 -0
- dycw_utilities-0.175.17.dist-info/WHEEL +4 -0
- dycw_utilities-0.175.17.dist-info/entry_points.txt +4 -0
- utilities/__init__.py +1 -1
- utilities/altair.py +14 -14
- utilities/asyncio.py +350 -819
- utilities/atomicwrites.py +18 -6
- utilities/atools.py +77 -22
- utilities/cachetools.py +24 -29
- utilities/click.py +393 -237
- utilities/concurrent.py +8 -11
- utilities/contextlib.py +216 -17
- utilities/contextvars.py +20 -1
- utilities/cryptography.py +3 -3
- utilities/dataclasses.py +83 -118
- utilities/docker.py +293 -0
- utilities/enum.py +26 -23
- utilities/errors.py +17 -3
- utilities/fastapi.py +29 -65
- utilities/fpdf2.py +3 -3
- utilities/functions.py +169 -416
- utilities/functools.py +18 -19
- utilities/git.py +9 -30
- utilities/grp.py +28 -0
- utilities/gzip.py +31 -0
- utilities/http.py +3 -2
- utilities/hypothesis.py +738 -589
- utilities/importlib.py +17 -1
- utilities/inflect.py +25 -0
- utilities/iterables.py +194 -262
- utilities/jinja2.py +148 -0
- utilities/json.py +70 -0
- utilities/libcst.py +38 -17
- utilities/lightweight_charts.py +5 -9
- utilities/logging.py +345 -543
- utilities/math.py +18 -13
- utilities/memory_profiler.py +11 -15
- utilities/more_itertools.py +200 -131
- utilities/operator.py +33 -29
- utilities/optuna.py +6 -6
- utilities/orjson.py +272 -137
- utilities/os.py +61 -4
- utilities/parse.py +59 -61
- utilities/pathlib.py +281 -40
- utilities/permissions.py +298 -0
- utilities/pickle.py +2 -2
- utilities/platform.py +24 -5
- utilities/polars.py +1214 -430
- utilities/polars_ols.py +1 -1
- utilities/postgres.py +408 -0
- utilities/pottery.py +113 -26
- utilities/pqdm.py +10 -11
- utilities/psutil.py +6 -57
- utilities/pwd.py +28 -0
- utilities/pydantic.py +4 -54
- utilities/pydantic_settings.py +240 -0
- utilities/pydantic_settings_sops.py +76 -0
- utilities/pyinstrument.py +8 -10
- utilities/pytest.py +227 -121
- utilities/pytest_plugins/__init__.py +1 -0
- utilities/pytest_plugins/pytest_randomly.py +23 -0
- utilities/pytest_plugins/pytest_regressions.py +56 -0
- utilities/pytest_regressions.py +26 -46
- utilities/random.py +13 -9
- utilities/re.py +58 -28
- utilities/redis.py +401 -550
- utilities/scipy.py +1 -1
- utilities/sentinel.py +10 -0
- utilities/shelve.py +4 -1
- utilities/shutil.py +25 -0
- utilities/slack_sdk.py +36 -106
- utilities/sqlalchemy.py +502 -473
- utilities/sqlalchemy_polars.py +38 -94
- utilities/string.py +2 -3
- utilities/subprocess.py +1572 -0
- utilities/tempfile.py +86 -4
- utilities/testbook.py +50 -0
- utilities/text.py +165 -42
- utilities/timer.py +37 -65
- utilities/traceback.py +158 -929
- utilities/types.py +146 -116
- utilities/typing.py +531 -71
- utilities/tzdata.py +1 -53
- utilities/tzlocal.py +6 -23
- utilities/uuid.py +43 -5
- utilities/version.py +27 -26
- utilities/whenever.py +1776 -386
- utilities/zoneinfo.py +84 -22
- dycw_utilities-0.129.10.dist-info/METADATA +0 -241
- dycw_utilities-0.129.10.dist-info/RECORD +0 -96
- dycw_utilities-0.129.10.dist-info/WHEEL +0 -4
- dycw_utilities-0.129.10.dist-info/licenses/LICENSE +0 -21
- utilities/datetime.py +0 -1409
- utilities/eventkit.py +0 -402
- utilities/loguru.py +0 -144
- utilities/luigi.py +0 -228
- utilities/period.py +0 -324
- utilities/pyrsistent.py +0 -89
- utilities/python_dotenv.py +0 -105
- utilities/streamlit.py +0 -105
- utilities/sys.py +0 -87
- utilities/tenacity.py +0 -145
utilities/timer.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import datetime as dt
|
|
4
3
|
from operator import add, eq, ge, gt, le, lt, mul, ne, sub, truediv
|
|
5
|
-
from
|
|
6
|
-
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Self, override
|
|
5
|
+
|
|
6
|
+
from utilities.whenever import get_now_local
|
|
7
7
|
|
|
8
8
|
if TYPE_CHECKING:
|
|
9
9
|
from collections.abc import Callable
|
|
10
10
|
|
|
11
|
-
from
|
|
11
|
+
from whenever import TimeDelta, ZonedDateTime
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class Timer:
|
|
@@ -16,116 +16,88 @@ class Timer:
|
|
|
16
16
|
|
|
17
17
|
def __init__(self) -> None:
|
|
18
18
|
super().__init__()
|
|
19
|
-
self._start =
|
|
20
|
-
self._end:
|
|
19
|
+
self._start: ZonedDateTime = get_now_local()
|
|
20
|
+
self._end: ZonedDateTime | None = None
|
|
21
21
|
|
|
22
22
|
# arithmetic
|
|
23
23
|
|
|
24
|
-
def __add__(self, other: Any) ->
|
|
25
|
-
|
|
26
|
-
return dt.timedelta(seconds=self._apply_op(add, other))
|
|
27
|
-
if isinstance(other, dt.timedelta | Timer):
|
|
28
|
-
return self._apply_op(add, other)
|
|
29
|
-
return NotImplemented
|
|
24
|
+
def __add__(self, other: Any) -> TimeDelta:
|
|
25
|
+
return self._apply_op(add, other)
|
|
30
26
|
|
|
31
27
|
def __float__(self) -> float:
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
return self.timedelta.in_seconds()
|
|
29
|
+
|
|
30
|
+
def __sub__(self, other: Any) -> TimeDelta:
|
|
31
|
+
return self._apply_op(sub, other)
|
|
34
32
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return NotImplemented
|
|
41
|
-
|
|
42
|
-
def __mul__(self, other: Any) -> dt.timedelta:
|
|
43
|
-
if isinstance(other, int | float):
|
|
44
|
-
return dt.timedelta(seconds=self._apply_op(mul, other))
|
|
45
|
-
return NotImplemented
|
|
46
|
-
|
|
47
|
-
@overload
|
|
48
|
-
def __truediv__(self, other: Number) -> dt.timedelta: ...
|
|
49
|
-
@overload
|
|
50
|
-
def __truediv__(self, other: dt.timedelta | Timer) -> float: ...
|
|
51
|
-
def __truediv__(self, other: Any) -> dt.timedelta | float:
|
|
52
|
-
if isinstance(other, int | float):
|
|
53
|
-
return dt.timedelta(seconds=self._apply_op(truediv, other))
|
|
54
|
-
if isinstance(other, dt.timedelta | Timer):
|
|
55
|
-
return self._apply_op(truediv, other)
|
|
56
|
-
return NotImplemented
|
|
33
|
+
def __mul__(self, other: Any) -> TimeDelta:
|
|
34
|
+
return self._apply_op(mul, other)
|
|
35
|
+
|
|
36
|
+
def __truediv__(self, other: Any) -> TimeDelta:
|
|
37
|
+
return self._apply_op(truediv, other)
|
|
57
38
|
|
|
58
39
|
# context manager
|
|
59
40
|
|
|
60
41
|
def __enter__(self) -> Self:
|
|
61
|
-
self._start =
|
|
42
|
+
self._start = get_now_local()
|
|
62
43
|
return self
|
|
63
44
|
|
|
64
45
|
def __exit__(self, *_: object) -> bool:
|
|
65
|
-
self._end =
|
|
46
|
+
self._end = get_now_local()
|
|
66
47
|
return False
|
|
67
48
|
|
|
49
|
+
# hash
|
|
50
|
+
|
|
51
|
+
@override
|
|
52
|
+
def __hash__(self) -> int:
|
|
53
|
+
return hash((id(self), self._start, self._end))
|
|
54
|
+
|
|
68
55
|
# repr
|
|
69
56
|
|
|
70
57
|
@override
|
|
71
58
|
def __repr__(self) -> str:
|
|
72
|
-
return
|
|
59
|
+
return self.timedelta.format_iso()
|
|
73
60
|
|
|
74
61
|
@override
|
|
75
62
|
def __str__(self) -> str:
|
|
76
|
-
return
|
|
63
|
+
return self.timedelta.format_iso()
|
|
77
64
|
|
|
78
65
|
# comparison
|
|
79
66
|
|
|
80
67
|
@override
|
|
81
68
|
def __eq__(self, other: object) -> bool:
|
|
82
|
-
|
|
83
|
-
return self._apply_op(eq, other)
|
|
84
|
-
return False
|
|
69
|
+
return self._apply_op(eq, other)
|
|
85
70
|
|
|
86
71
|
def __ge__(self, other: Any) -> bool:
|
|
87
|
-
|
|
88
|
-
return self._apply_op(ge, other)
|
|
89
|
-
return NotImplemented
|
|
72
|
+
return self._apply_op(ge, other)
|
|
90
73
|
|
|
91
74
|
def __gt__(self, other: Any) -> bool:
|
|
92
|
-
|
|
93
|
-
return self._apply_op(gt, other)
|
|
94
|
-
return NotImplemented
|
|
75
|
+
return self._apply_op(gt, other)
|
|
95
76
|
|
|
96
77
|
def __le__(self, other: Any) -> bool:
|
|
97
|
-
|
|
98
|
-
return self._apply_op(le, other)
|
|
99
|
-
return NotImplemented
|
|
78
|
+
return self._apply_op(le, other)
|
|
100
79
|
|
|
101
80
|
def __lt__(self, other: Any) -> bool:
|
|
102
|
-
|
|
103
|
-
return self._apply_op(lt, other)
|
|
104
|
-
return NotImplemented
|
|
81
|
+
return self._apply_op(lt, other)
|
|
105
82
|
|
|
106
83
|
@override
|
|
107
84
|
def __ne__(self, other: object) -> bool:
|
|
108
|
-
|
|
109
|
-
return self._apply_op(ne, other)
|
|
110
|
-
return True
|
|
85
|
+
return self._apply_op(ne, other)
|
|
111
86
|
|
|
112
87
|
# properties
|
|
113
88
|
|
|
114
89
|
@property
|
|
115
|
-
def timedelta(self) ->
|
|
90
|
+
def timedelta(self) -> TimeDelta:
|
|
116
91
|
"""The elapsed time, as a `timedelta` object."""
|
|
117
|
-
|
|
92
|
+
end_use = get_now_local() if (end := self._end) is None else end
|
|
93
|
+
return end_use - self._start
|
|
118
94
|
|
|
119
95
|
# private
|
|
120
96
|
|
|
121
97
|
def _apply_op(self, op: Callable[[Any, Any], Any], other: Any, /) -> Any:
|
|
122
|
-
if isinstance(other, int | float):
|
|
123
|
-
return op(float(self), other)
|
|
124
98
|
if isinstance(other, Timer):
|
|
125
99
|
return op(self.timedelta, other.timedelta)
|
|
126
|
-
|
|
127
|
-
return op(self.timedelta, other)
|
|
128
|
-
return NotImplemented # pragma: no cover
|
|
100
|
+
return op(self.timedelta, other)
|
|
129
101
|
|
|
130
102
|
|
|
131
103
|
__all__ = ["Timer"]
|