omlish 0.0.0.dev373__py3-none-any.whl → 0.0.0.dev374__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 +4 -1
- omlish/lang/functions.py +0 -32
- omlish/lite/args.py +36 -0
- omlish/testing/unittest/main.py +3 -0
- omlish/text/minja.py +39 -18
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/RECORD +12 -11
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev373.dist-info → omlish-0.0.0.dev374.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lang/__init__.py
CHANGED
@@ -174,7 +174,6 @@ from .enums import ( # noqa
|
|
174
174
|
)
|
175
175
|
|
176
176
|
from .functions import ( # noqa
|
177
|
-
Args,
|
178
177
|
VoidError,
|
179
178
|
as_async,
|
180
179
|
call_with,
|
@@ -359,6 +358,10 @@ from .typing import ( # noqa
|
|
359
358
|
|
360
359
|
##
|
361
360
|
|
361
|
+
from ..lite.args import ( # noqa
|
362
|
+
Args,
|
363
|
+
)
|
364
|
+
|
362
365
|
from ..lite.contextmanagers import ( # noqa
|
363
366
|
AsyncExitStacked,
|
364
367
|
ExitStacked,
|
omlish/lang/functions.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import dataclasses as dc
|
2
1
|
import functools
|
3
2
|
import time
|
4
3
|
import types
|
@@ -210,37 +209,6 @@ def periodically(
|
|
210
209
|
##
|
211
210
|
|
212
211
|
|
213
|
-
@dc.dataclass(init=False)
|
214
|
-
class Args:
|
215
|
-
args: ta.Sequence[ta.Any]
|
216
|
-
kwargs: ta.Mapping[str, ta.Any]
|
217
|
-
|
218
|
-
def __init__(self, *args: ta.Any, **kwargs: ta.Any) -> None:
|
219
|
-
super().__init__()
|
220
|
-
|
221
|
-
self.args = args
|
222
|
-
self.kwargs = kwargs
|
223
|
-
|
224
|
-
def __bool__(self) -> bool:
|
225
|
-
return bool(self.args) or bool(self.kwargs)
|
226
|
-
|
227
|
-
def update(self, *args: ta.Any, **kwargs: ta.Any) -> 'Args':
|
228
|
-
return Args(
|
229
|
-
*self.args,
|
230
|
-
*args,
|
231
|
-
**{
|
232
|
-
**self.kwargs,
|
233
|
-
**kwargs,
|
234
|
-
},
|
235
|
-
)
|
236
|
-
|
237
|
-
def __call__(self, fn: ta.Callable[..., T]) -> T:
|
238
|
-
return fn(*self.args, **self.kwargs)
|
239
|
-
|
240
|
-
|
241
|
-
##
|
242
|
-
|
243
|
-
|
244
212
|
def coalesce(*vs: T | None) -> T:
|
245
213
|
for v in vs:
|
246
214
|
if v is not None:
|
omlish/lite/args.py
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import dataclasses as dc
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
|
5
|
+
T = ta.TypeVar('T')
|
6
|
+
|
7
|
+
|
8
|
+
##
|
9
|
+
|
10
|
+
|
11
|
+
@dc.dataclass(init=False)
|
12
|
+
class Args:
|
13
|
+
args: ta.Sequence[ta.Any]
|
14
|
+
kwargs: ta.Mapping[str, ta.Any]
|
15
|
+
|
16
|
+
def __init__(self, *args: ta.Any, **kwargs: ta.Any) -> None:
|
17
|
+
super().__init__()
|
18
|
+
|
19
|
+
self.args = args
|
20
|
+
self.kwargs = kwargs
|
21
|
+
|
22
|
+
def __bool__(self) -> bool:
|
23
|
+
return bool(self.args) or bool(self.kwargs)
|
24
|
+
|
25
|
+
def update(self, *args: ta.Any, **kwargs: ta.Any) -> 'Args':
|
26
|
+
return Args(
|
27
|
+
*self.args,
|
28
|
+
*args,
|
29
|
+
**{
|
30
|
+
**self.kwargs,
|
31
|
+
**kwargs,
|
32
|
+
},
|
33
|
+
)
|
34
|
+
|
35
|
+
def __call__(self, fn: ta.Callable[..., T]) -> T:
|
36
|
+
return fn(*self.args, **self.kwargs)
|
omlish/testing/unittest/main.py
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
"""
|
3
3
|
https://docs.python.org/3/library/unittest.html#command-line-interface
|
4
4
|
~ https://github.com/python/cpython/tree/f66c75f11d3aeeb614600251fd5d3fe1a34b5ff1/Lib/unittest
|
5
|
+
|
6
|
+
TODO:
|
7
|
+
- giving it filenames doesn't work
|
5
8
|
"""
|
6
9
|
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
7
10
|
# --------------------------------------------
|
omlish/text/minja.py
CHANGED
@@ -49,10 +49,15 @@ class MinjaTemplateParam:
|
|
49
49
|
return cls(name, dfl)
|
50
50
|
|
51
51
|
|
52
|
+
class MinjaTemplateFn(ta.Protocol):
|
53
|
+
def __call__(self, **kwargs: ta.Any) -> str:
|
54
|
+
...
|
55
|
+
|
56
|
+
|
52
57
|
class MinjaTemplate:
|
53
58
|
def __init__(
|
54
59
|
self,
|
55
|
-
fn:
|
60
|
+
fn: MinjaTemplateFn,
|
56
61
|
params: ta.Sequence[MinjaTemplateParam],
|
57
62
|
) -> None:
|
58
63
|
super().__init__()
|
@@ -71,6 +76,16 @@ class MinjaTemplate:
|
|
71
76
|
##
|
72
77
|
|
73
78
|
|
79
|
+
class MinjaFunctionBuilder(ta.Protocol):
|
80
|
+
def __call__(
|
81
|
+
self,
|
82
|
+
name: str,
|
83
|
+
src: str,
|
84
|
+
ns: ta.Optional[ta.Mapping[str, ta.Any]] = None,
|
85
|
+
) -> ta.Callable:
|
86
|
+
...
|
87
|
+
|
88
|
+
|
74
89
|
class MinjaTemplateCompiler:
|
75
90
|
"""
|
76
91
|
Compiles a template string into a Python function. The returned function takes a dictionary 'context' and returns
|
@@ -96,6 +111,7 @@ class MinjaTemplateCompiler:
|
|
96
111
|
fragment_processor: ta.Optional[ta.Callable[[MinjaTemplateFragmentKind, str], str]] = None,
|
97
112
|
strict_strings: bool = False,
|
98
113
|
stringifier: ta.Optional[ta.Callable[[ta.Any], str]] = None,
|
114
|
+
function_builder: ta.Optional[MinjaFunctionBuilder] = None,
|
99
115
|
) -> None:
|
100
116
|
super().__init__()
|
101
117
|
|
@@ -120,6 +136,10 @@ class MinjaTemplateCompiler:
|
|
120
136
|
stringifier = lambda o: str(o)
|
121
137
|
self._stringifier = stringifier
|
122
138
|
|
139
|
+
if function_builder is None:
|
140
|
+
function_builder = self._build_function
|
141
|
+
self._function_builder = function_builder
|
142
|
+
|
123
143
|
self._stack: ta.List[ta.Literal['for', 'if']] = []
|
124
144
|
|
125
145
|
@staticmethod
|
@@ -128,6 +148,18 @@ class MinjaTemplateCompiler:
|
|
128
148
|
raise TypeError(o)
|
129
149
|
return o
|
130
150
|
|
151
|
+
@staticmethod
|
152
|
+
def _build_function(
|
153
|
+
name: str,
|
154
|
+
src: str,
|
155
|
+
ns: ta.Optional[ta.Mapping[str, ta.Any]] = None,
|
156
|
+
) -> ta.Callable:
|
157
|
+
glo: dict = {}
|
158
|
+
if ns:
|
159
|
+
glo.update(ns)
|
160
|
+
exec(src, glo)
|
161
|
+
return glo[name]
|
162
|
+
|
131
163
|
#
|
132
164
|
|
133
165
|
_TAG_PAT = re.compile(
|
@@ -210,11 +242,13 @@ class MinjaTemplateCompiler:
|
|
210
242
|
lines.append(f'def {self._RENDER_FN_NAME}():')
|
211
243
|
else:
|
212
244
|
lines.append(f'def {self._RENDER_FN_NAME}(')
|
245
|
+
lines.append(self._indent('*,'))
|
213
246
|
for p in self._params:
|
214
247
|
if p.default.present:
|
215
248
|
check.not_in(p.name, ns)
|
216
|
-
|
217
|
-
|
249
|
+
dn = f'__minja__default__{p.name}'
|
250
|
+
ns[dn] = p.default.must()
|
251
|
+
lines.append(self._indent(f'{p.name}={dn},'))
|
218
252
|
else:
|
219
253
|
lines.append(self._indent(f'{p.name},'))
|
220
254
|
lines.append('):')
|
@@ -269,19 +303,6 @@ class MinjaTemplateCompiler:
|
|
269
303
|
|
270
304
|
#
|
271
305
|
|
272
|
-
@classmethod
|
273
|
-
def _make_fn(
|
274
|
-
cls,
|
275
|
-
name: str,
|
276
|
-
src: str,
|
277
|
-
ns: ta.Optional[ta.Mapping[str, ta.Any]] = None,
|
278
|
-
) -> ta.Callable:
|
279
|
-
glo: dict = {}
|
280
|
-
if ns:
|
281
|
-
glo.update(ns)
|
282
|
-
exec(src, glo)
|
283
|
-
return glo[name]
|
284
|
-
|
285
306
|
def compile(
|
286
307
|
self,
|
287
308
|
ns: ta.Optional[ta.Mapping[str, ta.Any]] = None,
|
@@ -294,14 +315,14 @@ class MinjaTemplateCompiler:
|
|
294
315
|
raise KeyError(k)
|
295
316
|
ns[k] = v
|
296
317
|
|
297
|
-
render_fn = self.
|
318
|
+
render_fn = self._function_builder(
|
298
319
|
self._RENDER_FN_NAME,
|
299
320
|
rendered.src,
|
300
321
|
ns,
|
301
322
|
)
|
302
323
|
|
303
324
|
return MinjaTemplate(
|
304
|
-
render_fn,
|
325
|
+
ta.cast(MinjaTemplateFn, check.callable(render_fn)),
|
305
326
|
self._params,
|
306
327
|
)
|
307
328
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=_i_tQ9A48__MEZO6apOfvz5EyxB8GlOe28oLORkGJKk,3478
|
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
|
@@ -419,7 +419,7 @@ omlish/iterators/iterators.py,sha256=RxW35yQ5ed8vBQ22IqpDXFx-i5JiLQdp7-pkMZXhJJ8
|
|
419
419
|
omlish/iterators/recipes.py,sha256=wOwOZg-zWG9Zc3wcAxJFSe2rtavVBYwZOfG09qYEx_4,472
|
420
420
|
omlish/iterators/tools.py,sha256=M16LXrJhMdsz5ea2qH0vws30ZvhQuQSCVFSLpRf_gTg,2096
|
421
421
|
omlish/iterators/unique.py,sha256=Nw0pSaNEcHAkve0ugfLPvJcirDOn9ECyC5wIL8JlJKI,1395
|
422
|
-
omlish/lang/__init__.py,sha256=
|
422
|
+
omlish/lang/__init__.py,sha256=HBfW_xYymqMI480poCq-_7TB5ZxG3HJ7OmZ8XywJlhw,6563
|
423
423
|
omlish/lang/attrs.py,sha256=zFiVuGVOq88x45464T_LxDa-ZEq_RD9zJLq2zeVEBDc,5105
|
424
424
|
omlish/lang/casing.py,sha256=cFUlbDdXLhwnWwcYx4qnM5c4zGX7hIRUfcjiZbxUD28,4636
|
425
425
|
omlish/lang/clsdct.py,sha256=HAGIvBSbCefzRjXriwYSBLO7QHKRv2UsE78jixOb-fA,1828
|
@@ -429,7 +429,7 @@ omlish/lang/contextmanagers.py,sha256=7mbTG7yIwM2whQBuhja5Tt0C4kfefBUW4Y_AIn5j8i
|
|
429
429
|
omlish/lang/datetimes.py,sha256=01tg21QOx-PWDlm-CSFTalym3vpqF0EKzeinmtcVNoU,379
|
430
430
|
omlish/lang/descriptors.py,sha256=zBtgO9LjdSTGHNUgiIqswh78WOVoGH6KzS0NbgB1Wls,6572
|
431
431
|
omlish/lang/enums.py,sha256=F9tflHfaAoV2MpyuhZzpfX9-H55M3zNa9hCszsngEo8,111
|
432
|
-
omlish/lang/functions.py,sha256=
|
432
|
+
omlish/lang/functions.py,sha256=aLdxhmqG0Pj9tBgsKdoCu_q15r82WIkNqDDSPQU19L8,5689
|
433
433
|
omlish/lang/generators.py,sha256=a4D5HU_mySs2T2z3xCmE_s3t4QJkj0YRrK4-hhpGd0A,5197
|
434
434
|
omlish/lang/imports.py,sha256=y9W9Y-d_cQ35QCLuSIPoa6vnEqSErFCz8b-34IH128U,10552
|
435
435
|
omlish/lang/iterables.py,sha256=y1SX2Co3VsOeX2wlfFF7K3rwLvF7Dtre7VY6EpfwAwA,3338
|
@@ -463,6 +463,7 @@ omlish/lifecycles/manager.py,sha256=92s1IH_gDP25PM5tFuPMP2hD_6s5fPi_VzZiDS5549g,
|
|
463
463
|
omlish/lifecycles/states.py,sha256=6gTdY3hn7-1sJ60lA3GeMx5RVKvXtFBBXE4KEjoO1Hs,1297
|
464
464
|
omlish/lifecycles/transitions.py,sha256=3IFdWGtAeoy3XRlIyW7yCKV4e4Iof9ytkqklGMRFYQs,1944
|
465
465
|
omlish/lite/__init__.py,sha256=ISLhM4q0LR1XXTCaHdZOZxBRyIsoZqYm4u0bf1BPcVk,148
|
466
|
+
omlish/lite/args.py,sha256=_py7azSCqPJwA2P1qY0B91sSiORsvYIK7IBO6hPDYK4,739
|
466
467
|
omlish/lite/cached.py,sha256=O7ozcoDNFm1Hg2wtpHEqYSp_i_nCLNOP6Ueq_Uk-7mU,1300
|
467
468
|
omlish/lite/check.py,sha256=ytCkwZoKfOlJqylL-AGm8C2WfsWJd2q3kFbnZCzX3_M,13844
|
468
469
|
omlish/lite/configs.py,sha256=4-1uVxo-aNV7vMKa7PVNhM610eejG1WepB42-Dw2xQI,914
|
@@ -792,7 +793,7 @@ omlish/testing/pytest/plugins/switches/switches.py,sha256=lj8S9RMwUAW7a93ZqqTjoD
|
|
792
793
|
omlish/testing/unittest/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
|
793
794
|
omlish/testing/unittest/__main__.py,sha256=d23loR_cKfTYZwYiqpt_CmKI7dd5WcYFgIYzqMep75E,68
|
794
795
|
omlish/testing/unittest/loading.py,sha256=DT6vIZwXBkbEXocaxhrbWj8SqsoP7pyxD5K3bZlAE34,4764
|
795
|
-
omlish/testing/unittest/main.py,sha256=
|
796
|
+
omlish/testing/unittest/main.py,sha256=QYVLFzDlkzgyKt7P3V7wG9DoKekrOJHWYeFpI9nX2Vo,8451
|
796
797
|
omlish/testing/unittest/running.py,sha256=sifL1gjhn1VR965T9fdZy8NbJpVtpEQety8ngh5Fw7A,11821
|
797
798
|
omlish/testing/unittest/types.py,sha256=RvQwU9l2amH2mKv3W3QyPBFg0eXkQ8wWnIJeRXeDdi0,102
|
798
799
|
omlish/text/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -804,7 +805,7 @@ omlish/text/glyphsplit.py,sha256=ZX9mhwTtmUE8rJpuD1jBO1CTc6xzmBCtbfiHmp5vMM8,381
|
|
804
805
|
omlish/text/indent.py,sha256=BWVVaHs_B1ppwHJJIxKCDG3iCutkYy5e1qr59Z_Suzg,1524
|
805
806
|
omlish/text/linecache.py,sha256=hRYlEhD63ZfA6_ZOTkQIcnON-3W56QMAhcG3vEJqj9M,1858
|
806
807
|
omlish/text/mangle.py,sha256=k7mYavVgxJ2ENV2wfjw3c9u3hqH5NeVpjoxYbyaYC0Y,2796
|
807
|
-
omlish/text/minja.py,sha256=
|
808
|
+
omlish/text/minja.py,sha256=J5EqqMXovBeXrmjnYbhhbF2G-CbfRX31o2Od4-571MA,9667
|
808
809
|
omlish/text/parts.py,sha256=MpiCUyfpcL4PLb2Etj8V7Yj4qofhy0xVwBrIL6RfNdg,6646
|
809
810
|
omlish/text/random.py,sha256=8feS5JE_tSjYlMl-lp0j93kCfzBae9AM2cXlRLebXMA,199
|
810
811
|
omlish/text/templating.py,sha256=Nf5BVDgrYBf0WmYwV6SnHPDvl9XVMu8v7MX78pInLTw,3325
|
@@ -888,9 +889,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
888
889
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
889
890
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
890
891
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
891
|
-
omlish-0.0.0.
|
892
|
-
omlish-0.0.0.
|
893
|
-
omlish-0.0.0.
|
894
|
-
omlish-0.0.0.
|
895
|
-
omlish-0.0.0.
|
896
|
-
omlish-0.0.0.
|
892
|
+
omlish-0.0.0.dev374.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
893
|
+
omlish-0.0.0.dev374.dist-info/METADATA,sha256=CeT0SThiC6g7bnfBZYK1i5VyICnv96WDnWJvzSrwBdA,4416
|
894
|
+
omlish-0.0.0.dev374.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
895
|
+
omlish-0.0.0.dev374.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
896
|
+
omlish-0.0.0.dev374.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
897
|
+
omlish-0.0.0.dev374.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|