dycw-utilities 0.114.2__py3-none-any.whl → 0.114.3__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.114.2.dist-info → dycw_utilities-0.114.3.dist-info}/METADATA +1 -1
- {dycw_utilities-0.114.2.dist-info → dycw_utilities-0.114.3.dist-info}/RECORD +8 -8
- utilities/__init__.py +1 -1
- utilities/asyncio.py +22 -5
- utilities/redis.py +42 -3
- utilities/sqlalchemy.py +56 -2
- {dycw_utilities-0.114.2.dist-info → dycw_utilities-0.114.3.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.114.2.dist-info → dycw_utilities-0.114.3.dist-info}/licenses/LICENSE +0 -0
@@ -1,7 +1,7 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=SWDkfIOyhgygmyWsgThn0Boll445H7CW7YAsVtIjpMY,60
|
2
2
|
utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
|
3
3
|
utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
|
4
|
-
utilities/asyncio.py,sha256=
|
4
|
+
utilities/asyncio.py,sha256=Hysj5gHlizHUhBo3D9Czo5wciJxNoO5HrhXZ4hbC-sk,21478
|
5
5
|
utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
|
6
6
|
utilities/atools.py,sha256=IYMuFSFGSKyuQmqD6v5IUtDlz8PPw0Sr87Cub_gRU3M,1168
|
7
7
|
utilities/cachetools.py,sha256=C1zqOg7BYz0IfQFK8e3qaDDgEZxDpo47F15RTfJM37Q,2910
|
@@ -58,7 +58,7 @@ utilities/pytest_regressions.py,sha256=-SVT9647Dg6-JcdsiaDKXe3NdOmmrvGevLKWwGjxq
|
|
58
58
|
utilities/python_dotenv.py,sha256=iWcnpXbH7S6RoXHiLlGgyuH6udCupAcPd_gQ0eAenQ0,3190
|
59
59
|
utilities/random.py,sha256=lYdjgxB7GCfU_fwFVl5U-BIM_HV3q6_urL9byjrwDM8,4157
|
60
60
|
utilities/re.py,sha256=5J4d8VwIPFVrX2Eb8zfoxImDv7IwiN_U7mJ07wR2Wvs,3958
|
61
|
-
utilities/redis.py,sha256=
|
61
|
+
utilities/redis.py,sha256=O2EoSbavGRZsLT9Jfh7byZwBNBpZFPzlIcg4Qf_8CkE,26663
|
62
62
|
utilities/reprlib.py,sha256=Re9bk3n-kC__9DxQmRlevqFA86pE6TtVfWjUgpbVOv0,1849
|
63
63
|
utilities/rich.py,sha256=t50MwwVBsoOLxzmeVFSVpjno4OW6Ufum32skXbV8-Bs,1911
|
64
64
|
utilities/scipy.py,sha256=X6ROnHwiUhAmPhM0jkfEh0-Fd9iRvwiqtCQMOLmOQF8,945
|
@@ -66,7 +66,7 @@ utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
|
|
66
66
|
utilities/shelve.py,sha256=HZsMwK4tcIfg3sh0gApx4-yjQnrY4o3V3ZRimvRhoW0,738
|
67
67
|
utilities/slack_sdk.py,sha256=Gbla983KulSSXnNyzaXgYQLKoq84KvLH8SdhxU-jQ0Q,4126
|
68
68
|
utilities/socket.py,sha256=K77vfREvzoVTrpYKo6MZakol0EYu2q1sWJnnZqL0So0,118
|
69
|
-
utilities/sqlalchemy.py,sha256=
|
69
|
+
utilities/sqlalchemy.py,sha256=585hWuuXVTKTnyn0Pfd9JI6jp-hmKW6pLKGYMjXjytM,36959
|
70
70
|
utilities/sqlalchemy_polars.py,sha256=wjJpoUo-yO9E2ujpG_06vV5r2OdvBiQ4yvV6wKCa2Tk,15605
|
71
71
|
utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
|
72
72
|
utilities/streamlit.py,sha256=U9PJBaKP1IdSykKhPZhIzSPTZsmLsnwbEPZWzNhJPKk,2955
|
@@ -87,7 +87,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
|
|
87
87
|
utilities/whenever.py,sha256=iLRP_-8CZtBpHKbGZGu-kjSMg1ZubJ-VSmgSy7Eudxw,17787
|
88
88
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
89
89
|
utilities/zoneinfo.py,sha256=-Xm57PMMwDTYpxJdkiJG13wnbwK--I7XItBh5WVhD-o,1874
|
90
|
-
dycw_utilities-0.114.
|
91
|
-
dycw_utilities-0.114.
|
92
|
-
dycw_utilities-0.114.
|
93
|
-
dycw_utilities-0.114.
|
90
|
+
dycw_utilities-0.114.3.dist-info/METADATA,sha256=vNqkObcQLSh6xKu-ehOh26STTT5syHO9ImD4L7O3dPc,12943
|
91
|
+
dycw_utilities-0.114.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
92
|
+
dycw_utilities-0.114.3.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
93
|
+
dycw_utilities-0.114.3.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/asyncio.py
CHANGED
@@ -25,6 +25,7 @@ from contextlib import (
|
|
25
25
|
)
|
26
26
|
from dataclasses import dataclass, field
|
27
27
|
from io import StringIO
|
28
|
+
from logging import getLogger
|
28
29
|
from subprocess import PIPE
|
29
30
|
from sys import stderr, stdout
|
30
31
|
from typing import (
|
@@ -41,7 +42,7 @@ from typing import (
|
|
41
42
|
|
42
43
|
from utilities.datetime import MILLISECOND, MINUTE, SECOND, datetime_duration_to_float
|
43
44
|
from utilities.errors import ImpossibleCaseError
|
44
|
-
from utilities.functions import ensure_int, ensure_not_none
|
45
|
+
from utilities.functions import ensure_int, ensure_not_none, get_class_name
|
45
46
|
from utilities.sentinel import Sentinel, sentinel
|
46
47
|
from utilities.types import (
|
47
48
|
MaybeCallableEvent,
|
@@ -59,6 +60,7 @@ if TYPE_CHECKING:
|
|
59
60
|
|
60
61
|
from utilities.types import Duration
|
61
62
|
|
63
|
+
|
62
64
|
_T = TypeVar("_T")
|
63
65
|
|
64
66
|
|
@@ -328,11 +330,12 @@ class ExceptionProcessor(QueueProcessor[Exception | type[Exception]]):
|
|
328
330
|
class InfiniteLooper(ABC, Generic[THashable]):
|
329
331
|
"""An infinite loop which can throw exceptions by setting events."""
|
330
332
|
|
333
|
+
sleep_core: Duration = SECOND
|
334
|
+
sleep_restart: Duration = MINUTE
|
335
|
+
logger: str | None = None
|
331
336
|
_events: Mapping[THashable, Event] = field(
|
332
337
|
default_factory=dict, init=False, repr=False
|
333
338
|
)
|
334
|
-
sleep_core: Duration = SECOND
|
335
|
-
sleep_restart: Duration = MINUTE
|
336
339
|
|
337
340
|
def __post_init__(self) -> None:
|
338
341
|
self._events = {
|
@@ -395,11 +398,23 @@ class InfiniteLooper(ABC, Generic[THashable]):
|
|
395
398
|
|
396
399
|
def _error_upon_initialize(self, error: Exception, /) -> None:
|
397
400
|
"""Handle any errors upon initializing the looper."""
|
398
|
-
|
401
|
+
if self.logger is not None:
|
402
|
+
getLogger(name=self.logger).error(
|
403
|
+
"Error initializing %r due to %s; sleeping for %s...",
|
404
|
+
get_class_name(self),
|
405
|
+
error,
|
406
|
+
self.sleep_restart,
|
407
|
+
)
|
399
408
|
|
400
409
|
def _error_upon_core(self, error: Exception, /) -> None:
|
401
410
|
"""Handle any errors upon running the core function."""
|
402
|
-
|
411
|
+
if self.logger is not None:
|
412
|
+
getLogger(name=self.logger).error(
|
413
|
+
"Error running core part of %r due to %s; sleeping for %s...",
|
414
|
+
get_class_name(self),
|
415
|
+
error,
|
416
|
+
self.sleep_restart,
|
417
|
+
)
|
403
418
|
|
404
419
|
def _raise_error(self, event: THashable, /) -> NoReturn:
|
405
420
|
"""Raise the error corresponding to given event."""
|
@@ -684,7 +699,9 @@ __all__ = [
|
|
684
699
|
"AsyncService",
|
685
700
|
"EnhancedTaskGroup",
|
686
701
|
"ExceptionProcessor",
|
702
|
+
"InfiniteLooper",
|
687
703
|
"InfiniteLooperError",
|
704
|
+
"InfiniteQueueLooper",
|
688
705
|
"QueueProcessor",
|
689
706
|
"StreamCommandOutput",
|
690
707
|
"UniquePriorityQueue",
|
utilities/redis.py
CHANGED
@@ -21,7 +21,7 @@ from uuid import UUID, uuid4
|
|
21
21
|
from redis.asyncio import Redis
|
22
22
|
from redis.typing import EncodableT
|
23
23
|
|
24
|
-
from utilities.asyncio import QueueProcessor, timeout_dur
|
24
|
+
from utilities.asyncio import InfiniteQueueLooper, QueueProcessor, timeout_dur
|
25
25
|
from utilities.datetime import (
|
26
26
|
MILLISECOND,
|
27
27
|
SECOND,
|
@@ -30,7 +30,7 @@ from utilities.datetime import (
|
|
30
30
|
get_now,
|
31
31
|
)
|
32
32
|
from utilities.errors import ImpossibleCaseError
|
33
|
-
from utilities.functions import ensure_int
|
33
|
+
from utilities.functions import ensure_int, get_class_name
|
34
34
|
from utilities.iterables import always_iterable, one
|
35
35
|
|
36
36
|
if TYPE_CHECKING:
|
@@ -40,6 +40,7 @@ if TYPE_CHECKING:
|
|
40
40
|
Awaitable,
|
41
41
|
Callable,
|
42
42
|
Iterable,
|
43
|
+
Iterator,
|
43
44
|
Mapping,
|
44
45
|
Sequence,
|
45
46
|
)
|
@@ -49,7 +50,7 @@ if TYPE_CHECKING:
|
|
49
50
|
from redis.typing import ResponseT
|
50
51
|
|
51
52
|
from utilities.iterables import MaybeIterable
|
52
|
-
from utilities.types import Duration, TypeLike
|
53
|
+
from utilities.types import Duration, MaybeType, TypeLike
|
53
54
|
|
54
55
|
|
55
56
|
_K = TypeVar("_K")
|
@@ -603,6 +604,42 @@ class Publisher(QueueProcessor[tuple[str, EncodableT]]):
|
|
603
604
|
)
|
604
605
|
|
605
606
|
|
607
|
+
@dataclass(kw_only=True)
|
608
|
+
class PublisherIQL(InfiniteQueueLooper[None, tuple[str, EncodableT]]):
|
609
|
+
"""Publish a set of messages to Redis."""
|
610
|
+
|
611
|
+
redis: Redis
|
612
|
+
serializer: Callable[[Any], EncodableT] | None = None
|
613
|
+
timeout: Duration = _PUBLISH_TIMEOUT
|
614
|
+
|
615
|
+
@override
|
616
|
+
async def _process_items(self, *items: tuple[str, EncodableT]) -> None:
|
617
|
+
for item in items: # skipif-ci-and-not-linux
|
618
|
+
channel, data = item
|
619
|
+
_ = await publish(
|
620
|
+
self.redis,
|
621
|
+
channel,
|
622
|
+
data,
|
623
|
+
serializer=self.serializer,
|
624
|
+
timeout=self.timeout,
|
625
|
+
)
|
626
|
+
|
627
|
+
@override
|
628
|
+
def _yield_events_and_exceptions(
|
629
|
+
self,
|
630
|
+
) -> Iterator[tuple[None, MaybeType[BaseException]]]:
|
631
|
+
yield (None, PublisherIQLError) # skipif-ci-and-not-linux
|
632
|
+
|
633
|
+
|
634
|
+
@dataclass(kw_only=True)
|
635
|
+
class PublisherIQLError(Exception):
|
636
|
+
publisher: PublisherIQL
|
637
|
+
|
638
|
+
@override
|
639
|
+
def __str__(self) -> str:
|
640
|
+
return f"Error running {get_class_name(self.publisher)!r}" # skipif-ci-and-not-linux
|
641
|
+
|
642
|
+
|
606
643
|
##
|
607
644
|
|
608
645
|
|
@@ -780,6 +817,8 @@ _ = _TestRedis
|
|
780
817
|
|
781
818
|
__all__ = [
|
782
819
|
"Publisher",
|
820
|
+
"PublisherIQL",
|
821
|
+
"PublisherIQLError",
|
783
822
|
"RedisHashMapKey",
|
784
823
|
"RedisKey",
|
785
824
|
"publish",
|
utilities/sqlalchemy.py
CHANGED
@@ -57,7 +57,7 @@ from sqlalchemy.orm import (
|
|
57
57
|
from sqlalchemy.orm.exc import UnmappedClassError
|
58
58
|
from sqlalchemy.pool import NullPool, Pool
|
59
59
|
|
60
|
-
from utilities.asyncio import QueueProcessor, timeout_dur
|
60
|
+
from utilities.asyncio import InfiniteQueueLooper, QueueProcessor, timeout_dur
|
61
61
|
from utilities.functions import (
|
62
62
|
ensure_str,
|
63
63
|
get_class_name,
|
@@ -80,7 +80,13 @@ from utilities.iterables import (
|
|
80
80
|
)
|
81
81
|
from utilities.reprlib import get_repr
|
82
82
|
from utilities.text import snake_case
|
83
|
-
from utilities.types import
|
83
|
+
from utilities.types import (
|
84
|
+
Duration,
|
85
|
+
MaybeIterable,
|
86
|
+
MaybeType,
|
87
|
+
StrMapping,
|
88
|
+
TupleOrStrMapping,
|
89
|
+
)
|
84
90
|
|
85
91
|
_T = TypeVar("_T")
|
86
92
|
type _EngineOrConnectionOrAsync = Engine | Connection | AsyncEngine | AsyncConnection
|
@@ -644,6 +650,51 @@ class Upserter(QueueProcessor[_InsertItem]):
|
|
644
650
|
await self._post_upsert(items)
|
645
651
|
|
646
652
|
|
653
|
+
@dataclass(kw_only=True)
|
654
|
+
class UpserterIQL(InfiniteQueueLooper[None, _InsertItem]):
|
655
|
+
"""Upsert a set of items to a database."""
|
656
|
+
|
657
|
+
engine: AsyncEngine
|
658
|
+
snake: bool = False
|
659
|
+
selected_or_all: _SelectedOrAll = "selected"
|
660
|
+
chunk_size_frac: float = CHUNK_SIZE_FRAC
|
661
|
+
assume_tables_exist: bool = False
|
662
|
+
timeout_create: Duration | None = None
|
663
|
+
error_create: type[Exception] = TimeoutError
|
664
|
+
timeout_insert: Duration | None = None
|
665
|
+
error_insert: type[Exception] = TimeoutError
|
666
|
+
|
667
|
+
@override
|
668
|
+
async def _process_items(self, *items: _InsertItem) -> None:
|
669
|
+
await upsert_items(
|
670
|
+
self.engine,
|
671
|
+
*items,
|
672
|
+
snake=self.snake,
|
673
|
+
selected_or_all=self.selected_or_all,
|
674
|
+
chunk_size_frac=self.chunk_size_frac,
|
675
|
+
assume_tables_exist=self.assume_tables_exist,
|
676
|
+
timeout_create=self.timeout_create,
|
677
|
+
error_create=self.error_create,
|
678
|
+
timeout_insert=self.timeout_insert,
|
679
|
+
error_insert=self.error_insert,
|
680
|
+
)
|
681
|
+
|
682
|
+
@override
|
683
|
+
def _yield_events_and_exceptions(
|
684
|
+
self,
|
685
|
+
) -> Iterator[tuple[None, MaybeType[BaseException]]]:
|
686
|
+
yield (None, UpserterIQLError)
|
687
|
+
|
688
|
+
|
689
|
+
@dataclass(kw_only=True)
|
690
|
+
class UpserterIQLError(Exception):
|
691
|
+
upserter: UpserterIQL
|
692
|
+
|
693
|
+
@override
|
694
|
+
def __str__(self) -> str:
|
695
|
+
return f"Error running {get_class_name(self.upserter)!r}"
|
696
|
+
|
697
|
+
|
647
698
|
##
|
648
699
|
|
649
700
|
|
@@ -1099,6 +1150,9 @@ __all__ = [
|
|
1099
1150
|
"InsertItemsError",
|
1100
1151
|
"TablenameMixin",
|
1101
1152
|
"UpsertItemsError",
|
1153
|
+
"Upserter",
|
1154
|
+
"UpserterIQL",
|
1155
|
+
"UpserterIQLError",
|
1102
1156
|
"check_engine",
|
1103
1157
|
"columnwise_max",
|
1104
1158
|
"columnwise_min",
|
File without changes
|
File without changes
|