omlish 0.0.0.dev387__py3-none-any.whl → 0.0.0.dev389__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/asyncs/anyio/subprocesses.py +1 -10
- omlish/asyncs/asyncio/subprocesses.py +1 -21
- omlish/lang/__init__.py +4 -3
- omlish/lang/maysyncs.py +12 -22
- omlish/lite/maysyncs.py +152 -64
- omlish/subprocesses/{async_.py → asyncs.py} +20 -8
- omlish/subprocesses/maysyncs.py +152 -0
- omlish/subprocesses/run.py +18 -0
- omlish/subprocesses/sync.py +2 -0
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/RECORD +16 -15
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev387.dist-info → omlish-0.0.0.dev389.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
import io
|
2
2
|
import subprocess
|
3
|
-
import sys
|
4
3
|
import typing as ta
|
5
4
|
|
6
5
|
import anyio.abc
|
7
6
|
|
8
7
|
from ... import check
|
9
8
|
from ...lite.timeouts import Timeout
|
10
|
-
from ...subprocesses.
|
9
|
+
from ...subprocesses.asyncs import AbstractAsyncSubprocesses
|
11
10
|
from ...subprocesses.run import SubprocessRun
|
12
11
|
from ...subprocesses.run import SubprocessRunOutput
|
13
12
|
|
@@ -73,13 +72,5 @@ class AnyioSubprocesses(AbstractAsyncSubprocesses):
|
|
73
72
|
stderr=stderr.getvalue() if stderr is not None else None,
|
74
73
|
)
|
75
74
|
|
76
|
-
async def check_call(self, *cmd: str, stdout: ta.Any = sys.stderr, **kwargs: ta.Any) -> None:
|
77
|
-
with self.prepare_and_wrap(*cmd, stdout=stdout, check=True, **kwargs) as (cmd, kwargs): # noqa
|
78
|
-
await self.run(*cmd, **kwargs)
|
79
|
-
|
80
|
-
async def check_output(self, *cmd: str, **kwargs: ta.Any) -> bytes:
|
81
|
-
with self.prepare_and_wrap(*cmd, stdout=subprocess.PIPE, check=True, **kwargs) as (cmd, kwargs): # noqa
|
82
|
-
return check.not_none((await self.run(*cmd, **kwargs)).stdout)
|
83
|
-
|
84
75
|
|
85
76
|
anyio_subprocesses = AnyioSubprocesses()
|
@@ -6,12 +6,11 @@ import contextlib
|
|
6
6
|
import functools
|
7
7
|
import logging
|
8
8
|
import subprocess
|
9
|
-
import sys
|
10
9
|
import typing as ta
|
11
10
|
|
12
11
|
from ...lite.check import check
|
13
12
|
from ...lite.timeouts import TimeoutLike
|
14
|
-
from ...subprocesses.
|
13
|
+
from ...subprocesses.asyncs import AbstractAsyncSubprocesses
|
15
14
|
from ...subprocesses.run import SubprocessRun
|
16
15
|
from ...subprocesses.run import SubprocessRunOutput
|
17
16
|
from .timeouts import asyncio_maybe_timeout
|
@@ -208,24 +207,5 @@ class AsyncioSubprocesses(AbstractAsyncSubprocesses):
|
|
208
207
|
stderr=stderr,
|
209
208
|
)
|
210
209
|
|
211
|
-
#
|
212
|
-
|
213
|
-
async def check_call(
|
214
|
-
self,
|
215
|
-
*cmd: str,
|
216
|
-
stdout: ta.Any = sys.stderr,
|
217
|
-
**kwargs: ta.Any,
|
218
|
-
) -> None:
|
219
|
-
with self.prepare_and_wrap(*cmd, stdout=stdout, check=True, **kwargs) as (cmd, kwargs): # noqa
|
220
|
-
await self.run(*cmd, **kwargs)
|
221
|
-
|
222
|
-
async def check_output(
|
223
|
-
self,
|
224
|
-
*cmd: str,
|
225
|
-
**kwargs: ta.Any,
|
226
|
-
) -> bytes:
|
227
|
-
with self.prepare_and_wrap(*cmd, stdout=subprocess.PIPE, check=True, **kwargs) as (cmd, kwargs): # noqa
|
228
|
-
return check.not_none((await self.run(*cmd, **kwargs)).stdout)
|
229
|
-
|
230
210
|
|
231
211
|
asyncio_subprocesses = AsyncioSubprocesses()
|
omlish/lang/__init__.py
CHANGED
@@ -251,10 +251,9 @@ from .iterables import ( # noqa
|
|
251
251
|
)
|
252
252
|
|
253
253
|
from .maysyncs import ( # noqa
|
254
|
-
|
254
|
+
MaysyncP,
|
255
255
|
|
256
256
|
make_maysync,
|
257
|
-
|
258
257
|
maysync,
|
259
258
|
)
|
260
259
|
|
@@ -396,7 +395,9 @@ empty = Maybe.empty
|
|
396
395
|
just = Maybe.just
|
397
396
|
|
398
397
|
from ..lite.maysyncs import ( # noqa
|
399
|
-
|
398
|
+
Maywaitable,
|
399
|
+
Maysync,
|
400
|
+
Maysync_,
|
400
401
|
)
|
401
402
|
|
402
403
|
from ..lite.reprs import ( # noqa
|
omlish/lang/maysyncs.py
CHANGED
@@ -1,41 +1,31 @@
|
|
1
1
|
import typing as ta
|
2
2
|
|
3
|
+
from ..lite.maysyncs import Maywaitable
|
3
4
|
from ..lite.maysyncs import make_maysync as _make_maysync
|
4
5
|
from ..lite.maysyncs import maysync as _maysync
|
6
|
+
from .functions import as_async
|
5
7
|
|
6
8
|
|
7
|
-
|
9
|
+
T = ta.TypeVar('T')
|
8
10
|
P = ta.ParamSpec('P')
|
9
11
|
|
12
|
+
MaysyncP: ta.TypeAlias = ta.Callable[P, Maywaitable[T]]
|
10
13
|
|
11
|
-
##
|
12
|
-
|
13
|
-
|
14
|
-
class MaysyncableP(ta.Protocol[P, T_co]):
|
15
|
-
@property
|
16
|
-
def s(self) -> ta.Callable[P, T_co]:
|
17
|
-
...
|
18
14
|
|
19
|
-
|
20
|
-
def a(self) -> ta.Callable[P, ta.Awaitable[T_co]]:
|
21
|
-
...
|
22
|
-
|
23
|
-
@property
|
24
|
-
def m(self) -> ta.Callable[P, ta.Awaitable[T_co]]:
|
25
|
-
...
|
15
|
+
##
|
26
16
|
|
27
17
|
|
28
18
|
def make_maysync(
|
29
|
-
s: ta.Callable[P,
|
30
|
-
a: ta.Callable[P, ta.Awaitable[
|
31
|
-
) ->
|
32
|
-
return ta.cast('
|
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(
|
33
23
|
s,
|
34
|
-
a,
|
24
|
+
a if a is not None else as_async(s),
|
35
25
|
))
|
36
26
|
|
37
27
|
|
38
|
-
def maysync(m: ta.Callable[P, ta.Awaitable[
|
39
|
-
return ta.cast('
|
28
|
+
def maysync(m: ta.Callable[P, ta.Awaitable[T]]) -> MaysyncP[P, T]:
|
29
|
+
return ta.cast('MaysyncP[P, T]', _maysync(
|
40
30
|
m,
|
41
31
|
))
|
omlish/lite/maysyncs.py
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
# ruff: noqa: UP045
|
2
2
|
# @omlish-lite
|
3
|
+
"""
|
4
|
+
TODO:
|
5
|
+
- __del__
|
6
|
+
"""
|
3
7
|
import abc
|
4
|
-
import dataclasses as dc
|
5
8
|
import functools
|
6
9
|
import typing as ta
|
7
10
|
|
8
|
-
from .args import Args
|
9
|
-
from .check import check
|
10
|
-
|
11
11
|
|
12
12
|
T = ta.TypeVar('T')
|
13
|
+
T_co = ta.TypeVar('T_co', covariant=True)
|
14
|
+
_X = ta.TypeVar('_X')
|
13
15
|
|
14
16
|
_MaysyncGen = ta.Generator['_MaysyncOp', ta.Any, T] # ta.TypeAlias
|
15
17
|
|
@@ -17,62 +19,115 @@ _MaysyncGen = ta.Generator['_MaysyncOp', ta.Any, T] # ta.TypeAlias
|
|
17
19
|
##
|
18
20
|
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
38
|
|
26
|
-
@abc.abstractmethod
|
27
|
-
def a(self, *args: ta.Any, **kwargs: ta.Any) -> ta.Awaitable[T]:
|
28
|
-
raise NotImplementedError
|
29
39
|
|
40
|
+
##
|
41
|
+
|
42
|
+
|
43
|
+
class _Maywaitable(abc.ABC, ta.Generic[_X, T]):
|
30
44
|
@ta.final
|
31
|
-
def
|
32
|
-
|
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
|
+
))
|
33
62
|
|
34
63
|
|
35
64
|
##
|
36
65
|
|
37
66
|
|
38
|
-
@
|
39
|
-
class
|
40
|
-
|
41
|
-
|
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
|
+
)
|
42
86
|
|
43
|
-
def
|
44
|
-
|
45
|
-
check.not_none(self.a)
|
87
|
+
def __call__(self, *args, **kwargs):
|
88
|
+
return _FnMaywaitable(self, *args, **kwargs)
|
46
89
|
|
47
|
-
def __init_subclass__(cls, **kwargs):
|
48
|
-
raise TypeError
|
49
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)
|
50
95
|
|
51
|
-
|
96
|
+
async def a(self) -> T:
|
97
|
+
return await self.x.a(*self.args, **self.kwargs)
|
52
98
|
|
53
99
|
|
54
100
|
def make_maysync(
|
55
101
|
s: ta.Callable[..., T],
|
56
102
|
a: ta.Callable[..., ta.Awaitable[T]],
|
57
|
-
) ->
|
58
|
-
return
|
59
|
-
s,
|
60
|
-
a,
|
61
|
-
)
|
103
|
+
) -> Maysync[T]:
|
104
|
+
return _FnMaysync(s, a)
|
62
105
|
|
63
106
|
|
64
107
|
##
|
65
108
|
|
66
109
|
|
67
|
-
@
|
68
|
-
class
|
69
|
-
|
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
|
70
117
|
|
71
|
-
def
|
72
|
-
|
118
|
+
def __get__(self, instance, owner=None):
|
119
|
+
return _MgMaysync(
|
120
|
+
self.mg.__get__(instance, owner), # noqa
|
121
|
+
)
|
73
122
|
|
74
|
-
def
|
75
|
-
|
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)
|
76
131
|
|
77
132
|
i: ta.Any = None
|
78
133
|
e: ta.Any = None
|
@@ -89,14 +144,18 @@ class _MgMaysyncable(Maysyncable[T]):
|
|
89
144
|
i = None
|
90
145
|
e = None
|
91
146
|
|
92
|
-
|
147
|
+
if not isinstance(o, _MaysyncOp):
|
148
|
+
raise TypeError(o)
|
149
|
+
|
93
150
|
try:
|
94
|
-
i =
|
151
|
+
i = o.x(*o.args, **o.kwargs).s()
|
95
152
|
except BaseException as ex: # noqa
|
96
153
|
e = ex
|
97
154
|
|
98
|
-
|
99
|
-
|
155
|
+
del o
|
156
|
+
|
157
|
+
async def a(self) -> T:
|
158
|
+
g = self.x.mg(*self.args, **self.kwargs)
|
100
159
|
|
101
160
|
i: ta.Any = None
|
102
161
|
e: ta.Any = None
|
@@ -113,18 +172,31 @@ class _MgMaysyncable(Maysyncable[T]):
|
|
113
172
|
i = None
|
114
173
|
e = None
|
115
174
|
|
116
|
-
|
175
|
+
if not isinstance(o, _MaysyncOp):
|
176
|
+
raise TypeError(o)
|
177
|
+
|
117
178
|
try:
|
118
|
-
i = await
|
179
|
+
i = await o.x(*o.args, **o.kwargs).a()
|
119
180
|
except BaseException as ex: # noqa
|
120
181
|
e = ex
|
121
182
|
|
183
|
+
del o
|
184
|
+
|
185
|
+
|
186
|
+
@ta.final
|
187
|
+
class _MgMaysyncFn:
|
188
|
+
def __init__(self, m):
|
189
|
+
self.m = m
|
122
190
|
|
123
|
-
|
124
|
-
@functools.wraps(m)
|
125
|
-
def mg_fn(*args, **kwargs):
|
126
|
-
a = m(*args, **kwargs).__await__()
|
191
|
+
functools.update_wrapper(self, m)
|
127
192
|
|
193
|
+
def __get__(self, instance, owner=None):
|
194
|
+
return _MgMaysyncFn(
|
195
|
+
self.m.__get__(instance, owner),
|
196
|
+
)
|
197
|
+
|
198
|
+
def __call__(self, *args, **kwargs):
|
199
|
+
a = self.m(*args, **kwargs).__await__()
|
128
200
|
try:
|
129
201
|
g = iter(a)
|
130
202
|
try:
|
@@ -134,13 +206,17 @@ def maysync(m: ta.Callable[..., ta.Awaitable[T]]) -> Maysyncable[T]:
|
|
134
206
|
except StopIteration as e:
|
135
207
|
return e.value
|
136
208
|
|
137
|
-
|
138
|
-
|
209
|
+
if not isinstance(o, _MaysyncFuture):
|
210
|
+
raise TypeError(o)
|
211
|
+
|
212
|
+
if not o.done:
|
139
213
|
try:
|
140
|
-
|
214
|
+
o.result = yield o.op
|
141
215
|
except BaseException as e: # noqa
|
142
|
-
|
143
|
-
|
216
|
+
o.error = e
|
217
|
+
o.done = True
|
218
|
+
|
219
|
+
del o
|
144
220
|
|
145
221
|
finally:
|
146
222
|
g.close()
|
@@ -148,37 +224,49 @@ def maysync(m: ta.Callable[..., ta.Awaitable[T]]) -> Maysyncable[T]:
|
|
148
224
|
finally:
|
149
225
|
a.close()
|
150
226
|
|
151
|
-
|
227
|
+
|
228
|
+
def maysync(m: ta.Callable[..., ta.Awaitable[T]]) -> Maysync[T]:
|
229
|
+
return _MgMaysync(_MgMaysyncFn(m))
|
152
230
|
|
153
231
|
|
154
232
|
##
|
155
233
|
|
156
234
|
|
157
|
-
@
|
235
|
+
@ta.final
|
158
236
|
class _MaysyncOp:
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
237
|
+
def __init__(
|
238
|
+
self,
|
239
|
+
x: Maysync[T],
|
240
|
+
*args: ta.Any,
|
241
|
+
**kwargs: ta.Any,
|
242
|
+
) -> None:
|
243
|
+
self.x = x
|
244
|
+
self.args = args
|
245
|
+
self.kwargs = kwargs
|
164
246
|
|
165
247
|
|
166
|
-
|
248
|
+
class _MaysyncFutureNotAwaitedError(RuntimeError):
|
249
|
+
pass
|
167
250
|
|
168
251
|
|
169
|
-
@
|
252
|
+
@ta.final
|
170
253
|
class _MaysyncFuture(ta.Generic[T]):
|
171
|
-
|
254
|
+
def __init__(
|
255
|
+
self,
|
256
|
+
op: _MaysyncOp,
|
257
|
+
) -> None:
|
258
|
+
self.op = op
|
172
259
|
|
173
260
|
done: bool = False
|
261
|
+
result: T
|
174
262
|
error: ta.Optional[BaseException] = None
|
175
|
-
result: ta.Optional[T] = None
|
176
263
|
|
177
264
|
def __await__(self):
|
178
265
|
if not self.done:
|
179
266
|
yield self
|
180
267
|
if not self.done:
|
181
|
-
raise
|
268
|
+
raise _MaysyncFutureNotAwaitedError
|
182
269
|
if self.error is not None:
|
183
270
|
raise self.error
|
184
|
-
|
271
|
+
else:
|
272
|
+
return self.result
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# ruff: noqa: UP006 UP007 UP045
|
2
2
|
# @omlish-lite
|
3
3
|
import abc
|
4
|
+
import subprocess
|
4
5
|
import sys
|
5
6
|
import typing as ta
|
6
7
|
|
8
|
+
from ..lite.check import check
|
7
9
|
from ..lite.timeouts import TimeoutLike
|
8
10
|
from .base import BaseSubprocesses
|
9
11
|
from .run import SubprocessRun
|
@@ -15,7 +17,7 @@ from .run import SubprocessRunOutput
|
|
15
17
|
|
16
18
|
class AbstractAsyncSubprocesses(BaseSubprocesses):
|
17
19
|
@abc.abstractmethod
|
18
|
-
|
20
|
+
def run_(self, run: SubprocessRun) -> ta.Awaitable[SubprocessRunOutput]:
|
19
21
|
raise NotImplementedError
|
20
22
|
|
21
23
|
def run(
|
@@ -38,31 +40,41 @@ class AbstractAsyncSubprocesses(BaseSubprocesses):
|
|
38
40
|
|
39
41
|
#
|
40
42
|
|
41
|
-
@abc.abstractmethod
|
42
43
|
async def check_call(
|
43
44
|
self,
|
44
45
|
*cmd: str,
|
45
46
|
stdout: ta.Any = sys.stderr,
|
46
47
|
**kwargs: ta.Any,
|
47
48
|
) -> None:
|
48
|
-
|
49
|
+
await self.run(
|
50
|
+
*cmd,
|
51
|
+
stdout=stdout,
|
52
|
+
check=True,
|
53
|
+
**kwargs,
|
54
|
+
)
|
49
55
|
|
50
|
-
@abc.abstractmethod
|
51
56
|
async def check_output(
|
52
57
|
self,
|
53
58
|
*cmd: str,
|
59
|
+
stdout: ta.Any = subprocess.PIPE,
|
54
60
|
**kwargs: ta.Any,
|
55
61
|
) -> bytes:
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
return check.not_none((await self.run(
|
63
|
+
*cmd,
|
64
|
+
stdout=stdout,
|
65
|
+
check=True,
|
66
|
+
**kwargs,
|
67
|
+
)).stdout)
|
59
68
|
|
60
69
|
async def check_output_str(
|
61
70
|
self,
|
62
71
|
*cmd: str,
|
63
72
|
**kwargs: ta.Any,
|
64
73
|
) -> str:
|
65
|
-
return (await self.check_output(
|
74
|
+
return (await self.check_output(
|
75
|
+
*cmd,
|
76
|
+
**kwargs,
|
77
|
+
)).decode().strip()
|
66
78
|
|
67
79
|
#
|
68
80
|
|
@@ -0,0 +1,152 @@
|
|
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 Maywaitable
|
8
|
+
from ..lite.maysyncs import make_maysync
|
9
|
+
from ..lite.maysyncs import maysync
|
10
|
+
from ..lite.timeouts import TimeoutLike
|
11
|
+
from .asyncs import AbstractAsyncSubprocesses
|
12
|
+
from .base import BaseSubprocesses
|
13
|
+
from .run import SubprocessRun
|
14
|
+
from .run import SubprocessRunOutput
|
15
|
+
from .sync import AbstractSubprocesses
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
|
20
|
+
|
21
|
+
class AbstractMaysyncSubprocesses(BaseSubprocesses, abc.ABC):
|
22
|
+
@abc.abstractmethod
|
23
|
+
def run_(self, run: SubprocessRun) -> Maywaitable[SubprocessRunOutput]:
|
24
|
+
raise NotImplementedError
|
25
|
+
|
26
|
+
def run(
|
27
|
+
self,
|
28
|
+
*cmd: str,
|
29
|
+
input: ta.Any = None, # noqa
|
30
|
+
timeout: TimeoutLike = None,
|
31
|
+
check: bool = False,
|
32
|
+
capture_output: ta.Optional[bool] = None,
|
33
|
+
**kwargs: ta.Any,
|
34
|
+
) -> Maywaitable[SubprocessRunOutput]:
|
35
|
+
return self.run_(SubprocessRun(
|
36
|
+
cmd=cmd,
|
37
|
+
input=input,
|
38
|
+
timeout=timeout,
|
39
|
+
check=check,
|
40
|
+
capture_output=capture_output,
|
41
|
+
kwargs=kwargs,
|
42
|
+
))
|
43
|
+
|
44
|
+
#
|
45
|
+
|
46
|
+
@abc.abstractmethod
|
47
|
+
def check_call(
|
48
|
+
self,
|
49
|
+
*cmd: str,
|
50
|
+
stdout: ta.Any = sys.stderr,
|
51
|
+
**kwargs: ta.Any,
|
52
|
+
) -> Maywaitable[None]:
|
53
|
+
raise NotImplementedError
|
54
|
+
|
55
|
+
@abc.abstractmethod
|
56
|
+
def check_output(
|
57
|
+
self,
|
58
|
+
*cmd: str,
|
59
|
+
**kwargs: ta.Any,
|
60
|
+
) -> Maywaitable[bytes]:
|
61
|
+
raise NotImplementedError
|
62
|
+
|
63
|
+
#
|
64
|
+
|
65
|
+
@maysync
|
66
|
+
async def check_output_str(
|
67
|
+
self,
|
68
|
+
*cmd: str,
|
69
|
+
**kwargs: ta.Any,
|
70
|
+
) -> str:
|
71
|
+
return (await self.check_output(*cmd, **kwargs).m()).decode().strip()
|
72
|
+
|
73
|
+
#
|
74
|
+
|
75
|
+
@maysync
|
76
|
+
async def try_call(
|
77
|
+
self,
|
78
|
+
*cmd: str,
|
79
|
+
**kwargs: ta.Any,
|
80
|
+
) -> bool:
|
81
|
+
if isinstance(await self.async_try_fn(self.check_call(*cmd, **kwargs).m), Exception):
|
82
|
+
return False
|
83
|
+
else:
|
84
|
+
return True
|
85
|
+
|
86
|
+
@maysync
|
87
|
+
async def try_output(
|
88
|
+
self,
|
89
|
+
*cmd: str,
|
90
|
+
**kwargs: ta.Any,
|
91
|
+
) -> ta.Optional[bytes]:
|
92
|
+
if isinstance(ret := await self.async_try_fn(self.check_output(*cmd, **kwargs).m), Exception):
|
93
|
+
return None
|
94
|
+
else:
|
95
|
+
return ret
|
96
|
+
|
97
|
+
@maysync
|
98
|
+
async def try_output_str(
|
99
|
+
self,
|
100
|
+
*cmd: str,
|
101
|
+
**kwargs: ta.Any,
|
102
|
+
) -> ta.Optional[str]:
|
103
|
+
if (ret := await self.try_output(*cmd, **kwargs).m()) is None:
|
104
|
+
return None
|
105
|
+
else:
|
106
|
+
return ret.decode().strip()
|
107
|
+
|
108
|
+
|
109
|
+
##
|
110
|
+
|
111
|
+
|
112
|
+
class MaysyncSubprocesses(AbstractMaysyncSubprocesses):
|
113
|
+
def __init__(
|
114
|
+
self,
|
115
|
+
subprocesses: AbstractSubprocesses,
|
116
|
+
async_subprocesses: AbstractAsyncSubprocesses,
|
117
|
+
) -> None:
|
118
|
+
super().__init__()
|
119
|
+
|
120
|
+
self._subprocesses = subprocesses
|
121
|
+
self._async_subprocesses = async_subprocesses
|
122
|
+
|
123
|
+
#
|
124
|
+
|
125
|
+
def run_(self, run: SubprocessRun) -> Maywaitable[SubprocessRunOutput]:
|
126
|
+
return make_maysync(
|
127
|
+
self._subprocesses.run,
|
128
|
+
self._async_subprocesses.run,
|
129
|
+
)(run)
|
130
|
+
|
131
|
+
#
|
132
|
+
|
133
|
+
def check_call(
|
134
|
+
self,
|
135
|
+
*cmd: str,
|
136
|
+
stdout: ta.Any = sys.stderr,
|
137
|
+
**kwargs: ta.Any,
|
138
|
+
) -> Maywaitable[None]:
|
139
|
+
return make_maysync(
|
140
|
+
self._subprocesses.check_call,
|
141
|
+
self._async_subprocesses.check_call,
|
142
|
+
)(*cmd, stdout=stdout, **kwargs)
|
143
|
+
|
144
|
+
def check_output(
|
145
|
+
self,
|
146
|
+
*cmd: str,
|
147
|
+
**kwargs: ta.Any,
|
148
|
+
) -> Maywaitable[bytes]:
|
149
|
+
return make_maysync(
|
150
|
+
self._subprocesses.check_output,
|
151
|
+
self._async_subprocesses.check_output,
|
152
|
+
)(*cmd, **kwargs)
|
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))
|
omlish/subprocesses/sync.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=nywiLIvIX-iNrqLzoBB2G9Oux2R2MJWTjuu4s5X9qzM,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
|
@@ -34,7 +34,7 @@ omlish/asyncs/anyio/backends.py,sha256=jJIymWoiedaEJJm82gvKiJ41EWLQZ-bcyNHpbDpKK
|
|
34
34
|
omlish/asyncs/anyio/futures.py,sha256=Nm1gLerZEnHk-rlsmr0UfK168IWIK6zA8EebZFtoY_E,2052
|
35
35
|
omlish/asyncs/anyio/signals.py,sha256=ySSut5prdnoy0-5Ws5V1M4cC2ON_vY550vU10d2NHk8,893
|
36
36
|
omlish/asyncs/anyio/streams.py,sha256=Zum2qd1t3EiH6yzGWFwxFw79m-IH2VY5sTUTiluFfIY,2164
|
37
|
-
omlish/asyncs/anyio/subprocesses.py,sha256=
|
37
|
+
omlish/asyncs/anyio/subprocesses.py,sha256=5nWYw9sPaelK2AJ17NHTHQ34Qa3DXCFkcTpvddzjboA,2500
|
38
38
|
omlish/asyncs/anyio/sync.py,sha256=ZmSNhSsEkPwlXThrpefhtVTxw4GJ9F0P-yKyo5vbbSk,1574
|
39
39
|
omlish/asyncs/anyio/utils.py,sha256=-mveSB20De6znphfMlIuEd_rwITkcSjFNO07isshDjk,1704
|
40
40
|
omlish/asyncs/asyncio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -42,7 +42,7 @@ omlish/asyncs/asyncio/all.py,sha256=u2JpMEs-0AJ0Vd8yU10HvWD8rfKxdFfMiwBu2oDeuuQ,
|
|
42
42
|
omlish/asyncs/asyncio/channels.py,sha256=oniTpmw_eeKK70APyEZLhRUChwLwebE4N0_uZiwSKgQ,1085
|
43
43
|
omlish/asyncs/asyncio/sockets.py,sha256=i1a2DZ52IuvRQQQW8FJxEUFboqpKn_K08a_MsMaecqU,1264
|
44
44
|
omlish/asyncs/asyncio/streams.py,sha256=Laa9BNwajZ7Wt_rJoYMbQtfSX4Q4i-dVHhtYSekCHXM,1015
|
45
|
-
omlish/asyncs/asyncio/subprocesses.py,sha256=
|
45
|
+
omlish/asyncs/asyncio/subprocesses.py,sha256=8o-uWNsJhSoM7Egbofc23CeJFRmb4isb9zVVh1Fxjfk,6285
|
46
46
|
omlish/asyncs/asyncio/timeouts.py,sha256=lJ4qmDqyxUeAQCXJGiLL8pxYwoR1F1lntZ18HVf40Wo,452
|
47
47
|
omlish/asyncs/asyncio/utils.py,sha256=dCC4hXqCTKBpU5urAXsKUIIua2M9JXAtumwh7IUEu7E,2443
|
48
48
|
omlish/asyncs/bluelet/LICENSE,sha256=q5Kpj4s30qpi8H66tXFlh5v8_fkaKMFIzqdGfnN0Hz0,555
|
@@ -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/maysyncs.py,sha256=
|
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
|
@@ -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/maysyncs.py,sha256=
|
481
|
+
omlish/lite/maysyncs.py,sha256=qPYJw9adceaoW50PqyLRomlrhxjnzLBxswjyMaUk04M,5755
|
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,11 +748,12 @@ 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/
|
751
|
+
omlish/subprocesses/asyncs.py,sha256=G9wj275s3r0ueftHFl73Lt4kMRBc2hJOKcoJQCDlBms,2663
|
752
752
|
omlish/subprocesses/base.py,sha256=r60N3ad4ooSvdgFmT94L_xZEy7FMbMX6JcG2VgpHo6w,6139
|
753
753
|
omlish/subprocesses/editor.py,sha256=xBrd7gY0akhRfDIBK5YIBrYMHECtl_8r499iKViyfpQ,2634
|
754
|
-
omlish/subprocesses/
|
755
|
-
omlish/subprocesses/
|
754
|
+
omlish/subprocesses/maysyncs.py,sha256=XWWVC-jyjVJLcT-nWMZFf4jUQesRuBWWVhmwcG_fUWE,3818
|
755
|
+
omlish/subprocesses/run.py,sha256=8EeMm2FdNEFmEmbhhzJyHXASUhCCMMRN_-8ybqFhgLI,4378
|
756
|
+
omlish/subprocesses/sync.py,sha256=L-ZNj9RrZd69XjlKrXjt-EJ-XUpQF8E35Mh3b3SI3vc,3671
|
756
757
|
omlish/subprocesses/utils.py,sha256=v5uEzxmbmRvXwOl_0DtBa5Il6yITKYRgmVSGHcLsT4o,402
|
757
758
|
omlish/subprocesses/wrap.py,sha256=AhGV8rsnaVUMQCFYKkrjj35fs3O-VJLZC1hZ14dz3C8,769
|
758
759
|
omlish/term/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -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.dev389.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
899
|
+
omlish-0.0.0.dev389.dist-info/METADATA,sha256=YuiaRpmbQmDNnnQ-xxr5mY0iJC-fWVgVqlOANsG00BE,18825
|
900
|
+
omlish-0.0.0.dev389.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
901
|
+
omlish-0.0.0.dev389.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
902
|
+
omlish-0.0.0.dev389.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
903
|
+
omlish-0.0.0.dev389.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|