dycw-utilities 0.113.5__py3-none-any.whl → 0.114.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.113.5
3
+ Version: 0.114.0
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,7 +1,7 @@
1
- utilities/__init__.py,sha256=ZrPzCX_NTAeiRK-IwTswtKYPrKcHyvHM-9skmFcsa3Q,60
1
+ utilities/__init__.py,sha256=qECk5Uaq4SsKcMpFjNUaChs2N78j3evztQRVgKylt4g,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=q6hRkJ8GLJcmbah9ifdkw9LUcXAZlLh0g10aZ8cjZ54,17883
4
+ utilities/asyncio.py,sha256=a4riQIfTYCe4oxXUbbuP7YB3tIlzmYxYDC9XygdsrQc,17637
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
@@ -64,9 +64,9 @@ utilities/rich.py,sha256=t50MwwVBsoOLxzmeVFSVpjno4OW6Ufum32skXbV8-Bs,1911
64
64
  utilities/scipy.py,sha256=X6ROnHwiUhAmPhM0jkfEh0-Fd9iRvwiqtCQMOLmOQF8,945
65
65
  utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
66
66
  utilities/shelve.py,sha256=HZsMwK4tcIfg3sh0gApx4-yjQnrY4o3V3ZRimvRhoW0,738
67
- utilities/slack_sdk.py,sha256=SeDNMh24IPiEBWoGMdgvrflUaFa9TGlTS03H9-NKaQw,4132
67
+ utilities/slack_sdk.py,sha256=Gbla983KulSSXnNyzaXgYQLKoq84KvLH8SdhxU-jQ0Q,4126
68
68
  utilities/socket.py,sha256=K77vfREvzoVTrpYKo6MZakol0EYu2q1sWJnnZqL0So0,118
69
- utilities/sqlalchemy.py,sha256=GWzp54TP3F2mGhxPTn0c56KxxDeN9VKLMagcRSELhf4,35453
69
+ utilities/sqlalchemy.py,sha256=bs7rD1f8yB0uaFMYgmjo8wEoGow0x6aiELSYTPY_Img,35447
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.113.5.dist-info/METADATA,sha256=A14piT2adjIjfWnw8bf7FeFVUDRZfuzcsKkbFdZLrzc,12943
91
- dycw_utilities-0.113.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
- dycw_utilities-0.113.5.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
- dycw_utilities-0.113.5.dist-info/RECORD,,
90
+ dycw_utilities-0.114.0.dist-info/METADATA,sha256=plrwlVumL52G3Ix8B_ywj9b6hpqMXiheJfgTbbD5P_c,12943
91
+ dycw_utilities-0.114.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ dycw_utilities-0.114.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
93
+ dycw_utilities-0.114.0.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.113.5"
3
+ __version__ = "0.114.0"
utilities/asyncio.py CHANGED
@@ -4,7 +4,6 @@ from abc import ABC, abstractmethod
4
4
  from asyncio import (
5
5
  CancelledError,
6
6
  Event,
7
- Lock,
8
7
  PriorityQueue,
9
8
  Queue,
10
9
  QueueEmpty,
@@ -17,7 +16,7 @@ from asyncio import (
17
16
  sleep,
18
17
  timeout,
19
18
  )
20
- from collections.abc import Callable, Mapping
19
+ from collections.abc import Callable, Iterable, Mapping
21
20
  from contextlib import (
22
21
  AsyncExitStack,
23
22
  _AsyncGeneratorContextManager,
@@ -240,7 +239,6 @@ class QueueProcessor(AsyncService, Generic[_T]):
240
239
  sleep: Duration = MILLISECOND
241
240
  _await_upon_aenter: bool = field(default=False, init=False, repr=False)
242
241
  _queue: Queue[_T] = field(init=False, repr=False)
243
- _lock: Lock = field(default_factory=Lock, init=False, repr=False)
244
242
 
245
243
  def __post_init__(self) -> None:
246
244
  self._queue = self.queue_type(
@@ -265,9 +263,9 @@ class QueueProcessor(AsyncService, Generic[_T]):
265
263
  await self._run()
266
264
  await sleep_dur(duration=self.sleep)
267
265
 
268
- async def _get_items_nowait(self, *, max_size: int | None = None) -> Sequence[_T]:
266
+ def _get_items_nowait(self, *, max_size: int | None = None) -> Sequence[_T]:
269
267
  """Get items from the queue; no waiting."""
270
- return await get_items_nowait(self._queue, max_size=max_size, lock=self._lock)
268
+ return get_items_nowait(self._queue, max_size=max_size)
271
269
 
272
270
  @abstractmethod
273
271
  async def _process_item(self, item: _T, /) -> None:
@@ -282,7 +280,7 @@ class QueueProcessor(AsyncService, Generic[_T]):
282
280
  async def _run(self) -> None:
283
281
  """Run the processer."""
284
282
  try:
285
- (item,) = await self._get_items_nowait(max_size=1)
283
+ (item,) = self._get_items_nowait(max_size=1)
286
284
  except ValueError:
287
285
  raise QueueEmpty from None
288
286
  try:
@@ -465,9 +463,7 @@ def get_event(
465
463
  ##
466
464
 
467
465
 
468
- async def get_items(
469
- queue: Queue[_T], /, *, max_size: int | None = None, lock: Lock | None = None
470
- ) -> list[_T]:
466
+ async def get_items(queue: Queue[_T], /, *, max_size: int | None = None) -> list[_T]:
471
467
  """Get items from a queue; if empty then wait."""
472
468
  try:
473
469
  items = [await queue.get()]
@@ -476,28 +472,12 @@ async def get_items(
476
472
  return []
477
473
  raise
478
474
  max_size_use = None if max_size is None else (max_size - 1)
479
- if lock is None:
480
- items.extend(await get_items_nowait(queue, max_size=max_size_use))
481
- else:
482
- async with lock:
483
- items.extend(await get_items_nowait(queue, max_size=max_size_use))
475
+ items.extend(get_items_nowait(queue, max_size=max_size_use))
484
476
  return items
485
477
 
486
478
 
487
- async def get_items_nowait(
488
- queue: Queue[_T], /, *, max_size: int | None = None, lock: Lock | None = None
489
- ) -> list[_T]:
479
+ def get_items_nowait(queue: Queue[_T], /, *, max_size: int | None = None) -> list[_T]:
490
480
  """Get items from a queue; no waiting."""
491
- if lock is None:
492
- return _get_items_nowait_core(queue, max_size=max_size)
493
- async with lock:
494
- return _get_items_nowait_core(queue, max_size=max_size)
495
-
496
-
497
- def _get_items_nowait_core(
498
- queue: Queue[_T], /, *, max_size: int | None = None
499
- ) -> list[_T]:
500
- """Get all the items from a queue; no waiting."""
501
481
  items: list[_T] = []
502
482
  if max_size is None:
503
483
  while True:
@@ -517,6 +497,21 @@ def _get_items_nowait_core(
517
497
  ##
518
498
 
519
499
 
500
+ async def put_items(items: Iterable[_T], queue: Queue[_T], /) -> None:
501
+ """Put items into a queue; if full then wait."""
502
+ for item in items:
503
+ await queue.put(item)
504
+
505
+
506
+ def put_items_nowait(items: Iterable[_T], queue: Queue[_T], /) -> None:
507
+ """Put items into a queue; no waiting."""
508
+ for item in items:
509
+ queue.put_nowait(item)
510
+
511
+
512
+ ##
513
+
514
+
520
515
  async def sleep_dur(*, duration: Duration | None = None) -> None:
521
516
  """Sleep which accepts durations."""
522
517
  if duration is None:
@@ -602,6 +597,8 @@ __all__ = [
602
597
  "get_event",
603
598
  "get_items",
604
599
  "get_items_nowait",
600
+ "put_items",
601
+ "put_items_nowait",
605
602
  "sleep_dur",
606
603
  "stream_command",
607
604
  "timeout_dur",
utilities/slack_sdk.py CHANGED
@@ -78,7 +78,7 @@ class SlackHandler(Handler, QueueProcessor[str]):
78
78
  @override
79
79
  async def _process_item(self, item: str, /) -> None:
80
80
  """Process the first item."""
81
- items = list(chain([item], await self._get_items_nowait()))
81
+ items = list(chain([item], self._get_items_nowait()))
82
82
  text = "\n".join(items)
83
83
  try:
84
84
  async with timeout_dur(duration=self.timeout):
utilities/sqlalchemy.py CHANGED
@@ -627,7 +627,7 @@ class Upserter(QueueProcessor[_InsertItem]):
627
627
  @override
628
628
  async def _process_item(self, item: _InsertItem, /) -> None:
629
629
  """Process the first item."""
630
- items = list(chain([item], await self._get_items_nowait()))
630
+ items = list(chain([item], self._get_items_nowait()))
631
631
  await self._pre_upsert(items)
632
632
  await upsert_items(
633
633
  self.engine,