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.
Files changed (103) hide show
  1. dycw_utilities-0.175.17.dist-info/METADATA +34 -0
  2. dycw_utilities-0.175.17.dist-info/RECORD +103 -0
  3. dycw_utilities-0.175.17.dist-info/WHEEL +4 -0
  4. dycw_utilities-0.175.17.dist-info/entry_points.txt +4 -0
  5. utilities/__init__.py +1 -1
  6. utilities/altair.py +14 -14
  7. utilities/asyncio.py +350 -819
  8. utilities/atomicwrites.py +18 -6
  9. utilities/atools.py +77 -22
  10. utilities/cachetools.py +24 -29
  11. utilities/click.py +393 -237
  12. utilities/concurrent.py +8 -11
  13. utilities/contextlib.py +216 -17
  14. utilities/contextvars.py +20 -1
  15. utilities/cryptography.py +3 -3
  16. utilities/dataclasses.py +83 -118
  17. utilities/docker.py +293 -0
  18. utilities/enum.py +26 -23
  19. utilities/errors.py +17 -3
  20. utilities/fastapi.py +29 -65
  21. utilities/fpdf2.py +3 -3
  22. utilities/functions.py +169 -416
  23. utilities/functools.py +18 -19
  24. utilities/git.py +9 -30
  25. utilities/grp.py +28 -0
  26. utilities/gzip.py +31 -0
  27. utilities/http.py +3 -2
  28. utilities/hypothesis.py +738 -589
  29. utilities/importlib.py +17 -1
  30. utilities/inflect.py +25 -0
  31. utilities/iterables.py +194 -262
  32. utilities/jinja2.py +148 -0
  33. utilities/json.py +70 -0
  34. utilities/libcst.py +38 -17
  35. utilities/lightweight_charts.py +5 -9
  36. utilities/logging.py +345 -543
  37. utilities/math.py +18 -13
  38. utilities/memory_profiler.py +11 -15
  39. utilities/more_itertools.py +200 -131
  40. utilities/operator.py +33 -29
  41. utilities/optuna.py +6 -6
  42. utilities/orjson.py +272 -137
  43. utilities/os.py +61 -4
  44. utilities/parse.py +59 -61
  45. utilities/pathlib.py +281 -40
  46. utilities/permissions.py +298 -0
  47. utilities/pickle.py +2 -2
  48. utilities/platform.py +24 -5
  49. utilities/polars.py +1214 -430
  50. utilities/polars_ols.py +1 -1
  51. utilities/postgres.py +408 -0
  52. utilities/pottery.py +113 -26
  53. utilities/pqdm.py +10 -11
  54. utilities/psutil.py +6 -57
  55. utilities/pwd.py +28 -0
  56. utilities/pydantic.py +4 -54
  57. utilities/pydantic_settings.py +240 -0
  58. utilities/pydantic_settings_sops.py +76 -0
  59. utilities/pyinstrument.py +8 -10
  60. utilities/pytest.py +227 -121
  61. utilities/pytest_plugins/__init__.py +1 -0
  62. utilities/pytest_plugins/pytest_randomly.py +23 -0
  63. utilities/pytest_plugins/pytest_regressions.py +56 -0
  64. utilities/pytest_regressions.py +26 -46
  65. utilities/random.py +13 -9
  66. utilities/re.py +58 -28
  67. utilities/redis.py +401 -550
  68. utilities/scipy.py +1 -1
  69. utilities/sentinel.py +10 -0
  70. utilities/shelve.py +4 -1
  71. utilities/shutil.py +25 -0
  72. utilities/slack_sdk.py +36 -106
  73. utilities/sqlalchemy.py +502 -473
  74. utilities/sqlalchemy_polars.py +38 -94
  75. utilities/string.py +2 -3
  76. utilities/subprocess.py +1572 -0
  77. utilities/tempfile.py +86 -4
  78. utilities/testbook.py +50 -0
  79. utilities/text.py +165 -42
  80. utilities/timer.py +37 -65
  81. utilities/traceback.py +158 -929
  82. utilities/types.py +146 -116
  83. utilities/typing.py +531 -71
  84. utilities/tzdata.py +1 -53
  85. utilities/tzlocal.py +6 -23
  86. utilities/uuid.py +43 -5
  87. utilities/version.py +27 -26
  88. utilities/whenever.py +1776 -386
  89. utilities/zoneinfo.py +84 -22
  90. dycw_utilities-0.129.10.dist-info/METADATA +0 -241
  91. dycw_utilities-0.129.10.dist-info/RECORD +0 -96
  92. dycw_utilities-0.129.10.dist-info/WHEEL +0 -4
  93. dycw_utilities-0.129.10.dist-info/licenses/LICENSE +0 -21
  94. utilities/datetime.py +0 -1409
  95. utilities/eventkit.py +0 -402
  96. utilities/loguru.py +0 -144
  97. utilities/luigi.py +0 -228
  98. utilities/period.py +0 -324
  99. utilities/pyrsistent.py +0 -89
  100. utilities/python_dotenv.py +0 -105
  101. utilities/streamlit.py +0 -105
  102. utilities/sys.py +0 -87
  103. 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 timeit import default_timer
6
- from typing import TYPE_CHECKING, Any, Self, overload, override
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 utilities.types import Number
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 = default_timer()
20
- self._end: float | None = None
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) -> dt.timedelta:
25
- if isinstance(other, int | float):
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
- end_use = default_timer() if (end := self._end) is None else end
33
- return end_use - self._start
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 __sub__(self, other: Any) -> dt.timedelta:
36
- if isinstance(other, int | float):
37
- return dt.timedelta(seconds=self._apply_op(sub, other))
38
- if isinstance(other, dt.timedelta | Timer):
39
- return self._apply_op(sub, other)
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 = default_timer()
42
+ self._start = get_now_local()
62
43
  return self
63
44
 
64
45
  def __exit__(self, *_: object) -> bool:
65
- self._end = default_timer()
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 str(self.timedelta)
59
+ return self.timedelta.format_iso()
73
60
 
74
61
  @override
75
62
  def __str__(self) -> str:
76
- return str(self.timedelta)
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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
- if isinstance(other, int | float | dt.timedelta | Timer):
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) -> dt.timedelta:
90
+ def timedelta(self) -> TimeDelta:
116
91
  """The elapsed time, as a `timedelta` object."""
117
- return dt.timedelta(seconds=float(self))
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
- if isinstance(other, dt.timedelta):
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"]