omlish 0.0.0.dev408__py3-none-any.whl → 0.0.0.dev410__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/all.py +0 -8
- omlish/asyncs/bridge.py +1 -2
- omlish/lang/__init__.py +14 -4
- omlish/lang/asyncs.py +80 -0
- omlish/lang/imports/conditional.py +1 -1
- omlish/lang/maysyncs.py +40 -9
- omlish/lite/maysyncs.py +550 -126
- omlish/manifests/loading.py +19 -33
- omlish/subprocesses/maysyncs.py +4 -4
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/RECORD +17 -17
- omlish/asyncs/sync.py +0 -80
- /omlish/lang/imports/{resolution.py → resolving.py} +0 -0
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev408.dist-info → omlish-0.0.0.dev410.dist-info}/top_level.txt +0 -0
omlish/manifests/loading.py
CHANGED
@@ -209,6 +209,7 @@ class ManifestLoader:
|
|
209
209
|
@classmethod
|
210
210
|
def _discover_packages_uncached(cls) -> ta.Sequence[str]:
|
211
211
|
from importlib import metadata as importlib_metadata # noqa
|
212
|
+
|
212
213
|
return [
|
213
214
|
ep.value
|
214
215
|
for ep in importlib_metadata.entry_points(group=cls.ENTRY_POINT_GROUP)
|
@@ -262,35 +263,31 @@ class ManifestLoader:
|
|
262
263
|
|
263
264
|
##
|
264
265
|
|
265
|
-
|
266
|
-
|
267
|
-
def _do_initialize(self) -> None:
|
268
|
-
self._detected_packages = set()
|
266
|
+
def _detect_packages_uncached(self) -> ta.AbstractSet[str]:
|
267
|
+
ret: ta.Set[str] = set()
|
269
268
|
|
270
269
|
for r in self._config.package_scan_root_dirs or []:
|
271
|
-
|
270
|
+
ret.update(self._scan_package_root_dir_locked(r))
|
272
271
|
|
273
272
|
if self._config.discover_packages:
|
274
|
-
|
273
|
+
ret.update(dps := self.discover_packages())
|
275
274
|
if not dps:
|
276
275
|
for r in self._config.discover_packages_fallback_scan_root_dirs or []:
|
277
|
-
|
276
|
+
ret.update(self._scan_package_root_dir_locked(r))
|
278
277
|
|
279
|
-
|
278
|
+
return ret
|
280
279
|
|
281
|
-
|
282
|
-
if not self._has_initialized:
|
283
|
-
self._do_initialize()
|
284
|
-
self._has_initialized = True
|
280
|
+
_detected_packages: ta.Optional[ta.AbstractSet[str]] = None
|
285
281
|
|
286
|
-
def
|
287
|
-
|
288
|
-
|
282
|
+
def _detect_packages_locked(self) -> ta.AbstractSet[str]:
|
283
|
+
if self._detected_packages is None:
|
284
|
+
self._detected_packages = self._detect_packages_uncached()
|
289
285
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
286
|
+
return self._detected_packages
|
287
|
+
|
288
|
+
def detect_packages(self) -> ta.AbstractSet[str]:
|
289
|
+
with self._lock:
|
290
|
+
return self._detect_packages_locked()
|
294
291
|
|
295
292
|
##
|
296
293
|
|
@@ -429,6 +426,7 @@ class ManifestLoader:
|
|
429
426
|
return f.read()
|
430
427
|
|
431
428
|
from importlib import resources as importlib_resources # noqa
|
429
|
+
|
432
430
|
t = importlib_resources.files(package_name).joinpath(file_name)
|
433
431
|
if not t.is_file():
|
434
432
|
return None
|
@@ -497,7 +495,7 @@ class ManifestLoader:
|
|
497
495
|
|
498
496
|
##
|
499
497
|
|
500
|
-
def
|
498
|
+
def _load_locked(
|
501
499
|
self,
|
502
500
|
*,
|
503
501
|
packages: ta.Optional[ta.Collection[str]] = None,
|
@@ -511,7 +509,7 @@ class ManifestLoader:
|
|
511
509
|
class_keys = {self.get_class_key(cls) for cls in classes}
|
512
510
|
|
513
511
|
if packages is None:
|
514
|
-
packages = self.
|
512
|
+
packages = self._detect_packages_locked()
|
515
513
|
|
516
514
|
lst: ta.List[ManifestLoader.LoadedManifest] = []
|
517
515
|
for pn in packages:
|
@@ -527,18 +525,6 @@ class ManifestLoader:
|
|
527
525
|
|
528
526
|
return lst
|
529
527
|
|
530
|
-
def _load_locked(
|
531
|
-
self,
|
532
|
-
*,
|
533
|
-
packages: ta.Optional[ta.Collection[str]] = None,
|
534
|
-
classes: ta.Optional[ta.Collection[type]] = None,
|
535
|
-
) -> ta.Sequence[LoadedManifest]:
|
536
|
-
self._initialize_locked()
|
537
|
-
return self._load_initialized(
|
538
|
-
packages=packages,
|
539
|
-
classes=classes,
|
540
|
-
)
|
541
|
-
|
542
528
|
def load(
|
543
529
|
self,
|
544
530
|
*,
|
omlish/subprocesses/maysyncs.py
CHANGED
@@ -68,7 +68,7 @@ class AbstractMaysyncSubprocesses(BaseSubprocesses, abc.ABC):
|
|
68
68
|
*cmd: str,
|
69
69
|
**kwargs: ta.Any,
|
70
70
|
) -> str:
|
71
|
-
return (await self.check_output(*cmd, **kwargs).
|
71
|
+
return (await self.check_output(*cmd, **kwargs).a()).decode().strip()
|
72
72
|
|
73
73
|
#
|
74
74
|
|
@@ -78,7 +78,7 @@ class AbstractMaysyncSubprocesses(BaseSubprocesses, abc.ABC):
|
|
78
78
|
*cmd: str,
|
79
79
|
**kwargs: ta.Any,
|
80
80
|
) -> bool:
|
81
|
-
if isinstance(await self.async_try_fn(self.check_call(*cmd, **kwargs).
|
81
|
+
if isinstance(await self.async_try_fn(self.check_call(*cmd, **kwargs).a), Exception):
|
82
82
|
return False
|
83
83
|
else:
|
84
84
|
return True
|
@@ -89,7 +89,7 @@ class AbstractMaysyncSubprocesses(BaseSubprocesses, abc.ABC):
|
|
89
89
|
*cmd: str,
|
90
90
|
**kwargs: ta.Any,
|
91
91
|
) -> ta.Optional[bytes]:
|
92
|
-
if isinstance(ret := await self.async_try_fn(self.check_output(*cmd, **kwargs).
|
92
|
+
if isinstance(ret := await self.async_try_fn(self.check_output(*cmd, **kwargs).a), Exception):
|
93
93
|
return None
|
94
94
|
else:
|
95
95
|
return ret
|
@@ -100,7 +100,7 @@ class AbstractMaysyncSubprocesses(BaseSubprocesses, abc.ABC):
|
|
100
100
|
*cmd: str,
|
101
101
|
**kwargs: ta.Any,
|
102
102
|
) -> ta.Optional[str]:
|
103
|
-
if (ret := await self.try_output(*cmd, **kwargs).
|
103
|
+
if (ret := await self.try_output(*cmd, **kwargs).a()) is None:
|
104
104
|
return None
|
105
105
|
else:
|
106
106
|
return ret.decode().strip()
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=FLw7xkPiSXuImZgqSP8BwrEib2R1doSzUPLUkc-QUIA,8410
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=4TpD9f2NLOxe8wPIx2jkab-TAgd8pW7229kNrBPdko4,3601
|
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
|
@@ -21,11 +21,10 @@ omlish/argparse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
21
|
omlish/argparse/all.py,sha256=NeeMM5MIebY7XDAHaCxUzeesEoUYwsf5i9PrBUcO1cI,1057
|
22
22
|
omlish/argparse/cli.py,sha256=60cfq_WFLwL3YsIQxGAQ7XDi-LzNjH33RavcKdRnhUU,8737
|
23
23
|
omlish/asyncs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
omlish/asyncs/all.py,sha256=
|
25
|
-
omlish/asyncs/bridge.py,sha256=
|
24
|
+
omlish/asyncs/all.py,sha256=cS7dTWR8l3vF0oWYYiV9JXp0YGxOecVyCuJ2fydAPU0,526
|
25
|
+
omlish/asyncs/bridge.py,sha256=iRUUrvw5-5YxBxhsy57TvhpM_DmH_JH1QceexkGmiBw,10129
|
26
26
|
omlish/asyncs/buffers.py,sha256=_Ds4Aa1bUWQwQTGmcYsKLjcJ_d5HgbSkPTFrG9y-eMQ,1424
|
27
27
|
omlish/asyncs/flavors.py,sha256=1mNxGNRVmjUHzA13K5ht8vdJv4CLEmzYTQ6BZXr1520,4866
|
28
|
-
omlish/asyncs/sync.py,sha256=hS6VltWMkGnMgDjygls50RD_z-FBdpmlr4q8W_i0fCI,2040
|
29
28
|
omlish/asyncs/trio.py,sha256=fmZ5b_lKdVV8NQ3euCUutWgnkqTFzSnOjvJSA_jvmrE,367
|
30
29
|
omlish/asyncs/trio_asyncio.py,sha256=b6H5H32pB79Uz5xvWEmuhXTJgTAeKFHBHzocv_Rpt5A,1332
|
31
30
|
omlish/asyncs/utils.py,sha256=-oaa6nheDxMOxVDTfRylWZGlyOja3UVJEV2IibJXQv4,369
|
@@ -426,7 +425,8 @@ omlish/iterators/iterators.py,sha256=RxW35yQ5ed8vBQ22IqpDXFx-i5JiLQdp7-pkMZXhJJ8
|
|
426
425
|
omlish/iterators/recipes.py,sha256=wOwOZg-zWG9Zc3wcAxJFSe2rtavVBYwZOfG09qYEx_4,472
|
427
426
|
omlish/iterators/tools.py,sha256=M16LXrJhMdsz5ea2qH0vws30ZvhQuQSCVFSLpRf_gTg,2096
|
428
427
|
omlish/iterators/unique.py,sha256=BSE-eanva8byFCJi09Nt2zzTsVr8LnTqY1PIInGYRs0,1396
|
429
|
-
omlish/lang/__init__.py,sha256=
|
428
|
+
omlish/lang/__init__.py,sha256=AiFCnMJZo2lXrEOqgU29UAjk8Ovnuc_lwMYuLy6Y748,7393
|
429
|
+
omlish/lang/asyncs.py,sha256=HQrf8oaaZnUYbFwIiVLYvsEshJarMvRNHZ3VN-RyqLY,1789
|
430
430
|
omlish/lang/attrs.py,sha256=zFiVuGVOq88x45464T_LxDa-ZEq_RD9zJLq2zeVEBDc,5105
|
431
431
|
omlish/lang/casing.py,sha256=cFUlbDdXLhwnWwcYx4qnM5c4zGX7hIRUfcjiZbxUD28,4636
|
432
432
|
omlish/lang/clsdct.py,sha256=HAGIvBSbCefzRjXriwYSBLO7QHKRv2UsE78jixOb-fA,1828
|
@@ -441,7 +441,7 @@ omlish/lang/functions.py,sha256=aLdxhmqG0Pj9tBgsKdoCu_q15r82WIkNqDDSPQU19L8,5689
|
|
441
441
|
omlish/lang/generators.py,sha256=a4D5HU_mySs2T2z3xCmE_s3t4QJkj0YRrK4-hhpGd0A,5197
|
442
442
|
omlish/lang/iterables.py,sha256=y1SX2Co3VsOeX2wlfFF7K3rwLvF7Dtre7VY6EpfwAwA,3338
|
443
443
|
omlish/lang/lazyglobals.py,sha256=G1hwpyIgM4PUkVJ_St3K-EdQkHQdWpFOcXao6I5LwyY,1435
|
444
|
-
omlish/lang/maysyncs.py,sha256=
|
444
|
+
omlish/lang/maysyncs.py,sha256=Fa6jk8v0JQzoGvg7UbpCQXzrvWUuRqBG9XZCikbYvoQ,1646
|
445
445
|
omlish/lang/objects.py,sha256=eOhFyFiwvxqpbLs5QTEkXU3rdSt_tQXDgHoWF5SA28E,6119
|
446
446
|
omlish/lang/outcomes.py,sha256=0PqxoKaGbBXU9UYZ6AE2QSq94Z-gFDt6wYdp0KomNQw,8712
|
447
447
|
omlish/lang/overrides.py,sha256=IBzK6ljfLX6TLgIyKTSjhqTLcuKRkQNVtEOnBLS4nuA,2095
|
@@ -464,10 +464,10 @@ omlish/lang/classes/restrict.py,sha256=CUyvLpMYiQwTjpzo5sdG_lQxdeEIq2z2xSVNrsI9K
|
|
464
464
|
omlish/lang/classes/simple.py,sha256=9blmJdi4c15zyIEbNVjkA0ZTSImQbv4g0p2Il6knWAc,2539
|
465
465
|
omlish/lang/classes/virtual.py,sha256=z0MYQD9Q5MkX8DzF325wDB4J9XoYbsB09jZ1omC62To,3366
|
466
466
|
omlish/lang/imports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
467
|
-
omlish/lang/imports/conditional.py,sha256=
|
467
|
+
omlish/lang/imports/conditional.py,sha256=R-E47QD95mMonPImWlrde3rnJrFKCCkYz71c94W05sc,1006
|
468
468
|
omlish/lang/imports/lazy.py,sha256=Fhtb5tSAttff6G2pZdF8bh__GZlqJWHaMKtA8KubuX4,1479
|
469
469
|
omlish/lang/imports/proxyinit.py,sha256=ALpV9LahE8SQl6jNO92Mk4PcaQPce9Cv53K8AwnH5fQ,16749
|
470
|
-
omlish/lang/imports/
|
470
|
+
omlish/lang/imports/resolving.py,sha256=DeRarn35Fryg5JhVhy8wbiC9lvr58AnllI9B_reswUE,2085
|
471
471
|
omlish/lang/imports/traversal.py,sha256=pbFQIa880NGjSfcLsno2vE_G41_CLwDHb-7gWg2J3BI,2855
|
472
472
|
omlish/lifecycles/__init__.py,sha256=1FjYceXs-4fc-S-C9zFYmc2axHs4znnQHcJVHdY7a6E,578
|
473
473
|
omlish/lifecycles/abstract.py,sha256=c9UY7oxzYZ_neh5DPE4yv5HfuDv7B4Mj_9Zo-B8KDSs,1114
|
@@ -490,7 +490,7 @@ omlish/lite/json.py,sha256=m0Ce9eqUZG23-H7-oOp8n1sf4fzno5vtK4AK_4Vc-Mg,706
|
|
490
490
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
491
491
|
omlish/lite/marshal.py,sha256=K_wnZwfC8cftGILyE3RlmzQEYuZOfzkMLKey41zuwtM,20296
|
492
492
|
omlish/lite/maybes.py,sha256=0p_fzb6yiOjEpvMKaQ53Q6CH1VPW1or7v7Lt1JIKcgM,4359
|
493
|
-
omlish/lite/maysyncs.py,sha256=
|
493
|
+
omlish/lite/maysyncs.py,sha256=XZ-zbK3bES8Al6--lYcvGGhYKqfVg1zoHJ6GCwLbiv4,19663
|
494
494
|
omlish/lite/pycharm.py,sha256=FRHGcCDo42UzZXqNwW_DkhI-6kb_CmJKPiQ8F6mYkLA,1174
|
495
495
|
omlish/lite/reflect.py,sha256=gI-Qlws9V-jND7kvCQFaIhBFrndVpDsikTQ7C6U2z3w,2434
|
496
496
|
omlish/lite/reprs.py,sha256=2Bc7ukhKvYNTKmxPIuv9glZIph13C37y_W4fg9pBnu8,2006
|
@@ -520,7 +520,7 @@ omlish/logs/utils.py,sha256=OkFWf1exmWImmT7BaSiIC7c0Fk9tAis-PRqo8H4ny3c,398
|
|
520
520
|
omlish/manifests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
521
521
|
omlish/manifests/base.py,sha256=Dt44a3qppWaxkoi3naFFMetxbxw14qnz2naTKK93GNU,915
|
522
522
|
omlish/manifests/globals.py,sha256=kVqQ-fT4kc7xWzLHoI731GviitFPv2v2yqw-p7t7Exs,2628
|
523
|
-
omlish/manifests/loading.py,sha256=
|
523
|
+
omlish/manifests/loading.py,sha256=Br1OyI23pis_FfYju9xoacms608lzB1Zh_IqdVw_7vg,17201
|
524
524
|
omlish/manifests/static.py,sha256=9BaPBLkuzxHmg5A-5k9BjjBFINCdmFOIu06dMFgCfz4,497
|
525
525
|
omlish/manifests/types.py,sha256=NeOGuIVrcbqjCDbQ3MnCxxHAgHnw0CkWJsBzo230PWE,453
|
526
526
|
omlish/marshal/.dataclasses.json,sha256=wXWUy_IR8AolAa2RQnqn_mo2QnmVcvUJmayIykdVl0I,22
|
@@ -765,7 +765,7 @@ omlish/subprocesses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
|
|
765
765
|
omlish/subprocesses/asyncs.py,sha256=G9wj275s3r0ueftHFl73Lt4kMRBc2hJOKcoJQCDlBms,2663
|
766
766
|
omlish/subprocesses/base.py,sha256=r60N3ad4ooSvdgFmT94L_xZEy7FMbMX6JcG2VgpHo6w,6139
|
767
767
|
omlish/subprocesses/editor.py,sha256=xBrd7gY0akhRfDIBK5YIBrYMHECtl_8r499iKViyfpQ,2634
|
768
|
-
omlish/subprocesses/maysyncs.py,sha256=
|
768
|
+
omlish/subprocesses/maysyncs.py,sha256=sHReoZhT7RRlON_FjcbbHYLvOqK7nyWfkGi6fI26SGY,3818
|
769
769
|
omlish/subprocesses/run.py,sha256=8EeMm2FdNEFmEmbhhzJyHXASUhCCMMRN_-8ybqFhgLI,4378
|
770
770
|
omlish/subprocesses/sync.py,sha256=L-ZNj9RrZd69XjlKrXjt-EJ-XUpQF8E35Mh3b3SI3vc,3671
|
771
771
|
omlish/subprocesses/utils.py,sha256=v5uEzxmbmRvXwOl_0DtBa5Il6yITKYRgmVSGHcLsT4o,402
|
@@ -909,9 +909,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
909
909
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
910
910
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
911
911
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
912
|
-
omlish-0.0.0.
|
913
|
-
omlish-0.0.0.
|
914
|
-
omlish-0.0.0.
|
915
|
-
omlish-0.0.0.
|
916
|
-
omlish-0.0.0.
|
917
|
-
omlish-0.0.0.
|
912
|
+
omlish-0.0.0.dev410.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
913
|
+
omlish-0.0.0.dev410.dist-info/METADATA,sha256=tqNKk_ovprTJtbpkIsi_jZRS44y4hTlBreu5pTxzTRs,18881
|
914
|
+
omlish-0.0.0.dev410.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
915
|
+
omlish-0.0.0.dev410.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
916
|
+
omlish-0.0.0.dev410.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
917
|
+
omlish-0.0.0.dev410.dist-info/RECORD,,
|
omlish/asyncs/sync.py
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
TODO:
|
3
|
-
- async<->sync greeenlet bridge
|
4
|
-
In [5]: %timeit greenlet.greenlet(f).switch()
|
5
|
-
517 ns ± 13.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
|
6
|
-
- injected io provider - sync vs greenlet aio trampolined
|
7
|
-
- push/pull bridge?
|
8
|
-
- move to lang
|
9
|
-
|
10
|
-
https://github.com/sqlalchemy/sqlalchemy/blob/1e75c189da721395bc8c2d899c722a5b9a170404/lib/sqlalchemy/util/_concurrency_py3k.py#L83
|
11
|
-
"""
|
12
|
-
import functools
|
13
|
-
import typing as ta
|
14
|
-
|
15
|
-
|
16
|
-
T = ta.TypeVar('T')
|
17
|
-
|
18
|
-
|
19
|
-
##
|
20
|
-
|
21
|
-
|
22
|
-
def sync_await(fn: ta.Callable[..., T], *args: ta.Any, **kwargs: ta.Any) -> T:
|
23
|
-
ret = missing = object()
|
24
|
-
|
25
|
-
async def gate():
|
26
|
-
nonlocal ret
|
27
|
-
ret = await fn(*args, **kwargs) # type: ignore
|
28
|
-
|
29
|
-
cr = gate()
|
30
|
-
try:
|
31
|
-
try:
|
32
|
-
cr.send(None)
|
33
|
-
except StopIteration:
|
34
|
-
pass
|
35
|
-
if ret is missing or cr.cr_await is not None or cr.cr_running:
|
36
|
-
raise TypeError('Not terminated')
|
37
|
-
finally:
|
38
|
-
cr.close()
|
39
|
-
|
40
|
-
return ret # type: ignore
|
41
|
-
|
42
|
-
|
43
|
-
def sync_list(fn: ta.Callable[..., ta.AsyncIterator[T]], *args, **kwargs) -> list[T]:
|
44
|
-
lst = None
|
45
|
-
|
46
|
-
async def inner():
|
47
|
-
nonlocal lst
|
48
|
-
lst = [v async for v in fn(*args, **kwargs)]
|
49
|
-
|
50
|
-
sync_await(inner)
|
51
|
-
if not isinstance(lst, list):
|
52
|
-
raise TypeError(lst)
|
53
|
-
return lst
|
54
|
-
|
55
|
-
|
56
|
-
async def async_list(fn: ta.Callable[..., ta.AsyncIterator[T]], *args, **kwargs) -> list[T]:
|
57
|
-
return [v async for v in fn(*args, **kwargs)]
|
58
|
-
|
59
|
-
|
60
|
-
class SyncableIterable(ta.Generic[T]):
|
61
|
-
def __init__(self, obj) -> None:
|
62
|
-
super().__init__()
|
63
|
-
|
64
|
-
self._obj = obj
|
65
|
-
|
66
|
-
def __iter__(self) -> ta.Iterator[T]:
|
67
|
-
async def inner():
|
68
|
-
async for i in self._obj:
|
69
|
-
yield i
|
70
|
-
return iter(sync_list(inner))
|
71
|
-
|
72
|
-
def __aiter__(self) -> ta.AsyncIterator[T]:
|
73
|
-
return self._obj.__aiter__()
|
74
|
-
|
75
|
-
|
76
|
-
def syncable_iterable(fn: ta.Callable[..., ta.AsyncIterator[T]]) -> ta.Callable[..., SyncableIterable[T]]:
|
77
|
-
@functools.wraps(fn)
|
78
|
-
def inner(*args, **kwargs):
|
79
|
-
return SyncableIterable(fn(*args, **kwargs))
|
80
|
-
return inner
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|