omlish 0.0.0.dev386__py3-none-any.whl → 0.0.0.dev388__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.
- omlish/__about__.py +2 -2
- omlish/lang/__init__.py +10 -18
- omlish/lang/maysyncs.py +31 -0
- omlish/lite/args.py +5 -0
- omlish/lite/maysyncs.py +262 -0
- omlish/subprocesses/async_.py +5 -1
- omlish/subprocesses/maysync.py +52 -0
- omlish/subprocesses/run.py +18 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/RECORD +14 -13
- omlish/lang/maysync_.py +0 -53
- omlish/lite/maysync.py +0 -74
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev388.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lang/__init__.py
CHANGED
@@ -250,13 +250,11 @@ from .iterables import ( # noqa
|
|
250
250
|
take,
|
251
251
|
)
|
252
252
|
|
253
|
-
from .
|
254
|
-
|
253
|
+
from .maysyncs import ( # noqa
|
254
|
+
MaysyncP,
|
255
255
|
|
256
|
-
|
257
|
-
|
258
|
-
maysync_wrap,
|
259
|
-
a_maysync_wrap,
|
256
|
+
make_maysync,
|
257
|
+
maysync,
|
260
258
|
)
|
261
259
|
|
262
260
|
from .objects import ( # noqa
|
@@ -393,21 +391,15 @@ from ..lite.maybes import ( # noqa
|
|
393
391
|
Maybe,
|
394
392
|
)
|
395
393
|
|
396
|
-
from ..lite.maysync import ( # noqa
|
397
|
-
MaysyncGen,
|
398
|
-
MaysyncFn,
|
399
|
-
|
400
|
-
MaysyncOp,
|
401
|
-
|
402
|
-
maysync,
|
403
|
-
a_maysync,
|
404
|
-
|
405
|
-
MaysyncRunnable,
|
406
|
-
)
|
407
|
-
|
408
394
|
empty = Maybe.empty
|
409
395
|
just = Maybe.just
|
410
396
|
|
397
|
+
from ..lite.maysyncs import ( # noqa
|
398
|
+
Maywaitable,
|
399
|
+
Maysync,
|
400
|
+
Maysync_,
|
401
|
+
)
|
402
|
+
|
411
403
|
from ..lite.reprs import ( # noqa
|
412
404
|
AttrRepr,
|
413
405
|
attr_repr,
|
omlish/lang/maysyncs.py
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from ..lite.maysyncs import Maywaitable
|
4
|
+
from ..lite.maysyncs import make_maysync as _make_maysync
|
5
|
+
from ..lite.maysyncs import maysync as _maysync
|
6
|
+
from .functions import as_async
|
7
|
+
|
8
|
+
|
9
|
+
T = ta.TypeVar('T')
|
10
|
+
P = ta.ParamSpec('P')
|
11
|
+
|
12
|
+
MaysyncP: ta.TypeAlias = ta.Callable[P, Maywaitable[T]]
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
|
17
|
+
|
18
|
+
def make_maysync(
|
19
|
+
s: ta.Callable[P, T],
|
20
|
+
a: ta.Callable[P, ta.Awaitable[T]] | None = None,
|
21
|
+
) -> MaysyncP[P, T]:
|
22
|
+
return ta.cast('MaysyncP[P, T]', _make_maysync(
|
23
|
+
s,
|
24
|
+
a if a is not None else as_async(s),
|
25
|
+
))
|
26
|
+
|
27
|
+
|
28
|
+
def maysync(m: ta.Callable[P, ta.Awaitable[T]]) -> MaysyncP[P, T]:
|
29
|
+
return ta.cast('MaysyncP[P, T]', _maysync(
|
30
|
+
m,
|
31
|
+
))
|
omlish/lite/args.py
CHANGED
omlish/lite/maysyncs.py
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
# ruff: noqa: UP045
|
2
|
+
# @omlish-lite
|
3
|
+
"""
|
4
|
+
TODO:
|
5
|
+
- __del__
|
6
|
+
"""
|
7
|
+
import abc
|
8
|
+
import functools
|
9
|
+
import typing as ta
|
10
|
+
|
11
|
+
|
12
|
+
T = ta.TypeVar('T')
|
13
|
+
T_co = ta.TypeVar('T_co', covariant=True)
|
14
|
+
_X = ta.TypeVar('_X')
|
15
|
+
|
16
|
+
_MaysyncGen = ta.Generator['_MaysyncOp', ta.Any, T] # ta.TypeAlias
|
17
|
+
|
18
|
+
|
19
|
+
##
|
20
|
+
|
21
|
+
|
22
|
+
class Maywaitable(ta.Protocol[T_co]):
|
23
|
+
def s(self) -> T_co:
|
24
|
+
...
|
25
|
+
|
26
|
+
def a(self) -> ta.Awaitable[T_co]:
|
27
|
+
...
|
28
|
+
|
29
|
+
def m(self) -> ta.Awaitable[T_co]:
|
30
|
+
...
|
31
|
+
|
32
|
+
|
33
|
+
Maysync = ta.Callable[..., Maywaitable[T]] # ta.TypeAlias # omlish-amalg-typing-no-move
|
34
|
+
|
35
|
+
|
36
|
+
class Maysync_(abc.ABC): # noqa
|
37
|
+
pass
|
38
|
+
|
39
|
+
|
40
|
+
##
|
41
|
+
|
42
|
+
|
43
|
+
class _Maywaitable(abc.ABC, ta.Generic[_X, T]):
|
44
|
+
@ta.final
|
45
|
+
def __init__(
|
46
|
+
self,
|
47
|
+
x: _X,
|
48
|
+
*args: ta.Any,
|
49
|
+
**kwargs: ta.Any,
|
50
|
+
) -> None:
|
51
|
+
self.x = x
|
52
|
+
self.args = args
|
53
|
+
self.kwargs = kwargs
|
54
|
+
|
55
|
+
@ta.final
|
56
|
+
def m(self) -> ta.Awaitable[T]:
|
57
|
+
return _MaysyncFuture(_MaysyncOp(
|
58
|
+
ta.cast(ta.Any, self.x),
|
59
|
+
*self.args,
|
60
|
+
**self.kwargs,
|
61
|
+
))
|
62
|
+
|
63
|
+
|
64
|
+
##
|
65
|
+
|
66
|
+
|
67
|
+
@ta.final
|
68
|
+
class _FnMaysync(Maysync_, ta.Generic[T]):
|
69
|
+
def __init__(
|
70
|
+
self,
|
71
|
+
s: ta.Callable[..., T],
|
72
|
+
a: ta.Callable[..., ta.Awaitable[T]],
|
73
|
+
) -> None:
|
74
|
+
if s is None:
|
75
|
+
raise TypeError(s)
|
76
|
+
if a is None:
|
77
|
+
raise TypeError(a)
|
78
|
+
self.s = s
|
79
|
+
self.a = a
|
80
|
+
|
81
|
+
def __get__(self, instance, owner=None):
|
82
|
+
return _FnMaysync(
|
83
|
+
self.s.__get__(instance, owner), # noqa
|
84
|
+
self.a.__get__(instance, owner), # noqa
|
85
|
+
)
|
86
|
+
|
87
|
+
def __call__(self, *args, **kwargs):
|
88
|
+
return _FnMaywaitable(self, *args, **kwargs)
|
89
|
+
|
90
|
+
|
91
|
+
@ta.final
|
92
|
+
class _FnMaywaitable(_Maywaitable[_FnMaysync[T], T]):
|
93
|
+
def s(self) -> T:
|
94
|
+
return self.x.s(*self.args, **self.kwargs)
|
95
|
+
|
96
|
+
async def a(self) -> T:
|
97
|
+
return await self.x.a(*self.args, **self.kwargs)
|
98
|
+
|
99
|
+
|
100
|
+
def make_maysync(
|
101
|
+
s: ta.Callable[..., T],
|
102
|
+
a: ta.Callable[..., ta.Awaitable[T]],
|
103
|
+
) -> Maysync[T]:
|
104
|
+
return _FnMaysync(s, a)
|
105
|
+
|
106
|
+
|
107
|
+
##
|
108
|
+
|
109
|
+
|
110
|
+
@ta.final
|
111
|
+
class _MgMaysync(Maysync_, ta.Generic[T]):
|
112
|
+
def __init__(
|
113
|
+
self,
|
114
|
+
mg: ta.Callable[..., _MaysyncGen[T]],
|
115
|
+
) -> None:
|
116
|
+
self.mg = mg
|
117
|
+
|
118
|
+
def __get__(self, instance, owner=None):
|
119
|
+
return _MgMaysync(
|
120
|
+
self.mg.__get__(instance, owner), # noqa
|
121
|
+
)
|
122
|
+
|
123
|
+
def __call__(self, *args, **kwargs):
|
124
|
+
return _MgMaywaitable(self, *args, **kwargs)
|
125
|
+
|
126
|
+
|
127
|
+
@ta.final
|
128
|
+
class _MgMaywaitable(_Maywaitable[_MgMaysync[T], T]):
|
129
|
+
def s(self) -> T:
|
130
|
+
g = self.x.mg(*self.args, **self.kwargs)
|
131
|
+
|
132
|
+
i: ta.Any = None
|
133
|
+
e: ta.Any = None
|
134
|
+
|
135
|
+
while True:
|
136
|
+
try:
|
137
|
+
if e is not None:
|
138
|
+
o = g.throw(e)
|
139
|
+
else:
|
140
|
+
o = g.send(i)
|
141
|
+
except StopIteration as ex:
|
142
|
+
return ex.value
|
143
|
+
|
144
|
+
i = None
|
145
|
+
e = None
|
146
|
+
|
147
|
+
if not isinstance(o, _MaysyncOp):
|
148
|
+
raise TypeError(o)
|
149
|
+
try:
|
150
|
+
i = o.x(*o.args, **o.kwargs).s()
|
151
|
+
except BaseException as ex: # noqa
|
152
|
+
e = ex
|
153
|
+
|
154
|
+
del o
|
155
|
+
|
156
|
+
async def a(self) -> T:
|
157
|
+
g = self.x.mg(*self.args, **self.kwargs)
|
158
|
+
|
159
|
+
i: ta.Any = None
|
160
|
+
e: ta.Any = None
|
161
|
+
|
162
|
+
while True:
|
163
|
+
try:
|
164
|
+
if e is not None:
|
165
|
+
o = g.throw(e)
|
166
|
+
else:
|
167
|
+
o = g.send(i)
|
168
|
+
except StopIteration as ex:
|
169
|
+
return ex.value
|
170
|
+
|
171
|
+
i = None
|
172
|
+
e = None
|
173
|
+
|
174
|
+
if not isinstance(o, _MaysyncOp):
|
175
|
+
raise TypeError(o)
|
176
|
+
try:
|
177
|
+
i = await o.x(*o.args, **o.kwargs).a()
|
178
|
+
except BaseException as ex: # noqa
|
179
|
+
e = ex
|
180
|
+
|
181
|
+
del o
|
182
|
+
|
183
|
+
|
184
|
+
@ta.final
|
185
|
+
class _MgMaysyncFn:
|
186
|
+
def __init__(self, m):
|
187
|
+
self.m = m
|
188
|
+
|
189
|
+
functools.update_wrapper(self, m)
|
190
|
+
|
191
|
+
def __get__(self, instance, owner=None):
|
192
|
+
return _MgMaysyncFn(
|
193
|
+
self.m.__get__(instance, owner),
|
194
|
+
)
|
195
|
+
|
196
|
+
def __call__(self, *args, **kwargs):
|
197
|
+
a = self.m(*args, **kwargs).__await__()
|
198
|
+
try:
|
199
|
+
g = iter(a)
|
200
|
+
try:
|
201
|
+
while True:
|
202
|
+
try:
|
203
|
+
o = g.send(None)
|
204
|
+
except StopIteration as e:
|
205
|
+
return e.value
|
206
|
+
|
207
|
+
if not isinstance(o, _MaysyncFuture):
|
208
|
+
raise TypeError(o)
|
209
|
+
if not o.done:
|
210
|
+
try:
|
211
|
+
o.result = yield o.op
|
212
|
+
except BaseException as e: # noqa
|
213
|
+
o.error = e
|
214
|
+
o.done = True
|
215
|
+
|
216
|
+
finally:
|
217
|
+
g.close()
|
218
|
+
|
219
|
+
finally:
|
220
|
+
a.close()
|
221
|
+
|
222
|
+
|
223
|
+
def maysync(m: ta.Callable[..., ta.Awaitable[T]]) -> Maysync[T]:
|
224
|
+
return _MgMaysync(_MgMaysyncFn(m))
|
225
|
+
|
226
|
+
|
227
|
+
##
|
228
|
+
|
229
|
+
|
230
|
+
@ta.final
|
231
|
+
class _MaysyncOp:
|
232
|
+
def __init__(
|
233
|
+
self,
|
234
|
+
x: Maysync[T],
|
235
|
+
*args: ta.Any,
|
236
|
+
**kwargs: ta.Any,
|
237
|
+
) -> None:
|
238
|
+
self.x = x
|
239
|
+
self.args = args
|
240
|
+
self.kwargs = kwargs
|
241
|
+
|
242
|
+
|
243
|
+
@ta.final
|
244
|
+
class _MaysyncFuture(ta.Generic[T]):
|
245
|
+
def __init__(
|
246
|
+
self,
|
247
|
+
op: _MaysyncOp,
|
248
|
+
) -> None:
|
249
|
+
self.op = op
|
250
|
+
|
251
|
+
done: bool = False
|
252
|
+
result: ta.Optional[T] = None
|
253
|
+
error: ta.Optional[BaseException] = None
|
254
|
+
|
255
|
+
def __await__(self):
|
256
|
+
if not self.done:
|
257
|
+
yield self
|
258
|
+
if not self.done:
|
259
|
+
raise RuntimeError("await wasn't used with event future")
|
260
|
+
if self.error is not None:
|
261
|
+
raise self.error
|
262
|
+
return self.result
|
omlish/subprocesses/async_.py
CHANGED
@@ -13,7 +13,7 @@ from .run import SubprocessRunOutput
|
|
13
13
|
##
|
14
14
|
|
15
15
|
|
16
|
-
class
|
16
|
+
class _AbstractAsyncSubprocesses(BaseSubprocesses):
|
17
17
|
@abc.abstractmethod
|
18
18
|
async def run_(self, run: SubprocessRun) -> SubprocessRunOutput:
|
19
19
|
raise NotImplementedError
|
@@ -95,3 +95,7 @@ class AbstractAsyncSubprocesses(BaseSubprocesses):
|
|
95
95
|
return None
|
96
96
|
else:
|
97
97
|
return ret.decode().strip()
|
98
|
+
|
99
|
+
|
100
|
+
class AbstractAsyncSubprocesses(_AbstractAsyncSubprocesses, abc.ABC):
|
101
|
+
pass
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# ruff: noqa: UP006 UP007 UP045
|
2
|
+
# @omlish-lite
|
3
|
+
import abc
|
4
|
+
import sys
|
5
|
+
import typing as ta
|
6
|
+
|
7
|
+
from ..lite.maysyncs import make_maysync
|
8
|
+
from .async_ import AbstractAsyncSubprocesses
|
9
|
+
from .async_ import _AbstractAsyncSubprocesses
|
10
|
+
from .run import SubprocessRun
|
11
|
+
from .run import SubprocessRunOutput
|
12
|
+
from .sync import AbstractSubprocesses
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
|
17
|
+
|
18
|
+
class AbstractMaysyncSubprocesses(_AbstractAsyncSubprocesses, abc.ABC):
|
19
|
+
pass
|
20
|
+
|
21
|
+
|
22
|
+
##
|
23
|
+
|
24
|
+
|
25
|
+
class MaysyncSubprocesses(AbstractMaysyncSubprocesses):
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
subprocesses: AbstractSubprocesses,
|
29
|
+
async_subprocesses: AbstractAsyncSubprocesses,
|
30
|
+
) -> None:
|
31
|
+
super().__init__()
|
32
|
+
|
33
|
+
self._subprocesses = subprocesses
|
34
|
+
self._async_subprocesses = async_subprocesses
|
35
|
+
|
36
|
+
async def run_(self, run: SubprocessRun) -> SubprocessRunOutput:
|
37
|
+
return await make_maysync(
|
38
|
+
self._subprocesses.run,
|
39
|
+
self._async_subprocesses.run,
|
40
|
+
)(run).m()
|
41
|
+
|
42
|
+
async def check_call(self, *cmd: str, stdout: ta.Any = sys.stderr, **kwargs: ta.Any) -> None:
|
43
|
+
return await make_maysync(
|
44
|
+
self._subprocesses.check_call,
|
45
|
+
self._async_subprocesses.check_call,
|
46
|
+
)(*cmd, **kwargs).m()
|
47
|
+
|
48
|
+
async def check_output(self, *cmd: str, **kwargs: ta.Any) -> bytes:
|
49
|
+
return await make_maysync(
|
50
|
+
self._subprocesses.check_output,
|
51
|
+
self._async_subprocesses.check_output,
|
52
|
+
)(*cmd, **kwargs).m()
|
omlish/subprocesses/run.py
CHANGED
@@ -105,6 +105,17 @@ class SubprocessRun:
|
|
105
105
|
async_subprocesses = self._DEFAULT_ASYNC_SUBPROCESSES
|
106
106
|
return await check.not_none(async_subprocesses).run_(self.replace(**kwargs))
|
107
107
|
|
108
|
+
_DEFAULT_MAYSYNC_SUBPROCESSES: ta.ClassVar[ta.Optional[ta.Any]] = None # AbstractMaysyncSubprocesses
|
109
|
+
|
110
|
+
async def maysync_run(
|
111
|
+
self,
|
112
|
+
maysync_subprocesses: ta.Optional[ta.Any] = None, # AbstractMaysyncSubprocesses
|
113
|
+
**kwargs: ta.Any,
|
114
|
+
) -> SubprocessRunOutput:
|
115
|
+
if maysync_subprocesses is None:
|
116
|
+
maysync_subprocesses = self._DEFAULT_MAYSYNC_SUBPROCESSES
|
117
|
+
return await check.not_none(maysync_subprocesses).run_(self.replace(**kwargs))
|
118
|
+
|
108
119
|
|
109
120
|
SubprocessRun._FIELD_NAMES = frozenset(fld.name for fld in dc.fields(SubprocessRun)) # noqa
|
110
121
|
|
@@ -136,3 +147,10 @@ class SubprocessRunnable(abc.ABC, ta.Generic[T]):
|
|
136
147
|
**kwargs: ta.Any,
|
137
148
|
) -> T:
|
138
149
|
return self.handle_run_output(await self.make_run().async_run(async_subprocesses, **kwargs))
|
150
|
+
|
151
|
+
async def maysync_run(
|
152
|
+
self,
|
153
|
+
maysync_subprocesses: ta.Optional[ta.Any] = None, # AbstractMaysyncSubprocesses
|
154
|
+
**kwargs: ta.Any,
|
155
|
+
) -> T:
|
156
|
+
return self.handle_run_output(await self.make_run().maysync_run(maysync_subprocesses, **kwargs))
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=Yte_7PVV4dR_gMOEh3rykgNGh8hm1tSqvBzJHfYNgcE,3543
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=rer-TPOFDU6fYq_AWio_AmA-ckZ8JDY5shIzQ_yXfzA,8414
|
5
5
|
omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
|
@@ -420,7 +420,7 @@ omlish/iterators/iterators.py,sha256=RxW35yQ5ed8vBQ22IqpDXFx-i5JiLQdp7-pkMZXhJJ8
|
|
420
420
|
omlish/iterators/recipes.py,sha256=wOwOZg-zWG9Zc3wcAxJFSe2rtavVBYwZOfG09qYEx_4,472
|
421
421
|
omlish/iterators/tools.py,sha256=M16LXrJhMdsz5ea2qH0vws30ZvhQuQSCVFSLpRf_gTg,2096
|
422
422
|
omlish/iterators/unique.py,sha256=Nw0pSaNEcHAkve0ugfLPvJcirDOn9ECyC5wIL8JlJKI,1395
|
423
|
-
omlish/lang/__init__.py,sha256=
|
423
|
+
omlish/lang/__init__.py,sha256=ZkDWvp1jUTbw2-sDzUij4hYH4RtjnTBLHMPjrw-4ORk,6785
|
424
424
|
omlish/lang/attrs.py,sha256=zFiVuGVOq88x45464T_LxDa-ZEq_RD9zJLq2zeVEBDc,5105
|
425
425
|
omlish/lang/casing.py,sha256=cFUlbDdXLhwnWwcYx4qnM5c4zGX7hIRUfcjiZbxUD28,4636
|
426
426
|
omlish/lang/clsdct.py,sha256=HAGIvBSbCefzRjXriwYSBLO7QHKRv2UsE78jixOb-fA,1828
|
@@ -435,7 +435,7 @@ omlish/lang/functions.py,sha256=aLdxhmqG0Pj9tBgsKdoCu_q15r82WIkNqDDSPQU19L8,5689
|
|
435
435
|
omlish/lang/generators.py,sha256=a4D5HU_mySs2T2z3xCmE_s3t4QJkj0YRrK4-hhpGd0A,5197
|
436
436
|
omlish/lang/imports.py,sha256=y9W9Y-d_cQ35QCLuSIPoa6vnEqSErFCz8b-34IH128U,10552
|
437
437
|
omlish/lang/iterables.py,sha256=y1SX2Co3VsOeX2wlfFF7K3rwLvF7Dtre7VY6EpfwAwA,3338
|
438
|
-
omlish/lang/
|
438
|
+
omlish/lang/maysyncs.py,sha256=rUeOFpoqVSbQ_YcPvky4IDBDnpm67K26ADYCNfjMSQY,683
|
439
439
|
omlish/lang/objects.py,sha256=ZsibJwNp1EXorbaObm9TlCNtuuM65snCmVb7H4_llqI,6116
|
440
440
|
omlish/lang/outcomes.py,sha256=0PqxoKaGbBXU9UYZ6AE2QSq94Z-gFDt6wYdp0KomNQw,8712
|
441
441
|
omlish/lang/overrides.py,sha256=IBzK6ljfLX6TLgIyKTSjhqTLcuKRkQNVtEOnBLS4nuA,2095
|
@@ -466,7 +466,7 @@ omlish/lifecycles/manager.py,sha256=92s1IH_gDP25PM5tFuPMP2hD_6s5fPi_VzZiDS5549g,
|
|
466
466
|
omlish/lifecycles/states.py,sha256=6gTdY3hn7-1sJ60lA3GeMx5RVKvXtFBBXE4KEjoO1Hs,1297
|
467
467
|
omlish/lifecycles/transitions.py,sha256=3IFdWGtAeoy3XRlIyW7yCKV4e4Iof9ytkqklGMRFYQs,1944
|
468
468
|
omlish/lite/__init__.py,sha256=cyZEpGob7XjU8DohyNxVe5CQRk4CQ5vrHL42OdhQb8w,148
|
469
|
-
omlish/lite/args.py,sha256=
|
469
|
+
omlish/lite/args.py,sha256=ILJXAiN3KjIoJwY42aKpYPngUdxHIy9ssVIExFVz3fE,978
|
470
470
|
omlish/lite/cached.py,sha256=O7ozcoDNFm1Hg2wtpHEqYSp_i_nCLNOP6Ueq_Uk-7mU,1300
|
471
471
|
omlish/lite/check.py,sha256=ytCkwZoKfOlJqylL-AGm8C2WfsWJd2q3kFbnZCzX3_M,13844
|
472
472
|
omlish/lite/configs.py,sha256=4-1uVxo-aNV7vMKa7PVNhM610eejG1WepB42-Dw2xQI,914
|
@@ -478,7 +478,7 @@ omlish/lite/json.py,sha256=m0Ce9eqUZG23-H7-oOp8n1sf4fzno5vtK4AK_4Vc-Mg,706
|
|
478
478
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
479
479
|
omlish/lite/marshal.py,sha256=JD_8ox5-yeIo7MZ6iipCdiVxx33So52M02AtvFlRGC8,20392
|
480
480
|
omlish/lite/maybes.py,sha256=0p_fzb6yiOjEpvMKaQ53Q6CH1VPW1or7v7Lt1JIKcgM,4359
|
481
|
-
omlish/lite/
|
481
|
+
omlish/lite/maysyncs.py,sha256=Za0kvANYaK9q-IUs_rSjo1ZQIOTZzkVB7IIEGw5eOsQ,5687
|
482
482
|
omlish/lite/pycharm.py,sha256=FRHGcCDo42UzZXqNwW_DkhI-6kb_CmJKPiQ8F6mYkLA,1174
|
483
483
|
omlish/lite/reflect.py,sha256=pzOY2PPuHH0omdtglkN6DheXDrGopdL3PtTJnejyLFU,2189
|
484
484
|
omlish/lite/reprs.py,sha256=Tiqf_ciD8FfS0ury7FcJ5G21yY342fW0vPacYlb8EO4,2014
|
@@ -748,10 +748,11 @@ omlish/sql/tabledefs/lower.py,sha256=i4_QkVlVH5U99O6pqokrB661AudNVJ9Q-OwtkKOBleU
|
|
748
748
|
omlish/sql/tabledefs/marshal.py,sha256=5Z7K433SzfN7-z8Yd7FJRzOV9tJv-ErRMA6inZ2iBCE,475
|
749
749
|
omlish/sql/tabledefs/tabledefs.py,sha256=lIhvlt0pk6G7RZAtDFsFXm5j0l9BvRfnP7vNGeydHtE,816
|
750
750
|
omlish/subprocesses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
751
|
-
omlish/subprocesses/async_.py,sha256=
|
751
|
+
omlish/subprocesses/async_.py,sha256=Zs9TxCyROVTOhbZmZMHi_-zwydptVi7MN4esUiK4-YI,2448
|
752
752
|
omlish/subprocesses/base.py,sha256=r60N3ad4ooSvdgFmT94L_xZEy7FMbMX6JcG2VgpHo6w,6139
|
753
753
|
omlish/subprocesses/editor.py,sha256=xBrd7gY0akhRfDIBK5YIBrYMHECtl_8r499iKViyfpQ,2634
|
754
|
-
omlish/subprocesses/
|
754
|
+
omlish/subprocesses/maysync.py,sha256=dK2wDv2so4wa0rOWBkafUqBy1QEJmLg_9CxMsr_kR4I,1456
|
755
|
+
omlish/subprocesses/run.py,sha256=8EeMm2FdNEFmEmbhhzJyHXASUhCCMMRN_-8ybqFhgLI,4378
|
755
756
|
omlish/subprocesses/sync.py,sha256=YdGxa9_GhqqsvTucmnmUXWYcKKys0S5PQk271K1Jg68,3664
|
756
757
|
omlish/subprocesses/utils.py,sha256=v5uEzxmbmRvXwOl_0DtBa5Il6yITKYRgmVSGHcLsT4o,402
|
757
758
|
omlish/subprocesses/wrap.py,sha256=AhGV8rsnaVUMQCFYKkrjj35fs3O-VJLZC1hZ14dz3C8,769
|
@@ -894,9 +895,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
894
895
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
895
896
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
896
897
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
897
|
-
omlish-0.0.0.
|
898
|
-
omlish-0.0.0.
|
899
|
-
omlish-0.0.0.
|
900
|
-
omlish-0.0.0.
|
901
|
-
omlish-0.0.0.
|
902
|
-
omlish-0.0.0.
|
898
|
+
omlish-0.0.0.dev388.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
899
|
+
omlish-0.0.0.dev388.dist-info/METADATA,sha256=YvbEgGvf4ZNKIIJWrToJVEysF8nsyVuzRgd1VeAcc8k,18825
|
900
|
+
omlish-0.0.0.dev388.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
901
|
+
omlish-0.0.0.dev388.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
902
|
+
omlish-0.0.0.dev388.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
903
|
+
omlish-0.0.0.dev388.dist-info/RECORD,,
|
omlish/lang/maysync_.py
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
import functools
|
2
|
-
import typing as ta
|
3
|
-
|
4
|
-
from ..lite.maysync import MaysyncGen
|
5
|
-
from ..lite.maysync import MaysyncOp
|
6
|
-
from ..lite.maysync import a_maysync
|
7
|
-
from ..lite.maysync import maysync
|
8
|
-
|
9
|
-
|
10
|
-
T = ta.TypeVar('T')
|
11
|
-
P = ta.ParamSpec('P')
|
12
|
-
|
13
|
-
|
14
|
-
##
|
15
|
-
|
16
|
-
|
17
|
-
def maysync_op(
|
18
|
-
fn: ta.Callable[P, T],
|
19
|
-
a_fn: ta.Callable[P, ta.Awaitable[T]],
|
20
|
-
) -> MaysyncOp[T]:
|
21
|
-
return MaysyncOp(
|
22
|
-
fn,
|
23
|
-
a_fn,
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
|
-
##
|
28
|
-
|
29
|
-
|
30
|
-
def maysync_yield(
|
31
|
-
fn: ta.Callable[P, T],
|
32
|
-
a_fn: ta.Callable[P, ta.Awaitable[T]],
|
33
|
-
) -> ta.Callable[P, ta.Generator[ta.Any, ta.Any, T]]:
|
34
|
-
def inner(*args, **kwargs):
|
35
|
-
return (yield MaysyncOp(fn, a_fn)(*args, **kwargs))
|
36
|
-
return inner
|
37
|
-
|
38
|
-
|
39
|
-
##
|
40
|
-
|
41
|
-
|
42
|
-
def maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, T]:
|
43
|
-
@functools.wraps(fn)
|
44
|
-
def inner(*args, **kwargs):
|
45
|
-
return maysync(fn, *args, **kwargs)
|
46
|
-
return inner
|
47
|
-
|
48
|
-
|
49
|
-
def a_maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, ta.Awaitable[T]]:
|
50
|
-
@functools.wraps(fn)
|
51
|
-
async def inner(*args, **kwargs):
|
52
|
-
return await a_maysync(fn, *args, **kwargs)
|
53
|
-
return inner
|
omlish/lite/maysync.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# ruff: noqa: UP045
|
2
|
-
import abc
|
3
|
-
import dataclasses as dc
|
4
|
-
import typing as ta
|
5
|
-
|
6
|
-
from .args import Args
|
7
|
-
|
8
|
-
|
9
|
-
T = ta.TypeVar('T')
|
10
|
-
|
11
|
-
|
12
|
-
MaysyncGen = ta.Generator['MaysyncOp', ta.Any, T] # ta.TypeAlias
|
13
|
-
MaysyncFn = ta.Callable[..., MaysyncGen[T]] # ta.TypeAlias
|
14
|
-
|
15
|
-
|
16
|
-
##
|
17
|
-
|
18
|
-
|
19
|
-
@dc.dataclass(frozen=True)
|
20
|
-
class MaysyncOp(ta.Generic[T]):
|
21
|
-
fn: ta.Callable[..., T]
|
22
|
-
a_fn: ta.Callable[..., ta.Awaitable[T]]
|
23
|
-
|
24
|
-
args: ta.Optional[Args] = None
|
25
|
-
|
26
|
-
def __call__(self, *args: ta.Any, **kwargs: ta.Any) -> 'MaysyncOp[T]':
|
27
|
-
if self.args is not None:
|
28
|
-
raise RuntimeError('Args already bound')
|
29
|
-
return dc.replace(self, args=Args(*args, **kwargs))
|
30
|
-
|
31
|
-
|
32
|
-
maysync_op = MaysyncOp
|
33
|
-
|
34
|
-
|
35
|
-
##
|
36
|
-
|
37
|
-
|
38
|
-
def maysync(fn: MaysyncFn[T], *args: ta.Any, **kwargs: ta.Any) -> T:
|
39
|
-
g = fn(*args, **kwargs)
|
40
|
-
i = None
|
41
|
-
while True:
|
42
|
-
try:
|
43
|
-
o = g.send(i)
|
44
|
-
except StopIteration as e:
|
45
|
-
return e.value
|
46
|
-
i = Args.call(o.fn, o.args)
|
47
|
-
|
48
|
-
|
49
|
-
async def a_maysync(fn: MaysyncFn[T], *args: ta.Any, **kwargs: ta.Any) -> T:
|
50
|
-
g = fn(*args, **kwargs)
|
51
|
-
i = None
|
52
|
-
while True:
|
53
|
-
try:
|
54
|
-
o = g.send(i)
|
55
|
-
except StopIteration as e:
|
56
|
-
return e.value
|
57
|
-
i = await Args.call(o.a_fn, o.args)
|
58
|
-
|
59
|
-
|
60
|
-
##
|
61
|
-
|
62
|
-
|
63
|
-
class MaysyncRunnable(abc.ABC, ta.Generic[T]):
|
64
|
-
@abc.abstractmethod
|
65
|
-
def m_run(self) -> MaysyncGen[T]:
|
66
|
-
raise NotImplementedError
|
67
|
-
|
68
|
-
@ta.final
|
69
|
-
def run(self) -> T:
|
70
|
-
return maysync(self.m_run)
|
71
|
-
|
72
|
-
@ta.final
|
73
|
-
async def a_run(self) -> T:
|
74
|
-
return await a_maysync(self.m_run)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|