omlish 0.0.0.dev443__py3-none-any.whl → 0.0.0.dev445__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.

Potentially problematic release.


This version of omlish might be problematic. Click here for more details.

omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev443'
2
- __revision__ = '0dc6d8e2932a032b4a2cec65c010432d79c2b721'
1
+ __version__ = '0.0.0.dev445'
2
+ __revision__ = '68ca679313e2d1b22ba7545fe7f27bb938535ac3'
3
3
 
4
4
 
5
5
  #
@@ -174,6 +174,7 @@ class SetuptoolsBase:
174
174
  '*.cu',
175
175
  '*.g4',
176
176
  '*.h',
177
+ '*.hh',
177
178
 
178
179
  '.omlish-manifests.json',
179
180
 
@@ -184,6 +185,8 @@ class SetuptoolsBase:
184
185
 
185
186
 
186
187
  class Setuptools(SetuptoolsBase):
188
+ cexts = True
189
+
187
190
  find_packages = {
188
191
  'include': [Project.name, f'{Project.name}.*'],
189
192
  'exclude': [*SetuptoolsBase.find_packages['exclude']],
@@ -17,8 +17,10 @@ from ....funcs.genmachine import GenMachine
17
17
  from .errors import JsonStreamError
18
18
 
19
19
 
20
- with lang.auto_proxy_import(globals()):
20
+ if ta.TYPE_CHECKING:
21
21
  import unicodedata
22
+ else:
23
+ unicodedata = lang.proxy_import('unicodedata')
22
24
 
23
25
 
24
26
  ##
@@ -190,7 +192,9 @@ class JsonStreamLexer(GenMachine[str, Token]):
190
192
 
191
193
  self._allow_extended_idents = allow_extended_idents
192
194
 
193
- self._char_in_it: ta.Iterator[str] | None = None
195
+ self._char_in_str: str | None = None
196
+ self._char_in_str_len: int = 0
197
+ self._char_in_str_pos: int = 0
194
198
 
195
199
  self._ofs = 0
196
200
  self._line = 1
@@ -223,29 +227,29 @@ class JsonStreamLexer(GenMachine[str, Token]):
223
227
  return c
224
228
 
225
229
  def _yield_char_in(self, c: str) -> str:
226
- if self._char_in_it is not None:
230
+ if self._char_in_str is not None:
227
231
  raise JsonStreamError
228
232
 
229
- if len(c) > 1:
230
- in_it = iter(c)
231
- next(in_it)
232
- self._char_in_it = in_it
233
+ if (cl := len(c)) > 1:
234
+ self._char_in_str = c
235
+ self._char_in_str_len = cl
236
+ self._char_in_str_pos = 1
233
237
  c = c[0]
234
238
 
235
239
  self._advance_pos(c)
236
240
 
237
241
  return c
238
242
 
239
- def _it_char_in(self) -> str | None:
240
- if (it := self._char_in_it) is None:
243
+ def _str_char_in(self) -> str | None:
244
+ if (s := self._char_in_str) is None:
241
245
  return None
242
246
 
243
- try:
244
- c = next(it)
245
- except StopIteration:
246
- self._char_in_it = None
247
+ if (p := self._char_in_str_pos) >= self._char_in_str_len:
248
+ self._char_in_str = None
247
249
  return None
248
250
 
251
+ c = s[p]
252
+ self._char_in_str_pos += 1
249
253
  return self._advance_pos(c)
250
254
 
251
255
  def _make_tok(
@@ -278,7 +282,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
278
282
  c = peek
279
283
  peek = None
280
284
  else:
281
- if (c := self._it_char_in()) is None: # type: ignore[assignment]
285
+ if (c := self._str_char_in()) is None: # type: ignore[assignment]
282
286
  c = self._yield_char_in((yield None)) # noqa
283
287
 
284
288
  if not c:
@@ -320,13 +324,17 @@ class JsonStreamLexer(GenMachine[str, Token]):
320
324
 
321
325
  buf = self._buf
322
326
 
323
- char_in_it = self._char_in_it
327
+ char_in_str = self._char_in_str
328
+ char_in_str_len = self._char_in_str_len
329
+ char_in_str_pos = self._char_in_str_pos
324
330
  ofs = self._ofs
325
331
  line = self._line
326
332
  col = self._col
327
333
 
328
334
  def restore_state():
329
- self._char_in_it = char_in_it
335
+ self._char_in_str = char_in_str
336
+ self._char_in_str_len = char_in_str_len
337
+ self._char_in_str_pos = char_in_str_pos
330
338
  self._ofs = ofs
331
339
  self._line = line
332
340
  self._col = col
@@ -335,11 +343,17 @@ class JsonStreamLexer(GenMachine[str, Token]):
335
343
  while True:
336
344
  c: str | None = None
337
345
 
338
- if char_in_it is not None:
339
- try:
340
- c = next(char_in_it)
341
- except StopIteration:
342
- char_in_it = None
346
+ if char_in_str is not None:
347
+ if char_in_str_pos < char_in_str_len:
348
+ # FIXME: handle str chunks separately
349
+ # if (qp := char_in_str.find(q)) >= 0 and (not qp or (char_in_str[qp - 1] != '\\')):
350
+ # ofs += qp + 1
351
+ # line += char_in_str.count('\n', end=)
352
+ # if (np := char_in_str.rfind('\n')) >= 0
353
+ c = char_in_str[char_in_str_pos]
354
+ char_in_str_pos += 1
355
+ else:
356
+ char_in_str = None
343
357
 
344
358
  if c is None:
345
359
  try:
@@ -349,9 +363,9 @@ class JsonStreamLexer(GenMachine[str, Token]):
349
363
  self._raise('Unexpected end of input')
350
364
 
351
365
  if len(c) > 1:
352
- in_it = iter(c)
353
- next(in_it)
354
- char_in_it = in_it
366
+ char_in_str = c
367
+ char_in_str_len = len(char_in_str)
368
+ char_in_str_pos = 1
355
369
  c = c[0]
356
370
 
357
371
  if c and len(c) != 1:
@@ -396,7 +410,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
396
410
 
397
411
  while True:
398
412
  try:
399
- if (c := self._it_char_in()) is None: # type: ignore[assignment]
413
+ if (c := self._str_char_in()) is None: # type: ignore[assignment]
400
414
  c = self._yield_char_in((yield None)) # noqa
401
415
  except GeneratorExit:
402
416
  self._raise('Unexpected end of input')
@@ -431,7 +445,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
431
445
  raw += c
432
446
  try:
433
447
  for _ in range(len(svs) - 1):
434
- if (c := self._it_char_in()) is None: # type: ignore[assignment]
448
+ if (c := self._str_char_in()) is None: # type: ignore[assignment]
435
449
  c = self._yield_char_in((yield None)) # noqa
436
450
  if not c:
437
451
  break
@@ -479,7 +493,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
479
493
  raw = c
480
494
  while True:
481
495
  try:
482
- if (c := self._it_char_in()) is None: # type: ignore[assignment]
496
+ if (c := self._str_char_in()) is None: # type: ignore[assignment]
483
497
  c = self._yield_char_in((yield None)) # noqa
484
498
  except GeneratorExit:
485
499
  self._raise('Unexpected end of input')
@@ -498,7 +512,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
498
512
 
499
513
  def _do_unicode_escape(self):
500
514
  try:
501
- if (c := self._it_char_in()) is None:
515
+ if (c := self._str_char_in()) is None:
502
516
  c = self._yield_char_in((yield None)) # noqa
503
517
  except GeneratorExit:
504
518
  self._raise('Unexpected end of input')
@@ -509,7 +523,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
509
523
  ux = []
510
524
  for _ in range(4):
511
525
  try:
512
- if (c := self._it_char_in()) is None:
526
+ if (c := self._str_char_in()) is None:
513
527
  c = self._yield_char_in((yield None)) # noqa
514
528
  except GeneratorExit:
515
529
  self._raise('Unexpected end of input')
@@ -536,7 +550,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
536
550
 
537
551
  while True:
538
552
  try:
539
- if (c := self._it_char_in()) is None: # type: ignore[assignment]
553
+ if (c := self._str_char_in()) is None: # type: ignore[assignment]
540
554
  c = self._yield_char_in((yield None)) # noqa
541
555
  except GeneratorExit:
542
556
  self._raise('Unexpected end of input')
@@ -567,7 +581,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
567
581
 
568
582
  pos = self.pos
569
583
  try:
570
- if (oc := self._it_char_in()) is None:
584
+ if (oc := self._str_char_in()) is None:
571
585
  oc = self._yield_char_in((yield None)) # noqa
572
586
  except GeneratorExit:
573
587
  self._raise('Unexpected end of input')
@@ -575,7 +589,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
575
589
  if oc == '/':
576
590
  while True:
577
591
  try:
578
- if (ic := self._it_char_in()) is None:
592
+ if (ic := self._str_char_in()) is None:
579
593
  ic = self._yield_char_in((yield None)) # noqa
580
594
  except GeneratorExit:
581
595
  self._raise('Unexpected end of input')
@@ -598,7 +612,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
598
612
  lc: str | None = None
599
613
  while True:
600
614
  try:
601
- if (ic := self._it_char_in()) is None:
615
+ if (ic := self._str_char_in()) is None:
602
616
  ic = self._yield_char_in((yield None)) # noqa
603
617
  except GeneratorExit:
604
618
  self._raise('Unexpected end of input')
omlish/inject/binder.py CHANGED
@@ -32,8 +32,10 @@ from .types import Scope
32
32
  from .types import Unscoped
33
33
 
34
34
 
35
- with lang.auto_proxy_import(globals()):
35
+ if ta.TYPE_CHECKING:
36
36
  from .impl import inspect as _inspect
37
+ else:
38
+ _inspect = lang.proxy_import('.impl.inspect', __package__)
37
39
 
38
40
 
39
41
  T = ta.TypeVar('T')
@@ -51,8 +51,10 @@ from .providers2 import make_provider_impl
51
51
  from .scopes import make_scope_impl
52
52
 
53
53
 
54
- with lang.auto_proxy_import(globals()):
54
+ if ta.TYPE_CHECKING:
55
55
  from . import privates as _privates
56
+ else:
57
+ _privates = lang.proxy_import('.privates', __package__)
56
58
 
57
59
 
58
60
  ElementT = ta.TypeVar('ElementT', bound=Element)
@@ -31,8 +31,10 @@ from .bindings import BindingImpl
31
31
  from .providers import ProviderImpl
32
32
 
33
33
 
34
- with lang.auto_proxy_import(globals()):
34
+ if ta.TYPE_CHECKING:
35
35
  from . import injector as _injector
36
+ else:
37
+ _injector = lang.proxy_import('.injector', __package__)
36
38
 
37
39
 
38
40
  ##
omlish/inject/injector.py CHANGED
@@ -8,8 +8,10 @@ from .inspect import KwargsTarget
8
8
  from .keys import Key
9
9
 
10
10
 
11
- with lang.auto_proxy_import(globals()):
11
+ if ta.TYPE_CHECKING:
12
12
  from .impl import injector as _injector
13
+ else:
14
+ _injector = lang.proxy_import('.impl.injector', __package__)
13
15
 
14
16
 
15
17
  T = ta.TypeVar('T')
omlish/inject/inspect.py CHANGED
@@ -4,8 +4,10 @@ from .. import lang
4
4
  from .keys import Key
5
5
 
6
6
 
7
- with lang.auto_proxy_import(globals()):
7
+ if ta.TYPE_CHECKING:
8
8
  from .impl import inspect as _inspect
9
+ else:
10
+ _inspect = lang.proxy_import('.impl.inspect', __package__)
9
11
 
10
12
 
11
13
  T = ta.TypeVar('T')
omlish/inject/managed.py CHANGED
@@ -11,10 +11,14 @@ from .elements import Elemental
11
11
  from .impl.inspect import build_kwargs_target
12
12
 
13
13
 
14
- with lang.auto_proxy_import(globals()):
14
+ if ta.TYPE_CHECKING:
15
15
  from . import injector as _injector
16
16
  from . import maysync as _maysync
17
17
  from . import sync as _sync
18
+ else:
19
+ _injector = lang.proxy_import('.injector', __package__)
20
+ _maysync = lang.proxy_import('.maysync', __package__)
21
+ _sync = lang.proxy_import('.sync', __package__)
18
22
 
19
23
 
20
24
  T = ta.TypeVar('T')
omlish/inject/maysync.py CHANGED
@@ -6,8 +6,10 @@ from .elements import as_elements
6
6
  from .sync import Injector
7
7
 
8
8
 
9
- with lang.auto_proxy_import(globals()):
9
+ if ta.TYPE_CHECKING:
10
10
  from .impl import maysync as _maysync
11
+ else:
12
+ _maysync = lang.proxy_import('.impl.maysync', __package__)
11
13
 
12
14
 
13
15
  T = ta.TypeVar('T')
omlish/inject/scopes.py CHANGED
@@ -14,10 +14,14 @@ from .providers import Provider
14
14
  from .types import Scope
15
15
 
16
16
 
17
- with lang.auto_proxy_import(globals()):
17
+ if ta.TYPE_CHECKING:
18
18
  from . import injector as _injector
19
19
  from . import maysync as _maysync
20
20
  from . import sync as _sync
21
+ else:
22
+ _injector = lang.proxy_import('.injector', __package__)
23
+ _maysync = lang.proxy_import('.maysync', __package__)
24
+ _sync = lang.proxy_import('.sync', __package__)
21
25
 
22
26
 
23
27
  ##
@@ -112,7 +116,7 @@ def maysync_enter_seeded_scope(
112
116
  ss: SeededScope,
113
117
  keys: ta.Mapping[Key, ta.Any],
114
118
  ) -> ta.ContextManager[None]:
115
- return lang.sync_await_context_manager(async_enter_seeded_scope(
119
+ return lang.sync_async_with(async_enter_seeded_scope(
116
120
  i[AsyncInjector],
117
121
  ss,
118
122
  keys,
omlish/inject/sync.py CHANGED
@@ -8,8 +8,10 @@ from .inspect import KwargsTarget
8
8
  from .keys import Key
9
9
 
10
10
 
11
- with lang.auto_proxy_import(globals()):
11
+ if ta.TYPE_CHECKING:
12
12
  from .impl import sync as _sync
13
+ else:
14
+ _sync = lang.proxy_import('.impl.sync', __package__)
13
15
 
14
16
 
15
17
  T = ta.TypeVar('T')
omlish/lang/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .imports.proxyinit import auto_proxy_init as _auto_proxy_init
1
+ from .imports.proxy import auto_proxy_init as _auto_proxy_init
2
2
 
3
3
 
4
4
  with _auto_proxy_init(globals(), update_exports=True):
@@ -274,13 +274,9 @@ with _auto_proxy_init(globals(), update_exports=True):
274
274
 
275
275
  from .imports.proxy import ( # noqa
276
276
  proxy_import,
277
-
278
277
  auto_proxy_import,
279
- )
280
278
 
281
- from .imports.proxyinit import ( # noqa
282
279
  proxy_init,
283
-
284
280
  auto_proxy_init,
285
281
  )
286
282
 
@@ -466,7 +462,7 @@ with _auto_proxy_init(globals(), update_exports=True):
466
462
  sync_async_list,
467
463
 
468
464
  SyncAwaitContextManager,
469
- sync_await_context_manager,
465
+ sync_async_with,
470
466
 
471
467
  SyncToAsyncContextManager,
472
468
  as_async_context_manager,
@@ -0,0 +1,101 @@
1
+ // @omlish-cext
2
+ #include <atomic>
3
+
4
+ #define PY_SSIZE_T_CLEAN
5
+ #define Py_BUILD_CORE 1
6
+ #include "Python.h"
7
+ #include "internal/pycore_frame.h"
8
+ #undef Py_BUILD_CORE
9
+
10
+ #if PY_VERSION_HEX < 0x030D0000
11
+ # error "This extension requires CPython 3.13+"
12
+ #endif
13
+
14
+ //
15
+
16
+ #define _MODULE_NAME "_capture"
17
+ #define _PACKAGE_NAME "omlish.lang.imports"
18
+ #define _MODULE_FULL_NAME _PACKAGE_NAME "." _MODULE_NAME
19
+
20
+ //
21
+
22
+ static PyObject *
23
+ _set_frame_builtins(PyObject *self, PyObject *args)
24
+ {
25
+ PyObject *frame_obj;
26
+ PyObject *old_builtins;
27
+ PyObject *new_builtins;
28
+
29
+ if (!PyArg_ParseTuple(
30
+ args, "OO!O!",
31
+ &frame_obj,
32
+ &PyDict_Type, &old_builtins,
33
+ &PyDict_Type, &new_builtins
34
+ )) {
35
+ return NULL;
36
+ }
37
+
38
+ if (!PyFrame_Check(frame_obj)) {
39
+ PyErr_SetString(PyExc_TypeError, "first argument must be a frame object");
40
+ return NULL;
41
+ }
42
+
43
+ PyFrameObject *frame = (PyFrameObject *)frame_obj;
44
+ _PyInterpreterFrame *iframe = frame->f_frame;
45
+
46
+ if (!iframe) {
47
+ PyErr_SetString(PyExc_ValueError, "frame has no underlying interpreter frame");
48
+ return NULL;
49
+ }
50
+
51
+ std::atomic_ref<PyObject*> builtins_ref(iframe->f_builtins);
52
+ PyObject* expected = old_builtins;
53
+ bool success = builtins_ref.compare_exchange_strong(
54
+ expected,
55
+ new_builtins,
56
+ std::memory_order_acq_rel,
57
+ std::memory_order_acquire
58
+ );
59
+
60
+ if (success) {
61
+ Py_RETURN_TRUE;
62
+ } else {
63
+ Py_RETURN_FALSE;
64
+ }
65
+ }
66
+
67
+ //
68
+
69
+ PyDoc_STRVAR(capture_doc, _MODULE_NAME);
70
+
71
+ static PyMethodDef capture_methods[] = {
72
+ {"_set_frame_builtins", _set_frame_builtins, METH_VARARGS, "_set_frame_builtins"},
73
+ {NULL, NULL, 0, NULL}
74
+ };
75
+
76
+ static struct PyModuleDef_Slot capture_slots[] = {
77
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
78
+ {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED},
79
+ {0, NULL}
80
+ };
81
+
82
+ static struct PyModuleDef capture_module = {
83
+ .m_base = PyModuleDef_HEAD_INIT,
84
+ .m_name = _MODULE_NAME,
85
+ .m_doc = capture_doc,
86
+ .m_size = 0,
87
+ .m_methods = capture_methods,
88
+ .m_slots = capture_slots,
89
+ .m_traverse = NULL,
90
+ .m_clear = NULL,
91
+ .m_free = NULL,
92
+ };
93
+
94
+ extern "C" {
95
+
96
+ PyMODINIT_FUNC PyInit__capture(void)
97
+ {
98
+ return PyModuleDef_Init(&capture_module);
99
+ }
100
+
101
+ }