haiway 0.10.15__py3-none-any.whl → 0.10.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.
- haiway/__init__.py +111 -0
- haiway/context/__init__.py +27 -0
- haiway/context/access.py +615 -0
- haiway/context/disposables.py +78 -0
- haiway/context/identifier.py +92 -0
- haiway/context/logging.py +176 -0
- haiway/context/metrics.py +165 -0
- haiway/context/state.py +113 -0
- haiway/context/tasks.py +64 -0
- haiway/context/types.py +12 -0
- haiway/helpers/__init__.py +21 -0
- haiway/helpers/asynchrony.py +225 -0
- haiway/helpers/caching.py +326 -0
- haiway/helpers/metrics.py +459 -0
- haiway/helpers/retries.py +223 -0
- haiway/helpers/throttling.py +133 -0
- haiway/helpers/timeouted.py +112 -0
- haiway/helpers/tracing.py +137 -0
- haiway/py.typed +0 -0
- haiway/state/__init__.py +12 -0
- haiway/state/attributes.py +747 -0
- haiway/state/path.py +542 -0
- haiway/state/requirement.py +229 -0
- haiway/state/structure.py +414 -0
- haiway/state/validation.py +468 -0
- haiway/types/__init__.py +14 -0
- haiway/types/default.py +108 -0
- haiway/types/frozen.py +5 -0
- haiway/types/missing.py +95 -0
- haiway/utils/__init__.py +28 -0
- haiway/utils/always.py +61 -0
- haiway/utils/collections.py +185 -0
- haiway/utils/env.py +230 -0
- haiway/utils/freezing.py +28 -0
- haiway/utils/logs.py +57 -0
- haiway/utils/mimic.py +77 -0
- haiway/utils/noop.py +24 -0
- haiway/utils/queue.py +82 -0
- {haiway-0.10.15.dist-info → haiway-0.10.17.dist-info}/METADATA +1 -1
- haiway-0.10.17.dist-info/RECORD +42 -0
- haiway-0.10.15.dist-info/RECORD +0 -4
- {haiway-0.10.15.dist-info → haiway-0.10.17.dist-info}/WHEEL +0 -0
- {haiway-0.10.15.dist-info → haiway-0.10.17.dist-info}/licenses/LICENSE +0 -0
haiway/utils/queue.py
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
from asyncio import AbstractEventLoop, CancelledError, Future, get_running_loop
|
2
|
+
from collections import deque
|
3
|
+
from collections.abc import AsyncIterator
|
4
|
+
|
5
|
+
__all__ = [
|
6
|
+
"AsyncQueue",
|
7
|
+
]
|
8
|
+
|
9
|
+
|
10
|
+
class AsyncQueue[Element](AsyncIterator[Element]):
|
11
|
+
"""
|
12
|
+
Asynchronous queue supporting iteration and finishing.
|
13
|
+
Cannot be concurrently consumed by multiple readers.
|
14
|
+
"""
|
15
|
+
|
16
|
+
def __init__(
|
17
|
+
self,
|
18
|
+
*elements: Element,
|
19
|
+
loop: AbstractEventLoop | None = None,
|
20
|
+
) -> None:
|
21
|
+
self._loop: AbstractEventLoop = loop or get_running_loop()
|
22
|
+
self._queue: deque[Element] = deque(elements)
|
23
|
+
self._waiting: Future[Element] | None = None
|
24
|
+
self._finish_reason: BaseException | None = None
|
25
|
+
|
26
|
+
def __del__(self) -> None:
|
27
|
+
self.finish()
|
28
|
+
|
29
|
+
@property
|
30
|
+
def is_finished(self) -> bool:
|
31
|
+
return self._finish_reason is not None
|
32
|
+
|
33
|
+
def enqueue(
|
34
|
+
self,
|
35
|
+
element: Element,
|
36
|
+
/,
|
37
|
+
*elements: Element,
|
38
|
+
) -> None:
|
39
|
+
if self.is_finished:
|
40
|
+
raise RuntimeError("AsyncQueue is already finished")
|
41
|
+
|
42
|
+
if self._waiting is not None and not self._waiting.done():
|
43
|
+
self._waiting.set_result(element)
|
44
|
+
|
45
|
+
else:
|
46
|
+
self._queue.append(element)
|
47
|
+
|
48
|
+
self._queue.extend(elements)
|
49
|
+
|
50
|
+
def finish(
|
51
|
+
self,
|
52
|
+
exception: BaseException | None = None,
|
53
|
+
) -> None:
|
54
|
+
if self.is_finished:
|
55
|
+
return # already finished, ignore
|
56
|
+
|
57
|
+
self._finish_reason = exception or StopAsyncIteration()
|
58
|
+
|
59
|
+
if self._waiting is not None and not self._waiting.done():
|
60
|
+
self._waiting.set_exception(self._finish_reason)
|
61
|
+
|
62
|
+
def cancel(self) -> None:
|
63
|
+
self.finish(exception=CancelledError())
|
64
|
+
|
65
|
+
async def __anext__(self) -> Element:
|
66
|
+
assert self._waiting is None, "Only a single queue consumer is supported!" # nosec: B101
|
67
|
+
|
68
|
+
if self._queue: # check the queue, let it finish
|
69
|
+
return self._queue.popleft()
|
70
|
+
|
71
|
+
if self._finish_reason is not None: # check if is finished
|
72
|
+
raise self._finish_reason
|
73
|
+
|
74
|
+
try:
|
75
|
+
# create a new future to wait for next
|
76
|
+
self._waiting = self._loop.create_future()
|
77
|
+
# wait for the result
|
78
|
+
return await self._waiting
|
79
|
+
|
80
|
+
finally:
|
81
|
+
# cleanup
|
82
|
+
self._waiting = None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: haiway
|
3
|
-
Version: 0.10.
|
3
|
+
Version: 0.10.17
|
4
4
|
Summary: Framework for dependency injection and state management within structured concurrency model.
|
5
5
|
Project-URL: Homepage, https://miquido.com
|
6
6
|
Project-URL: Repository, https://github.com/miquido/haiway.git
|
@@ -0,0 +1,42 @@
|
|
1
|
+
haiway/__init__.py,sha256=IEUCyFYKT5IPHnkiUvDVZHdJeHqCaBnG8FhPD20Zgo8,1929
|
2
|
+
haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
haiway/context/__init__.py,sha256=eRvuhifx7xCd-_6desgk55idzNpD5S5sprmCfGb3_9M,662
|
4
|
+
haiway/context/access.py,sha256=Fc2NfoIV2zWE5qPnNgSitK1dy-PME-rJJfUPhoNwJzY,17125
|
5
|
+
haiway/context/disposables.py,sha256=DZjnMp-wMfF-em2Wjhbm1MvXubNpuzFBT70BQNIxC7M,2019
|
6
|
+
haiway/context/identifier.py,sha256=Fyb6OHx5FPaSLLRK249HUEr_KlBSG5F-eW01Oxg_Ke8,2570
|
7
|
+
haiway/context/logging.py,sha256=ptwgENuyw-WFgokVsYx9OXZGhJENuO_wgfVjcBryUKM,4251
|
8
|
+
haiway/context/metrics.py,sha256=Ve628X39u0rdLm0vYmVZt7aGeoEeRquR6f67vJIXClY,4213
|
9
|
+
haiway/context/state.py,sha256=LCcFxXqDBu6prvPyPicN-ecONSNHyR56PfQ5u5jNFCU,3000
|
10
|
+
haiway/context/tasks.py,sha256=h6OxLxHHqkw0LfQi81NtbsCKfACKxYRZAkDhlJTpqCM,1904
|
11
|
+
haiway/context/types.py,sha256=VvJA7wAPZ3ISpgyThVguioYUXqhHf0XkPfRd0M1ERiQ,142
|
12
|
+
haiway/helpers/__init__.py,sha256=8XRJWNhidWuBKqRZ1Hyc2xqt7DeWLcoOs2V-oexl8VY,579
|
13
|
+
haiway/helpers/asynchrony.py,sha256=9lo9wT3G0TyPb4vfmTnWGBvB_eN6p6nIlj46_9Ag8fQ,6022
|
14
|
+
haiway/helpers/caching.py,sha256=Ok_WE5Whe7XqnIuLZo4rNNBFeWap-aUWX799s4b1JAQ,9536
|
15
|
+
haiway/helpers/metrics.py,sha256=0oFBiO-hAzihyC5jvXevNrYOoTcUGc2yGhE1A_866Mc,13314
|
16
|
+
haiway/helpers/retries.py,sha256=gIkyUlqJLDYaxIZd3qzeqGFY9y5Gp8dgZLlZ6hs8hoc,7538
|
17
|
+
haiway/helpers/throttling.py,sha256=zo0OwFq64si5KUwhd58cFHLmGAmYwRbFRJMbv9suhPs,3844
|
18
|
+
haiway/helpers/timeouted.py,sha256=1xU09hQnFdj6p48BwZl5xUvtIr3zC0ZUXehkdrduCjs,3074
|
19
|
+
haiway/helpers/tracing.py,sha256=VDOAhdVELaYs92HxHreEo_ZV8b7e6ZQs10lTNn8xOtQ,3383
|
20
|
+
haiway/state/__init__.py,sha256=emTuwGFn7HyjyTJ_ass69J5jQIA7_WHO4teZz_dR05Y,355
|
21
|
+
haiway/state/attributes.py,sha256=plCcYGE5LVU1Nvo0GHkhThqFG96uLR3tFsisQyK1jK0,23122
|
22
|
+
haiway/state/path.py,sha256=p-ZVSDU02qAUDln12SDc1pGWzhZ88-1zYEBC0hqceXM,17930
|
23
|
+
haiway/state/requirement.py,sha256=3iQqzp5Q7w6y5uClamJGH7S5Hib9pciuTAV27PP5lS8,6161
|
24
|
+
haiway/state/structure.py,sha256=bSIj0S_HG-F1Z5GxSlY6VpGtrtiwG82-AIL_PL1lRLo,12465
|
25
|
+
haiway/state/validation.py,sha256=r0EMIs-nvoXsmSA74oGu6Lrbw8lkzmseaY82_-E8ous,13814
|
26
|
+
haiway/types/__init__.py,sha256=-j4uDN6ix3GBXLBqXC-k_QOJSDlO6zvNCxDej8vVzek,342
|
27
|
+
haiway/types/default.py,sha256=IVQsNzDnfukL3-XlScYv2PgTcJ1x_BNP9i5UlS5oEbg,2179
|
28
|
+
haiway/types/frozen.py,sha256=CZhFCXnWAKEhuWSfILxA8smfdpMd5Ku694ycfLh98R8,76
|
29
|
+
haiway/types/missing.py,sha256=rDnyA2wxPkTbJl0L-zbo0owp7IJ04xkCIp6xD6wh8NI,1712
|
30
|
+
haiway/utils/__init__.py,sha256=O7qmAmUktX-X_5D1L5FJMeCFEiOVrrnyYSyiycm4nyg,739
|
31
|
+
haiway/utils/always.py,sha256=2abp8Lm9rQkrfS3rm1Iqhb-IcWyVfH1BULab3KMxgOw,1234
|
32
|
+
haiway/utils/collections.py,sha256=pKHZhXqTMcOth7gV6mXcC5WcSyBl70MmVIELbDSmMoA,3320
|
33
|
+
haiway/utils/env.py,sha256=vlW21LEp8uOVNnUXpBfPtj3zKi9Kkjoemb_H5hQpYPQ,4433
|
34
|
+
haiway/utils/freezing.py,sha256=K34ZIMzbkpgkHKH-KF73plEbXExsajNRkRTYp9nJEf4,620
|
35
|
+
haiway/utils/logs.py,sha256=oDsc1ZdqKDjlTlctLbDcp9iX98Acr-1tdw-Pyg3DElo,1577
|
36
|
+
haiway/utils/mimic.py,sha256=BkVjTVP2TxxC8GChPGyDV6UXVwJmiRiSWeOYZNZFHxs,1828
|
37
|
+
haiway/utils/noop.py,sha256=qgbZlOKWY6_23Zs43OLukK2HagIQKRyR04zrFVm5rWI,344
|
38
|
+
haiway/utils/queue.py,sha256=oQ3GXCJ-PGNtMEr6EPdgqAvYZoj8lAa7Z2drBKBEoBM,2345
|
39
|
+
haiway-0.10.17.dist-info/METADATA,sha256=IwCgN_53mbzSI8qNibPFrXQT_pwJnA34YxZY1BNdrc8,3858
|
40
|
+
haiway-0.10.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
41
|
+
haiway-0.10.17.dist-info/licenses/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
|
42
|
+
haiway-0.10.17.dist-info/RECORD,,
|
haiway-0.10.15.dist-info/RECORD
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
haiway-0.10.15.dist-info/METADATA,sha256=zb14EnZGhmxkP0nOzp2J1a3ZUCz1njWu4LtvN3K7_P4,3858
|
2
|
-
haiway-0.10.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
3
|
-
haiway-0.10.15.dist-info/licenses/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
|
4
|
-
haiway-0.10.15.dist-info/RECORD,,
|
File without changes
|
File without changes
|