dycw-utilities 0.175.17__py3-none-any.whl → 0.185.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.
- dycw_utilities-0.185.8.dist-info/METADATA +33 -0
- dycw_utilities-0.185.8.dist-info/RECORD +90 -0
- {dycw_utilities-0.175.17.dist-info → dycw_utilities-0.185.8.dist-info}/WHEEL +2 -2
- utilities/__init__.py +1 -1
- utilities/altair.py +8 -6
- utilities/asyncio.py +40 -56
- utilities/atools.py +9 -11
- utilities/cachetools.py +8 -6
- utilities/click.py +4 -3
- utilities/concurrent.py +1 -1
- utilities/constants.py +492 -0
- utilities/contextlib.py +23 -30
- utilities/contextvars.py +1 -23
- utilities/core.py +2581 -0
- utilities/dataclasses.py +16 -119
- utilities/docker.py +139 -45
- utilities/enum.py +1 -1
- utilities/errors.py +2 -16
- utilities/fastapi.py +5 -5
- utilities/fpdf2.py +2 -1
- utilities/functions.py +33 -264
- utilities/http.py +2 -3
- utilities/hypothesis.py +48 -25
- utilities/iterables.py +39 -575
- utilities/jinja2.py +3 -6
- utilities/jupyter.py +5 -3
- utilities/libcst.py +1 -1
- utilities/lightweight_charts.py +4 -6
- utilities/logging.py +17 -15
- utilities/math.py +1 -36
- utilities/more_itertools.py +4 -6
- utilities/numpy.py +2 -1
- utilities/operator.py +2 -2
- utilities/orjson.py +24 -25
- utilities/os.py +4 -185
- utilities/packaging.py +129 -0
- utilities/parse.py +33 -13
- utilities/pathlib.py +2 -136
- utilities/platform.py +8 -90
- utilities/polars.py +34 -31
- utilities/postgres.py +9 -4
- utilities/pottery.py +20 -18
- utilities/pqdm.py +3 -4
- utilities/psutil.py +2 -3
- utilities/pydantic.py +18 -4
- utilities/pydantic_settings.py +7 -9
- utilities/pydantic_settings_sops.py +3 -3
- utilities/pyinstrument.py +4 -4
- utilities/pytest.py +49 -108
- utilities/pytest_plugins/pytest_regressions.py +2 -2
- utilities/pytest_regressions.py +8 -6
- utilities/random.py +2 -8
- utilities/redis.py +98 -94
- utilities/reprlib.py +11 -118
- utilities/shellingham.py +66 -0
- utilities/slack_sdk.py +13 -12
- utilities/sqlalchemy.py +42 -30
- utilities/sqlalchemy_polars.py +16 -25
- utilities/subprocess.py +1166 -148
- utilities/tabulate.py +32 -0
- utilities/testbook.py +8 -8
- utilities/text.py +24 -115
- utilities/throttle.py +159 -0
- utilities/time.py +18 -0
- utilities/timer.py +29 -12
- utilities/traceback.py +15 -22
- utilities/types.py +38 -3
- utilities/typing.py +18 -12
- utilities/uuid.py +1 -1
- utilities/version.py +202 -45
- utilities/whenever.py +22 -150
- dycw_utilities-0.175.17.dist-info/METADATA +0 -34
- dycw_utilities-0.175.17.dist-info/RECORD +0 -103
- utilities/atomicwrites.py +0 -182
- utilities/cryptography.py +0 -41
- utilities/getpass.py +0 -8
- utilities/git.py +0 -19
- utilities/grp.py +0 -28
- utilities/gzip.py +0 -31
- utilities/json.py +0 -70
- utilities/permissions.py +0 -298
- utilities/pickle.py +0 -25
- utilities/pwd.py +0 -28
- utilities/re.py +0 -156
- utilities/sentinel.py +0 -73
- utilities/socket.py +0 -8
- utilities/string.py +0 -20
- utilities/tempfile.py +0 -136
- utilities/tzdata.py +0 -11
- utilities/tzlocal.py +0 -28
- utilities/warnings.py +0 -65
- utilities/zipfile.py +0 -25
- utilities/zoneinfo.py +0 -133
- {dycw_utilities-0.175.17.dist-info → dycw_utilities-0.185.8.dist-info}/entry_points.txt +0 -0
utilities/traceback.py
CHANGED
|
@@ -13,28 +13,22 @@ from sys import stderr
|
|
|
13
13
|
from traceback import TracebackException
|
|
14
14
|
from typing import TYPE_CHECKING, override
|
|
15
15
|
|
|
16
|
-
from utilities.
|
|
17
|
-
|
|
18
|
-
from utilities.iterables import OneEmptyError, one
|
|
19
|
-
from utilities.pathlib import module_path, to_path
|
|
20
|
-
from utilities.reprlib import (
|
|
16
|
+
from utilities.constants import (
|
|
17
|
+
LOCAL_TIME_ZONE_NAME,
|
|
21
18
|
RICH_EXPAND_ALL,
|
|
22
19
|
RICH_INDENT_SIZE,
|
|
23
20
|
RICH_MAX_DEPTH,
|
|
24
21
|
RICH_MAX_LENGTH,
|
|
25
22
|
RICH_MAX_STRING,
|
|
26
23
|
RICH_MAX_WIDTH,
|
|
27
|
-
yield_mapping_repr,
|
|
28
24
|
)
|
|
25
|
+
from utilities.core import OneEmptyError, get_now, get_now_local, one, write_text
|
|
26
|
+
from utilities.errors import repr_error
|
|
27
|
+
from utilities.pathlib import module_path, to_path
|
|
28
|
+
from utilities.reprlib import yield_mapping_repr
|
|
29
29
|
from utilities.text import to_bool
|
|
30
|
-
from utilities.
|
|
31
|
-
from utilities.
|
|
32
|
-
from utilities.whenever import (
|
|
33
|
-
format_compact,
|
|
34
|
-
get_now,
|
|
35
|
-
get_now_local,
|
|
36
|
-
to_zoned_date_time,
|
|
37
|
-
)
|
|
30
|
+
from utilities.version import to_version3
|
|
31
|
+
from utilities.whenever import format_compact, to_zoned_date_time
|
|
38
32
|
|
|
39
33
|
if TYPE_CHECKING:
|
|
40
34
|
from collections.abc import Callable, Iterator
|
|
@@ -48,7 +42,7 @@ if TYPE_CHECKING:
|
|
|
48
42
|
MaybeCallableZonedDateTimeLike,
|
|
49
43
|
PathLike,
|
|
50
44
|
)
|
|
51
|
-
from utilities.version import
|
|
45
|
+
from utilities.version import MaybeCallableVersion3Like
|
|
52
46
|
|
|
53
47
|
|
|
54
48
|
##
|
|
@@ -60,7 +54,7 @@ def format_exception_stack(
|
|
|
60
54
|
*,
|
|
61
55
|
header: bool = False,
|
|
62
56
|
start: MaybeCallableZonedDateTimeLike = get_now,
|
|
63
|
-
version:
|
|
57
|
+
version: MaybeCallableVersion3Like | None = None,
|
|
64
58
|
capture_locals: bool = False,
|
|
65
59
|
max_width: int = RICH_MAX_WIDTH,
|
|
66
60
|
indent_size: int = RICH_INDENT_SIZE,
|
|
@@ -91,7 +85,7 @@ def format_exception_stack(
|
|
|
91
85
|
def _yield_header_lines(
|
|
92
86
|
*,
|
|
93
87
|
start: MaybeCallableZonedDateTimeLike = get_now,
|
|
94
|
-
version:
|
|
88
|
+
version: MaybeCallableVersion3Like | None = None,
|
|
95
89
|
) -> Iterator[str]:
|
|
96
90
|
"""Yield the header lines."""
|
|
97
91
|
now = get_now_local()
|
|
@@ -102,7 +96,7 @@ def _yield_header_lines(
|
|
|
102
96
|
yield f"User | {getuser()}"
|
|
103
97
|
yield f"Host | {gethostname()}"
|
|
104
98
|
yield f"Process ID | {getpid()}"
|
|
105
|
-
version_use = "" if version is None else
|
|
99
|
+
version_use = "" if version is None else to_version3(version)
|
|
106
100
|
yield f"Version | {version_use}"
|
|
107
101
|
yield ""
|
|
108
102
|
|
|
@@ -197,7 +191,7 @@ def _trim_path(path: PathLike, pattern: str, /) -> Path | None:
|
|
|
197
191
|
def make_except_hook(
|
|
198
192
|
*,
|
|
199
193
|
start: MaybeCallableZonedDateTimeLike = get_now,
|
|
200
|
-
version:
|
|
194
|
+
version: MaybeCallableVersion3Like | None = None,
|
|
201
195
|
path: MaybeCallablePathLike | None = None,
|
|
202
196
|
path_max_age: Delta | None = None,
|
|
203
197
|
max_width: int = RICH_MAX_WIDTH,
|
|
@@ -236,7 +230,7 @@ def _make_except_hook_inner(
|
|
|
236
230
|
/,
|
|
237
231
|
*,
|
|
238
232
|
start: MaybeCallableZonedDateTimeLike = get_now,
|
|
239
|
-
version:
|
|
233
|
+
version: MaybeCallableVersion3Like | None = None,
|
|
240
234
|
path: MaybeCallablePathLike | None = None,
|
|
241
235
|
path_max_age: Delta | None = None,
|
|
242
236
|
max_width: int = RICH_MAX_WIDTH,
|
|
@@ -272,8 +266,7 @@ def _make_except_hook_inner(
|
|
|
272
266
|
max_depth=max_depth,
|
|
273
267
|
expand_all=expand_all,
|
|
274
268
|
)
|
|
275
|
-
|
|
276
|
-
_ = temp.write_text(full)
|
|
269
|
+
write_text(path_log, full, overwrite=True)
|
|
277
270
|
if path_max_age is not None:
|
|
278
271
|
_make_except_hook_purge(path, path_max_age)
|
|
279
272
|
if slack_url is not None: # pragma: no cover
|
utilities/types.py
CHANGED
|
@@ -11,6 +11,7 @@ from re import Pattern
|
|
|
11
11
|
from types import TracebackType
|
|
12
12
|
from typing import (
|
|
13
13
|
Any,
|
|
14
|
+
BinaryIO,
|
|
14
15
|
ClassVar,
|
|
15
16
|
Literal,
|
|
16
17
|
Protocol,
|
|
@@ -65,6 +66,7 @@ type OpenMode = Literal[
|
|
|
65
66
|
type MaybeCallable[T] = T | Callable[[], T]
|
|
66
67
|
type MaybeStr[T] = T | str
|
|
67
68
|
type MaybeType[T] = T | type[T]
|
|
69
|
+
type StrDict = dict[str, Any]
|
|
68
70
|
type StrMapping = Mapping[str, Any]
|
|
69
71
|
type StrStrMapping = Mapping[str, str]
|
|
70
72
|
type TupleOrStrMapping = tuple[Any, ...] | StrMapping
|
|
@@ -89,6 +91,11 @@ class SupportsKeysAndGetItem(Protocol[_T, _T_co]):
|
|
|
89
91
|
def __getitem__(self, key: _T, /) -> _T_co: ... # pragma: no cover
|
|
90
92
|
|
|
91
93
|
|
|
94
|
+
# compression
|
|
95
|
+
type Compression = Literal["bz2", "gzip", "lzma"]
|
|
96
|
+
type PathToBinaryIO = Callable[[PathLike], BinaryIO]
|
|
97
|
+
|
|
98
|
+
|
|
92
99
|
# concurrent
|
|
93
100
|
type Parallelism = Literal["processes", "threads"]
|
|
94
101
|
|
|
@@ -98,7 +105,7 @@ type Parallelism = Literal["processes", "threads"]
|
|
|
98
105
|
class Dataclass(Protocol):
|
|
99
106
|
"""Protocol for `dataclass` classes."""
|
|
100
107
|
|
|
101
|
-
__dataclass_fields__: ClassVar[
|
|
108
|
+
__dataclass_fields__: ClassVar[StrDict]
|
|
102
109
|
|
|
103
110
|
|
|
104
111
|
# datetime
|
|
@@ -127,7 +134,7 @@ type SequenceLT[T] = list[T] | tuple[T, ...]
|
|
|
127
134
|
# iterables - dervied
|
|
128
135
|
type MaybeSequence[T] = T | SequenceLT[T]
|
|
129
136
|
type SequenceStr = SequenceLT[str]
|
|
130
|
-
type CollectionStr =
|
|
137
|
+
type CollectionStr = StrDict | frozenset[str] | set[str] | SequenceStr
|
|
131
138
|
# iterables - maybe str
|
|
132
139
|
type MaybeCollectionStr = str | CollectionStr
|
|
133
140
|
type MaybeSequenceStr = str | SequenceStr
|
|
@@ -213,16 +220,26 @@ class SupportsRound(Protocol[_T_co]):
|
|
|
213
220
|
def __round__(self, ndigits: int, /) -> _T_co: ...
|
|
214
221
|
|
|
215
222
|
|
|
223
|
+
# os
|
|
224
|
+
type CopyOrMove = Literal["copy", "move"]
|
|
225
|
+
type IntOrAll = int | Literal["all"]
|
|
226
|
+
|
|
227
|
+
|
|
216
228
|
# parse
|
|
217
229
|
type ParseObjectExtra = Mapping[Any, Callable[[str], Any]]
|
|
218
230
|
type SerializeObjectExtra = Mapping[Any, Callable[[Any], str]]
|
|
219
231
|
|
|
220
232
|
|
|
221
233
|
# pathlib
|
|
234
|
+
type FileOrDir = Literal["file", "dir"]
|
|
222
235
|
type PathLike = MaybeStr[Path]
|
|
223
236
|
type MaybeCallablePathLike = MaybeCallable[PathLike]
|
|
224
237
|
|
|
225
238
|
|
|
239
|
+
# platform
|
|
240
|
+
type System = Literal["windows", "mac", "linux"]
|
|
241
|
+
|
|
242
|
+
|
|
226
243
|
# random
|
|
227
244
|
type Seed = int | float | str | bytes | bytearray | Random
|
|
228
245
|
|
|
@@ -232,13 +249,17 @@ type PatternLike = MaybeStr[Pattern[str]]
|
|
|
232
249
|
|
|
233
250
|
|
|
234
251
|
# retry
|
|
235
|
-
type Retry = tuple[int,
|
|
252
|
+
type Retry = tuple[int, Duration | None]
|
|
236
253
|
|
|
237
254
|
|
|
238
255
|
# text
|
|
239
256
|
type MaybeCallableStr = MaybeCallable[str]
|
|
240
257
|
|
|
241
258
|
|
|
259
|
+
# time
|
|
260
|
+
type Duration = Number | TimeDelta
|
|
261
|
+
|
|
262
|
+
|
|
242
263
|
# traceback
|
|
243
264
|
type ExcInfo = tuple[type[BaseException], BaseException, TracebackType]
|
|
244
265
|
type OptExcInfo = ExcInfo | tuple[None, None, None]
|
|
@@ -249,6 +270,11 @@ type UUIDLike = MaybeStr[UUID]
|
|
|
249
270
|
type MaybeCallableUUIDLike = MaybeCallable[UUIDLike | Seed]
|
|
250
271
|
|
|
251
272
|
|
|
273
|
+
# warnings
|
|
274
|
+
type FilterWarningsAction = Literal[
|
|
275
|
+
"error", "ignore", "always", "default", "module", "once"
|
|
276
|
+
]
|
|
277
|
+
|
|
252
278
|
# whenever
|
|
253
279
|
type DateDeltaLike = MaybeStr[DateDelta]
|
|
254
280
|
type DateLike = MaybeStr[Date]
|
|
@@ -292,6 +318,8 @@ type TimeZoneLike = (
|
|
|
292
318
|
|
|
293
319
|
__all__ = [
|
|
294
320
|
"TIME_ZONES",
|
|
321
|
+
"Compression",
|
|
322
|
+
"CopyOrMove",
|
|
295
323
|
"Coro",
|
|
296
324
|
"Dataclass",
|
|
297
325
|
"DateDeltaLike",
|
|
@@ -300,11 +328,15 @@ __all__ = [
|
|
|
300
328
|
"DateTimeDeltaLike",
|
|
301
329
|
"DateTimeRoundMode",
|
|
302
330
|
"Delta",
|
|
331
|
+
"Duration",
|
|
303
332
|
"EnumLike",
|
|
304
333
|
"ExcInfo",
|
|
305
334
|
"ExceptionTypeLike",
|
|
335
|
+
"FileOrDir",
|
|
336
|
+
"FilterWarningsAction",
|
|
306
337
|
"IPv4AddressLike",
|
|
307
338
|
"IPv6AddressLike",
|
|
339
|
+
"IntOrAll",
|
|
308
340
|
"LogLevel",
|
|
309
341
|
"LoggerLike",
|
|
310
342
|
"MathRoundMode",
|
|
@@ -334,6 +366,7 @@ __all__ = [
|
|
|
334
366
|
"Parallelism",
|
|
335
367
|
"ParseObjectExtra",
|
|
336
368
|
"PathLike",
|
|
369
|
+
"PathToBinaryIO",
|
|
337
370
|
"PatternLike",
|
|
338
371
|
"PlainDateTimeLike",
|
|
339
372
|
"Retry",
|
|
@@ -341,6 +374,7 @@ __all__ = [
|
|
|
341
374
|
"SequenceStr",
|
|
342
375
|
"SerializeObjectExtra",
|
|
343
376
|
"Sign",
|
|
377
|
+
"StrDict",
|
|
344
378
|
"StrMapping",
|
|
345
379
|
"StrStrMapping",
|
|
346
380
|
"SupportsAbs",
|
|
@@ -356,6 +390,7 @@ __all__ = [
|
|
|
356
390
|
"SupportsLT",
|
|
357
391
|
"SupportsRichComparison",
|
|
358
392
|
"SupportsRound",
|
|
393
|
+
"System",
|
|
359
394
|
"TimeDeltaLike",
|
|
360
395
|
"TimeLike",
|
|
361
396
|
"TimeOrDateTimeDelta",
|
utilities/typing.py
CHANGED
|
@@ -19,7 +19,6 @@ from typing import (
|
|
|
19
19
|
TypeGuard,
|
|
20
20
|
Union, # pyright: ignore[reportDeprecated]
|
|
21
21
|
_TypedDictMeta, # pyright: ignore[reportAttributeAccessIssue]
|
|
22
|
-
cast,
|
|
23
22
|
get_origin,
|
|
24
23
|
overload,
|
|
25
24
|
override,
|
|
@@ -40,10 +39,11 @@ from whenever import (
|
|
|
40
39
|
ZonedDateTime,
|
|
41
40
|
)
|
|
42
41
|
|
|
43
|
-
from utilities.
|
|
44
|
-
from utilities.
|
|
42
|
+
from utilities.constants import Sentinel
|
|
43
|
+
from utilities.core import unique_everseen
|
|
45
44
|
from utilities.types import (
|
|
46
45
|
Dataclass,
|
|
46
|
+
StrDict,
|
|
47
47
|
StrMapping,
|
|
48
48
|
StrStrMapping,
|
|
49
49
|
TupleOrStrMapping,
|
|
@@ -145,7 +145,7 @@ def get_type_hints(
|
|
|
145
145
|
globalns: StrMapping | None = None,
|
|
146
146
|
localns: StrMapping | None = None,
|
|
147
147
|
warn_name_errors: bool = False,
|
|
148
|
-
) ->
|
|
148
|
+
) -> StrDict:
|
|
149
149
|
"""Get the type hints of an object."""
|
|
150
150
|
_ = {
|
|
151
151
|
Date,
|
|
@@ -170,7 +170,7 @@ def get_type_hints(
|
|
|
170
170
|
}
|
|
171
171
|
globalns_use = globals() | ({} if globalns is None else dict(globalns))
|
|
172
172
|
localns_use = {} if localns is None else dict(localns)
|
|
173
|
-
result:
|
|
173
|
+
result: StrDict = obj.__annotations__
|
|
174
174
|
result = result | dict(get_forward_ref_args(obj))
|
|
175
175
|
try:
|
|
176
176
|
hints = _get_type_hints(
|
|
@@ -404,11 +404,8 @@ def _is_instance_typed_dict[T: _TypedDictMeta](
|
|
|
404
404
|
localns: StrMapping | None = None,
|
|
405
405
|
warn_name_errors: bool = False,
|
|
406
406
|
) -> TypeGuard[T]:
|
|
407
|
-
if not
|
|
407
|
+
if not is_str_dict(obj):
|
|
408
408
|
return False
|
|
409
|
-
if not all(isinstance(k, str) for k in obj):
|
|
410
|
-
return False
|
|
411
|
-
obj = cast("dict[str, Any]", obj)
|
|
412
409
|
hints = get_type_hints(
|
|
413
410
|
type_, globalns=globalns, localns=localns, warn_name_errors=warn_name_errors
|
|
414
411
|
)
|
|
@@ -749,7 +746,15 @@ def is_set_type(obj: Any, /) -> bool:
|
|
|
749
746
|
##
|
|
750
747
|
|
|
751
748
|
|
|
752
|
-
def
|
|
749
|
+
def is_str_dict(obj: Any, /) -> TypeGuard[StrDict]:
|
|
750
|
+
"""Check if an object is a string mapping."""
|
|
751
|
+
return isinstance(obj, Mapping) and is_iterable_of(obj, str)
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
##
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def is_str_mapping(obj: Any, /) -> TypeGuard[StrMapping]:
|
|
753
758
|
"""Check if an object is a string mapping."""
|
|
754
759
|
return isinstance(obj, Mapping) and is_iterable_of(obj, str)
|
|
755
760
|
|
|
@@ -852,7 +857,7 @@ def is_tuple(obj: Any, /) -> TypeGuard[tuple[Any, ...]]:
|
|
|
852
857
|
|
|
853
858
|
def is_tuple_or_str_mapping(obj: Any, /) -> TypeGuard[TupleOrStrMapping]:
|
|
854
859
|
"""Check if an object is a tuple or string mapping."""
|
|
855
|
-
return is_tuple(obj) or
|
|
860
|
+
return is_tuple(obj) or is_str_mapping(obj)
|
|
856
861
|
|
|
857
862
|
|
|
858
863
|
##
|
|
@@ -943,7 +948,8 @@ __all__ = [
|
|
|
943
948
|
"is_sequence_of_tuple_or_str_mapping",
|
|
944
949
|
"is_sequence_type",
|
|
945
950
|
"is_set_type",
|
|
946
|
-
"
|
|
951
|
+
"is_str_dict",
|
|
952
|
+
"is_str_mapping",
|
|
947
953
|
"is_subclass_gen",
|
|
948
954
|
"is_tuple",
|
|
949
955
|
"is_tuple_or_str_mapping",
|
utilities/uuid.py
CHANGED
|
@@ -5,8 +5,8 @@ from random import Random
|
|
|
5
5
|
from typing import TYPE_CHECKING, assert_never, overload
|
|
6
6
|
from uuid import UUID, uuid4
|
|
7
7
|
|
|
8
|
+
from utilities.constants import Sentinel
|
|
8
9
|
from utilities.random import get_state
|
|
9
|
-
from utilities.sentinel import Sentinel
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
12
|
from utilities.types import MaybeCallableUUIDLike, Seed
|