queutils 0.8.5__py3-none-any.whl → 0.9.1__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.
- queutils/__init__.py +5 -0
- queutils/categorycounterqueue.py +116 -0
- {queutils-0.8.5.dist-info → queutils-0.9.1.dist-info}/METADATA +5 -2
- queutils-0.9.1.dist-info/RECORD +11 -0
- {queutils-0.8.5.dist-info → queutils-0.9.1.dist-info}/WHEEL +1 -1
- queutils-0.8.5.dist-info/RECORD +0 -10
- {queutils-0.8.5.dist-info → queutils-0.9.1.dist-info}/licenses/LICENSE +0 -0
queutils/__init__.py
CHANGED
@@ -2,10 +2,15 @@ from .countable import Countable as Countable
|
|
2
2
|
from .asyncqueue import AsyncQueue as AsyncQueue
|
3
3
|
from .iterablequeue import IterableQueue as IterableQueue, QueueDone as QueueDone
|
4
4
|
from .filequeue import FileQueue as FileQueue
|
5
|
+
from .categorycounterqueue import (
|
6
|
+
QCounter as QCounter,
|
7
|
+
CategoryCounterQueue as CategoryCounterQueue,
|
8
|
+
)
|
5
9
|
|
6
10
|
__all__ = [
|
7
11
|
"asyncqueue",
|
8
12
|
"countable",
|
13
|
+
"categorycounterqueue",
|
9
14
|
"filequeue",
|
10
15
|
"iterablequeue",
|
11
16
|
]
|
@@ -0,0 +1,116 @@
|
|
1
|
+
from asyncio import Queue
|
2
|
+
from typing import TypeVar
|
3
|
+
from deprecated import deprecated
|
4
|
+
from .countable import Countable
|
5
|
+
from .iterablequeue import IterableQueue, QueueDone
|
6
|
+
from collections import defaultdict
|
7
|
+
import logging
|
8
|
+
|
9
|
+
logger = logging.getLogger()
|
10
|
+
error = logger.error
|
11
|
+
message = logger.warning
|
12
|
+
verbose = logger.info
|
13
|
+
debug = logger.debug
|
14
|
+
|
15
|
+
###########################################
|
16
|
+
#
|
17
|
+
# class CounterQueue
|
18
|
+
#
|
19
|
+
###########################################
|
20
|
+
T = TypeVar("T")
|
21
|
+
|
22
|
+
|
23
|
+
@deprecated(version="0.9.1", reason="Use CategoryCounterQueue instead")
|
24
|
+
class CounterQueue(Queue[T], Countable):
|
25
|
+
"""
|
26
|
+
CounterQueue is a asyncio.Queue for counting items
|
27
|
+
"""
|
28
|
+
|
29
|
+
_counter: int
|
30
|
+
_count_items: bool
|
31
|
+
_batch: int
|
32
|
+
|
33
|
+
def __init__(
|
34
|
+
self, *args, count_items: bool = True, batch: int = 1, **kwargs
|
35
|
+
) -> None:
|
36
|
+
super().__init__(*args, **kwargs)
|
37
|
+
self._counter = 0
|
38
|
+
self._count_items = count_items
|
39
|
+
self._batch = batch
|
40
|
+
|
41
|
+
def task_done(self) -> None:
|
42
|
+
super().task_done()
|
43
|
+
if self._count_items:
|
44
|
+
self._counter += 1
|
45
|
+
return None
|
46
|
+
|
47
|
+
@property
|
48
|
+
def count(self) -> int:
|
49
|
+
"""Return number of completed tasks"""
|
50
|
+
return self._counter * self._batch
|
51
|
+
|
52
|
+
@property
|
53
|
+
def count_items(self) -> bool:
|
54
|
+
"""Whether or not count items"""
|
55
|
+
return self._count_items
|
56
|
+
|
57
|
+
|
58
|
+
class CategoryCounterQueue(IterableQueue[tuple[str, int]]):
|
59
|
+
"""
|
60
|
+
CategorySummerQueue is a asyncio.Queue for summing up values by category
|
61
|
+
"""
|
62
|
+
|
63
|
+
_counter: defaultdict[str, int]
|
64
|
+
_batch: int
|
65
|
+
|
66
|
+
def __init__(self, *args, batch: int = 1, **kwargs) -> None:
|
67
|
+
super().__init__(*args, **kwargs)
|
68
|
+
self._batch = batch
|
69
|
+
self._counter = defaultdict(int)
|
70
|
+
|
71
|
+
async def receive(self) -> tuple[str, int]:
|
72
|
+
"""Receive a category value from the queue and sum it"""
|
73
|
+
category: str
|
74
|
+
value: int
|
75
|
+
category, value = await super().get()
|
76
|
+
self._counter[category] += value
|
77
|
+
super().task_done()
|
78
|
+
return (category, value)
|
79
|
+
|
80
|
+
async def send(self, category: str = "count", value: int = 1) -> None:
|
81
|
+
"""Send count of a category"""
|
82
|
+
await super().put((category, value))
|
83
|
+
return None
|
84
|
+
|
85
|
+
def get_count(self, category: str = "count") -> int:
|
86
|
+
"""Return count of a category"""
|
87
|
+
return self._counter[category]
|
88
|
+
|
89
|
+
def get_counts(self) -> defaultdict[str, int]:
|
90
|
+
"""Return counts of all categories"""
|
91
|
+
return self._counter
|
92
|
+
|
93
|
+
async def listen(self) -> defaultdict[str, int]:
|
94
|
+
"""Listen for category values"""
|
95
|
+
try:
|
96
|
+
while True:
|
97
|
+
await self.receive()
|
98
|
+
except QueueDone:
|
99
|
+
pass
|
100
|
+
return self.get_counts()
|
101
|
+
|
102
|
+
|
103
|
+
class QCounter:
|
104
|
+
def __init__(self, Q: Queue[int]):
|
105
|
+
self._count = 0
|
106
|
+
self._Q: Queue[int] = Q
|
107
|
+
|
108
|
+
@property
|
109
|
+
def count(self) -> int:
|
110
|
+
return self._count
|
111
|
+
|
112
|
+
async def start(self) -> None:
|
113
|
+
"""Read and count items from Q"""
|
114
|
+
while True:
|
115
|
+
self._count += await self._Q.get()
|
116
|
+
self._Q.task_done()
|
@@ -1,10 +1,11 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: queutils
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.9.1
|
4
4
|
Summary: Handy Python Queue utilies
|
5
5
|
Project-URL: Homepage, https://github.com/Jylpah/queutils
|
6
6
|
Project-URL: Bug Tracker, https://github.com/Jylpah/queutils/issues
|
7
7
|
Author-email: Jylpah <jylpah@gmail.com>
|
8
|
+
License-File: LICENSE
|
8
9
|
Classifier: Development Status :: 4 - Beta
|
9
10
|
Classifier: Framework :: AsyncIO
|
10
11
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -13,6 +14,7 @@ Classifier: Programming Language :: Python :: 3
|
|
13
14
|
Classifier: Topic :: Software Development :: Libraries
|
14
15
|
Requires-Python: >=3.11
|
15
16
|
Requires-Dist: aioconsole>=0.6
|
17
|
+
Requires-Dist: deprecated>=1.2.18
|
16
18
|
Provides-Extra: dev
|
17
19
|
Requires-Dist: build>=0.10; extra == 'dev'
|
18
20
|
Requires-Dist: hatchling>=1.22.4; extra == 'dev'
|
@@ -24,6 +26,7 @@ Requires-Dist: pytest-datafiles>=3.0; extra == 'dev'
|
|
24
26
|
Requires-Dist: pytest-timeout>=2.2; extra == 'dev'
|
25
27
|
Requires-Dist: pytest>=8.0; extra == 'dev'
|
26
28
|
Requires-Dist: ruff>=0.1.9; extra == 'dev'
|
29
|
+
Requires-Dist: types-deprecated>=1.2.15; extra == 'dev'
|
27
30
|
Description-Content-Type: text/markdown
|
28
31
|
|
29
32
|
[](https://github.com/Jylpah/queutils/actions/workflows/python-package.yml) [](https://codecov.io/gh/Jylpah/queutils)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
queutils/__init__.py,sha256=buANyRlxO1x4G_EBE3tYFpPtZGSepJDKRkWl-zKct1M,453
|
2
|
+
queutils/asyncqueue.py,sha256=GZRmlWTBQoKzTf7xr4MI-qhNqvIiaNWswAxFokP91Lg,2789
|
3
|
+
queutils/categorycounterqueue.py,sha256=Ku5pAJXSsoNyUsuWkQe9w7SaPeiPwPHFMdZFqA0LtBw,3097
|
4
|
+
queutils/countable.py,sha256=YSi7ILf9CuB5Tm3T4UUMEFlveqzqcmomfqJAlLGHEz8,172
|
5
|
+
queutils/filequeue.py,sha256=q2ly9H-lSCq6xuOqT1IlWgyCVyLoZiKbc0NuzmkF4aw,5360
|
6
|
+
queutils/iterablequeue.py,sha256=ZXwa9040yTawL1DMMNBXgQKiYr32nmzuSbgi-raAtZc,8664
|
7
|
+
queutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
queutils-0.9.1.dist-info/METADATA,sha256=zT3br-kHUXjDGp2QhPxW_K-EvP212VUYWZNbjTb-MUA,4281
|
9
|
+
queutils-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
queutils-0.9.1.dist-info/licenses/LICENSE,sha256=J1zeIKU2JVQmhwO2hHQDK8WR6zjVZ-wX8r7ZlL45AbI,1063
|
11
|
+
queutils-0.9.1.dist-info/RECORD,,
|
queutils-0.8.5.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
queutils/__init__.py,sha256=MboAom80iQTQURz0liGv_f2ae2Np8YA5ORX1LwsNa50,311
|
2
|
-
queutils/asyncqueue.py,sha256=GZRmlWTBQoKzTf7xr4MI-qhNqvIiaNWswAxFokP91Lg,2789
|
3
|
-
queutils/countable.py,sha256=YSi7ILf9CuB5Tm3T4UUMEFlveqzqcmomfqJAlLGHEz8,172
|
4
|
-
queutils/filequeue.py,sha256=q2ly9H-lSCq6xuOqT1IlWgyCVyLoZiKbc0NuzmkF4aw,5360
|
5
|
-
queutils/iterablequeue.py,sha256=ZXwa9040yTawL1DMMNBXgQKiYr32nmzuSbgi-raAtZc,8664
|
6
|
-
queutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
queutils-0.8.5.dist-info/METADATA,sha256=6sJ7O4naraaat7-8ZFeTD9c_r1RFM9uDtkotLuX6aq0,4169
|
8
|
-
queutils-0.8.5.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
9
|
-
queutils-0.8.5.dist-info/licenses/LICENSE,sha256=J1zeIKU2JVQmhwO2hHQDK8WR6zjVZ-wX8r7ZlL45AbI,1063
|
10
|
-
queutils-0.8.5.dist-info/RECORD,,
|
File without changes
|