haiway 0.1.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.
- haiway/__init__.py +75 -0
- haiway/context/__init__.py +14 -0
- haiway/context/access.py +416 -0
- haiway/context/dependencies.py +61 -0
- haiway/context/metrics.py +329 -0
- haiway/context/state.py +115 -0
- haiway/context/tasks.py +65 -0
- haiway/context/types.py +17 -0
- haiway/helpers/__init__.py +13 -0
- haiway/helpers/asynchronous.py +226 -0
- haiway/helpers/cache.py +326 -0
- haiway/helpers/retry.py +210 -0
- haiway/helpers/throttling.py +133 -0
- haiway/helpers/timeout.py +112 -0
- haiway/py.typed +0 -0
- haiway/state/__init__.py +8 -0
- haiway/state/attributes.py +360 -0
- haiway/state/structure.py +254 -0
- haiway/state/validation.py +125 -0
- haiway/types/__init__.py +11 -0
- haiway/types/frozen.py +5 -0
- haiway/types/missing.py +91 -0
- haiway/utils/__init__.py +23 -0
- haiway/utils/always.py +61 -0
- haiway/utils/env.py +164 -0
- haiway/utils/immutable.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 +89 -0
- haiway-0.1.0.dist-info/LICENSE +21 -0
- haiway-0.1.0.dist-info/METADATA +86 -0
- haiway-0.1.0.dist-info/RECORD +35 -0
- haiway-0.1.0.dist-info/WHEEL +5 -0
- haiway-0.1.0.dist-info/top_level.txt +1 -0
haiway/utils/queue.py
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
from asyncio import AbstractEventLoop, CancelledError, Future, get_running_loop
|
2
|
+
from collections import deque
|
3
|
+
from collections.abc import AsyncIterator
|
4
|
+
from typing import Self
|
5
|
+
|
6
|
+
from haiway.utils.immutable import freeze
|
7
|
+
|
8
|
+
__all__ = [
|
9
|
+
"AsyncQueue",
|
10
|
+
]
|
11
|
+
|
12
|
+
|
13
|
+
class AsyncQueue[Element](AsyncIterator[Element]):
|
14
|
+
"""
|
15
|
+
Asynchronous queue supporting iteration and finishing.
|
16
|
+
Cannot be concurrently consumed by multiple readers.
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __init__(
|
20
|
+
self,
|
21
|
+
loop: AbstractEventLoop | None = None,
|
22
|
+
) -> None:
|
23
|
+
self._loop: AbstractEventLoop = loop or get_running_loop()
|
24
|
+
self._queue: deque[Element] = deque()
|
25
|
+
self._waiting: Future[Element] | None = None
|
26
|
+
self._finish_reason: BaseException | None = None
|
27
|
+
|
28
|
+
freeze(self)
|
29
|
+
|
30
|
+
def __del__(self) -> None:
|
31
|
+
self.finish()
|
32
|
+
|
33
|
+
@property
|
34
|
+
def finished(self) -> bool:
|
35
|
+
return self._finish_reason is not None
|
36
|
+
|
37
|
+
def enqueue(
|
38
|
+
self,
|
39
|
+
element: Element,
|
40
|
+
/,
|
41
|
+
*elements: Element,
|
42
|
+
) -> None:
|
43
|
+
if self.finished:
|
44
|
+
raise RuntimeError("AsyncQueue is already finished")
|
45
|
+
|
46
|
+
if self._waiting is not None and not self._waiting.done():
|
47
|
+
self._waiting.set_result(element)
|
48
|
+
|
49
|
+
else:
|
50
|
+
self._queue.append(element)
|
51
|
+
|
52
|
+
self._queue.extend(elements)
|
53
|
+
|
54
|
+
def finish(
|
55
|
+
self,
|
56
|
+
exception: BaseException | None = None,
|
57
|
+
) -> None:
|
58
|
+
if self.finished:
|
59
|
+
return # already finished, ignore
|
60
|
+
|
61
|
+
self._finish_reason = exception or StopAsyncIteration()
|
62
|
+
|
63
|
+
if self._waiting is not None and not self._waiting.done():
|
64
|
+
self._waiting.set_exception(self._finish_reason)
|
65
|
+
|
66
|
+
def cancel(self) -> None:
|
67
|
+
self.finish(exception=CancelledError())
|
68
|
+
|
69
|
+
def __aiter__(self) -> Self:
|
70
|
+
return self
|
71
|
+
|
72
|
+
async def __anext__(self) -> Element:
|
73
|
+
assert self._waiting is None, "Only a single queue iterator is supported!" # nosec: B101
|
74
|
+
|
75
|
+
if self._queue: # check the queue, let it finish
|
76
|
+
return self._queue.popleft()
|
77
|
+
|
78
|
+
if self._finish_reason is not None: # check if is finished
|
79
|
+
raise self._finish_reason
|
80
|
+
|
81
|
+
try:
|
82
|
+
# create a new future to wait for next
|
83
|
+
self._waiting = self._loop.create_future()
|
84
|
+
# wait for the result
|
85
|
+
return await self._waiting
|
86
|
+
|
87
|
+
finally:
|
88
|
+
# cleanup
|
89
|
+
self._waiting = None
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Miquido
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: haiway
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Framework for dependency injection and state management within structured concurrency model.
|
5
|
+
Maintainer-email: Kacper KaliΕski <kacper.kalinski@miquido.com>
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2024 Miquido
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
Project-URL: Homepage, https://miquido.com
|
28
|
+
Project-URL: Repository, https://github.com/miquido/haiway.git
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
30
|
+
Classifier: Intended Audience :: Developers
|
31
|
+
Classifier: Programming Language :: Python
|
32
|
+
Classifier: Typing :: Typed
|
33
|
+
Classifier: Topic :: Software Development
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
35
|
+
Requires-Python: >=3.12
|
36
|
+
Description-Content-Type: text/markdown
|
37
|
+
License-File: LICENSE
|
38
|
+
Provides-Extra: dev
|
39
|
+
Requires-Dist: ruff ~=0.5.0 ; extra == 'dev'
|
40
|
+
Requires-Dist: pyright ~=1.1 ; extra == 'dev'
|
41
|
+
Requires-Dist: bandit ~=1.7 ; extra == 'dev'
|
42
|
+
Requires-Dist: pytest ~=7.4 ; extra == 'dev'
|
43
|
+
Requires-Dist: pytest-cov ~=4.1 ; extra == 'dev'
|
44
|
+
Requires-Dist: pytest-asyncio ~=0.23.0 ; extra == 'dev'
|
45
|
+
|
46
|
+
# π haiway π π π
|
47
|
+
|
48
|
+
haiway is a framework helping to build better project codebase by leveraging concepts of structured concurrency and functional programming.
|
49
|
+
|
50
|
+
## π₯οΈ Install
|
51
|
+
|
52
|
+
With pip:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
pip install haiway
|
56
|
+
```
|
57
|
+
|
58
|
+
## π· Contributing
|
59
|
+
|
60
|
+
As an open-source project in a rapidly evolving field, we welcome all contributions. Whether you can add a new feature, enhance our infrastructure, or improve our documentation, your input is valuable to us.
|
61
|
+
|
62
|
+
We welcome any feedback and suggestions! Feel free to open an issue or pull request.
|
63
|
+
|
64
|
+
## βοΈ License
|
65
|
+
|
66
|
+
MIT License
|
67
|
+
|
68
|
+
Copyright (c) 2024 Miquido
|
69
|
+
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
71
|
+
of this software and associated documentation files (the "Software"), to deal
|
72
|
+
in the Software without restriction, including without limitation the rights
|
73
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
74
|
+
copies of the Software, and to permit persons to whom the Software is
|
75
|
+
furnished to do so, subject to the following conditions:
|
76
|
+
|
77
|
+
The above copyright notice and this permission notice shall be included in all
|
78
|
+
copies or substantial portions of the Software.
|
79
|
+
|
80
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
81
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
82
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
83
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
84
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
85
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
86
|
+
SOFTWARE.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
haiway/__init__.py,sha256=20WZqVGbImtVKnZLFw1CU1usQbXjLSEHcu1J07OTEhA,1243
|
2
|
+
haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
haiway/context/__init__.py,sha256=iD_AjgtyJthrkF0Ys2vHxSDLDK54GkcLk-h33HyD4P0,383
|
4
|
+
haiway/context/access.py,sha256=pdc0pZIwQlW24hDcojoE3lUrpC2zvyH-PtoOOGS7D9g,11263
|
5
|
+
haiway/context/dependencies.py,sha256=US1TYM78AHujat9SxLKrP7Ow1dctdLN-OqEx3grBv0Y,1609
|
6
|
+
haiway/context/metrics.py,sha256=OF06T9Er62SJPCZmQF9SnMW8lO9HGxDP3qUkvk6mXUo,8672
|
7
|
+
haiway/context/state.py,sha256=aQgUE3tAWPEYgGv4P16Yk9RkOouY8UpkEpjhzv0AwkA,3014
|
8
|
+
haiway/context/tasks.py,sha256=xXtXIUwXOra0EePTdkcEbMOmpWwFcO3hCRfR_IfvAHk,1978
|
9
|
+
haiway/context/types.py,sha256=OS3d2A0F2CbOpz_hxAhBitSH2_Bs8Aw-kIL6mEBmZdw,214
|
10
|
+
haiway/helpers/__init__.py,sha256=WBGQ3pF6EhCjEQLpMfpW7LwF5u-iR26fr9q6l7xTEJE,335
|
11
|
+
haiway/helpers/asynchronous.py,sha256=FYcV_ERrGy7f47y18oKeUk7fcbk-i_SOuPQ7lHhX5iI,6119
|
12
|
+
haiway/helpers/cache.py,sha256=oONE0xKIfhvPA_wnY8JV_2CtOeSrHAoNpu5n7t-jd8w,9540
|
13
|
+
haiway/helpers/retry.py,sha256=qFeLvOiqAktF-awkh-hTdhyT2zf6kGV0VxAIBrUVdn0,7135
|
14
|
+
haiway/helpers/throttling.py,sha256=zo0OwFq64si5KUwhd58cFHLmGAmYwRbFRJMbv9suhPs,3844
|
15
|
+
haiway/helpers/timeout.py,sha256=iNfDotZ4G9rb_zEuEgzaZP37QqkkXQyEFHClA4Eckl0,3084
|
16
|
+
haiway/state/__init__.py,sha256=sFEo9tWwMK5r6RR_D6d2xRL2Tcb7NgWIEUHx-FCbvbI,212
|
17
|
+
haiway/state/attributes.py,sha256=DIjr8NAhabJJiHHiNc_t7-t9AncobiXg_JRZ3lJ-_G0,13403
|
18
|
+
haiway/state/structure.py,sha256=AQIVz-DUBMFMgBHXbOvLrplmdSCmL3xRjCDwNhFTLV8,7079
|
19
|
+
haiway/state/validation.py,sha256=V4Q94Ik4p9t7f-7EIwK3Q9Zki8VkLOjPIGWGwLRVCoc,2873
|
20
|
+
haiway/types/__init__.py,sha256=cAJQzDgFi8AKRqpzY3HWrutaPR69tnJqeJK_mQVtYUk,252
|
21
|
+
haiway/types/frozen.py,sha256=CZhFCXnWAKEhuWSfILxA8smfdpMd5Ku694ycfLh98R8,76
|
22
|
+
haiway/types/missing.py,sha256=3t2bcZuw5fAKiycP-0Aly2TDUWtM3xyHy3KDCT91TLs,1660
|
23
|
+
haiway/utils/__init__.py,sha256=UA9h8YDvYI5rYujvsIS9t5Q-SWYImmk30uhR_42flqs,608
|
24
|
+
haiway/utils/always.py,sha256=2abp8Lm9rQkrfS3rm1Iqhb-IcWyVfH1BULab3KMxgOw,1234
|
25
|
+
haiway/utils/env.py,sha256=lKPOBZWyRD_gQariDGBjVLYTm0740nytPCSQpK2oRyE,3136
|
26
|
+
haiway/utils/immutable.py,sha256=K34ZIMzbkpgkHKH-KF73plEbXExsajNRkRTYp9nJEf4,620
|
27
|
+
haiway/utils/logs.py,sha256=oDsc1ZdqKDjlTlctLbDcp9iX98Acr-1tdw-Pyg3DElo,1577
|
28
|
+
haiway/utils/mimic.py,sha256=BkVjTVP2TxxC8GChPGyDV6UXVwJmiRiSWeOYZNZFHxs,1828
|
29
|
+
haiway/utils/noop.py,sha256=qgbZlOKWY6_23Zs43OLukK2HagIQKRyR04zrFVm5rWI,344
|
30
|
+
haiway/utils/queue.py,sha256=WGW8kSusIwRYHsYRIKD2CaqhhC1pUtVgtNHFDXDtYrw,2443
|
31
|
+
haiway-0.1.0.dist-info/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
|
32
|
+
haiway-0.1.0.dist-info/METADATA,sha256=ZHdNdTn7cjJQUK6pK8onjkNS0QmOhjpFCWLsQyqQE0o,3872
|
33
|
+
haiway-0.1.0.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
34
|
+
haiway-0.1.0.dist-info/top_level.txt,sha256=_LdXVLzUzgkvAGQnQJj5kQfoFhpPW6EF4Kj9NapniLg,7
|
35
|
+
haiway-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
haiway
|