omlish 0.0.0.dev416__py3-none-any.whl → 0.0.0.dev418__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.
Files changed (44) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/bootstrap/__init__.py +2 -2
  3. omlish/dataclasses/__init__.py +23 -13
  4. omlish/dataclasses/impl/configs.py +1 -1
  5. omlish/dataclasses/impl/processing/base.py +1 -1
  6. omlish/inject/__init__.py +12 -0
  7. omlish/marshal/__init__.py +229 -202
  8. omlish/marshal/base/configs.py +18 -0
  9. omlish/marshal/base/contexts.py +8 -7
  10. omlish/marshal/base/funcs.py +57 -0
  11. omlish/marshal/base/overrides.py +11 -6
  12. omlish/marshal/base/registries.py +58 -14
  13. omlish/marshal/base/types.py +4 -26
  14. omlish/marshal/factories/invalidate.py +118 -0
  15. omlish/marshal/factories/moduleimport/__init__.py +0 -0
  16. omlish/marshal/factories/moduleimport/configs.py +26 -0
  17. omlish/marshal/factories/moduleimport/factories.py +114 -0
  18. omlish/marshal/factories/typecache.py +24 -4
  19. omlish/marshal/globals.py +28 -13
  20. omlish/marshal/objects/dataclasses.py +29 -4
  21. omlish/marshal/polymorphism/metadata.py +2 -2
  22. omlish/marshal/standard.py +132 -65
  23. omlish/secrets/all.py +0 -9
  24. omlish/secrets/secrets.py +4 -6
  25. omlish/specs/jsonrpc/__init__.py +2 -2
  26. omlish/specs/jsonschema/__init__.py +2 -2
  27. omlish/specs/openapi/__init__.py +2 -2
  28. omlish/sql/queries/__init__.py +4 -2
  29. omlish/sql/tabledefs/__init__.py +2 -2
  30. omlish/text/templating.py +9 -7
  31. omlish/typedvalues/__init__.py +41 -34
  32. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/METADATA +1 -1
  33. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/RECORD +43 -38
  34. omlish/marshal/factories/func.py +0 -28
  35. /omlish/bootstrap/{marshal.py → _marshal.py} +0 -0
  36. /omlish/specs/jsonrpc/{marshal.py → _marshal.py} +0 -0
  37. /omlish/specs/jsonschema/{marshal.py → _marshal.py} +0 -0
  38. /omlish/specs/openapi/{marshal.py → _marshal.py} +0 -0
  39. /omlish/sql/queries/{marshal.py → _marshal.py} +0 -0
  40. /omlish/sql/tabledefs/{marshal.py → _marshal.py} +0 -0
  41. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/WHEEL +0 -0
  42. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/entry_points.txt +0 -0
  43. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/licenses/LICENSE +0 -0
  44. {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/top_level.txt +0 -0
@@ -2,7 +2,7 @@ import dataclasses as dc
2
2
  import typing as ta
3
3
 
4
4
  from ... import lang
5
- from ..base.registries import RegistryItem
5
+ from ..base.configs import Config
6
6
  from ..naming import Naming
7
7
  from ..naming import translate_name
8
8
 
@@ -10,7 +10,7 @@ from ..naming import translate_name
10
10
  ##
11
11
 
12
12
 
13
- class TypeTagging(RegistryItem, lang.Abstract, lang.Sealed):
13
+ class TypeTagging(Config, lang.Abstract, lang.Sealed):
14
14
  pass
15
15
 
16
16
 
@@ -1,3 +1,9 @@
1
+ """
2
+ FIXME:
3
+ - this is gross and temporary
4
+ - move to global registry somehow
5
+ """
6
+ import threading
1
7
  import typing as ta
2
8
 
3
9
  from .base.types import MarshalerFactory
@@ -16,6 +22,10 @@ from .composite.optionals import OptionalMarshalerFactory
16
22
  from .composite.optionals import OptionalUnmarshalerFactory
17
23
  from .composite.special import SequenceNotStrMarshalerFactory
18
24
  from .composite.special import SequenceNotStrUnmarshalerFactory
25
+ from .factories.invalidate import InvalidatableMarshalerFactory
26
+ from .factories.invalidate import InvalidatableUnmarshalerFactory
27
+ from .factories.moduleimport.factories import ModuleImportingMarshalerFactory
28
+ from .factories.moduleimport.factories import ModuleImportingUnmarshalerFactory
19
29
  from .factories.multi import MultiMarshalerFactory
20
30
  from .factories.multi import MultiUnmarshalerFactory
21
31
  from .factories.recursive import RecursiveMarshalerFactory
@@ -45,24 +55,53 @@ from .trivial.any import ANY_UNMARSHALER_FACTORY
45
55
  ##
46
56
 
47
57
 
48
- STANDARD_MARSHALER_FACTORIES: list[MarshalerFactory] = [
49
- PRIMITIVE_MARSHALER_FACTORY,
50
- NewtypeMarshalerFactory(),
51
- OptionalMarshalerFactory(),
52
- PrimitiveUnionMarshalerFactory(),
53
- DataclassMarshalerFactory(),
54
- NamedtupleMarshalerFactory(),
55
- EnumMarshalerFactory(),
56
- LiteralMarshalerFactory(),
57
- NUMBERS_MARSHALER_FACTORY,
58
- UUID_MARSHALER_FACTORY,
59
- DATETIME_MARSHALER_FACTORY,
60
- MaybeMarshalerFactory(),
61
- MappingMarshalerFactory(),
62
- SequenceNotStrMarshalerFactory(),
63
- IterableMarshalerFactory(),
64
- ANY_MARSHALER_FACTORY,
65
- ]
58
+ class StandardFactories(ta.NamedTuple):
59
+ marshaler_factories: ta.Sequence[MarshalerFactory]
60
+ unmarshaler_factories: ta.Sequence[UnmarshalerFactory]
61
+
62
+
63
+ DEFAULT_STANDARD_FACTORIES = StandardFactories(
64
+ (
65
+ PRIMITIVE_MARSHALER_FACTORY,
66
+ NewtypeMarshalerFactory(),
67
+ OptionalMarshalerFactory(),
68
+ PrimitiveUnionMarshalerFactory(),
69
+ DataclassMarshalerFactory(),
70
+ NamedtupleMarshalerFactory(),
71
+ EnumMarshalerFactory(),
72
+ LiteralMarshalerFactory(),
73
+ NUMBERS_MARSHALER_FACTORY,
74
+ UUID_MARSHALER_FACTORY,
75
+ DATETIME_MARSHALER_FACTORY,
76
+ MaybeMarshalerFactory(),
77
+ MappingMarshalerFactory(),
78
+ SequenceNotStrMarshalerFactory(),
79
+ IterableMarshalerFactory(),
80
+ ANY_MARSHALER_FACTORY,
81
+ ),
82
+
83
+ (
84
+ PRIMITIVE_UNMARSHALER_FACTORY,
85
+ NewtypeUnmarshalerFactory(),
86
+ OptionalUnmarshalerFactory(),
87
+ PrimitiveUnionUnmarshalerFactory(),
88
+ DataclassUnmarshalerFactory(),
89
+ NamedtupleUnmarshalerFactory(),
90
+ EnumUnmarshalerFactory(),
91
+ LiteralUnmarshalerFactory(),
92
+ NUMBERS_UNMARSHALER_FACTORY,
93
+ UUID_UNMARSHALER_FACTORY,
94
+ DATETIME_UNMARSHALER_FACTORY,
95
+ MaybeUnmarshalerFactory(),
96
+ MappingUnmarshalerFactory(),
97
+ SequenceNotStrUnmarshalerFactory(),
98
+ IterableUnmarshalerFactory(),
99
+ ANY_UNMARSHALER_FACTORY,
100
+ ),
101
+ )
102
+
103
+
104
+ ##
66
105
 
67
106
 
68
107
  def new_standard_marshaler_factory(
@@ -70,38 +109,32 @@ def new_standard_marshaler_factory(
70
109
  first: ta.Iterable[MarshalerFactory] | None = None,
71
110
  last: ta.Iterable[MarshalerFactory] | None = None,
72
111
  ) -> MarshalerFactory:
73
- return TypeCacheMarshalerFactory(
74
- RecursiveMarshalerFactory(
75
- MultiMarshalerFactory([
76
- *(first if first is not None else []),
77
- *STANDARD_MARSHALER_FACTORIES,
78
- *(last if last is not None else []),
79
- ]),
80
- ),
81
- )
112
+ gl: ta.Any = None
82
113
 
114
+ def fi_fn():
115
+ nonlocal gl
116
+ gl = DEFAULT_STANDARD_FACTORIES
83
117
 
84
- ##
118
+ fi: MarshalerFactory = MultiMarshalerFactory([
119
+ *(first if first is not None else []),
120
+ *gl.marshaler_factories,
121
+ *(last if last is not None else []),
122
+ ])
123
+
124
+ fi = RecursiveMarshalerFactory(fi)
125
+
126
+ fi = TypeCacheMarshalerFactory(fi)
85
127
 
128
+ return fi
86
129
 
87
- STANDARD_UNMARSHALER_FACTORIES: list[UnmarshalerFactory] = [
88
- PRIMITIVE_UNMARSHALER_FACTORY,
89
- NewtypeUnmarshalerFactory(),
90
- OptionalUnmarshalerFactory(),
91
- PrimitiveUnionUnmarshalerFactory(),
92
- DataclassUnmarshalerFactory(),
93
- NamedtupleUnmarshalerFactory(),
94
- EnumUnmarshalerFactory(),
95
- LiteralUnmarshalerFactory(),
96
- NUMBERS_UNMARSHALER_FACTORY,
97
- UUID_UNMARSHALER_FACTORY,
98
- DATETIME_UNMARSHALER_FACTORY,
99
- MaybeUnmarshalerFactory(),
100
- MappingUnmarshalerFactory(),
101
- SequenceNotStrUnmarshalerFactory(),
102
- IterableUnmarshalerFactory(),
103
- ANY_UNMARSHALER_FACTORY,
104
- ]
130
+ fo: MarshalerFactory = (iv := InvalidatableMarshalerFactory(
131
+ fi_fn,
132
+ lambda: DEFAULT_STANDARD_FACTORIES is not gl,
133
+ ))
134
+
135
+ fo = ModuleImportingMarshalerFactory(fo, iv.invalidate)
136
+
137
+ return fo
105
138
 
106
139
 
107
140
  def new_standard_unmarshaler_factory(
@@ -109,33 +142,67 @@ def new_standard_unmarshaler_factory(
109
142
  first: ta.Iterable[UnmarshalerFactory] | None = None,
110
143
  last: ta.Iterable[UnmarshalerFactory] | None = None,
111
144
  ) -> UnmarshalerFactory:
112
- return TypeCacheUnmarshalerFactory(
113
- RecursiveUnmarshalerFactory(
114
- MultiUnmarshalerFactory([
115
- *(first if first is not None else []),
116
- *STANDARD_UNMARSHALER_FACTORIES,
117
- *(last if last is not None else []),
118
- ]),
119
- ),
120
- )
145
+ gl: ta.Any = None
146
+
147
+ def fi_fn():
148
+ nonlocal gl
149
+ gl = DEFAULT_STANDARD_FACTORIES
150
+
151
+ fi: UnmarshalerFactory = MultiUnmarshalerFactory([
152
+ *(first if first is not None else []),
153
+ *gl.unmarshaler_factories,
154
+ *(last if last is not None else []),
155
+ ])
156
+
157
+ fi = RecursiveUnmarshalerFactory(fi)
158
+
159
+ fi = TypeCacheUnmarshalerFactory(fi)
160
+
161
+ return fi
162
+
163
+ fo: UnmarshalerFactory = (iv := InvalidatableUnmarshalerFactory(
164
+ fi_fn,
165
+ lambda: DEFAULT_STANDARD_FACTORIES is not gl,
166
+ ))
167
+
168
+ fo = ModuleImportingUnmarshalerFactory(fo, iv.invalidate)
169
+
170
+ return fo
121
171
 
122
172
 
123
173
  ##
124
174
 
125
175
 
176
+ _GLOBAL_LOCK = threading.RLock()
177
+
178
+
126
179
  def install_standard_factories(
127
180
  *factories: MarshalerFactory | UnmarshalerFactory,
128
181
  ) -> None:
129
- for f in factories:
130
- k = False
182
+ with _GLOBAL_LOCK:
183
+ global DEFAULT_STANDARD_FACTORIES
184
+
185
+ m_lst: list[MarshalerFactory] = list(DEFAULT_STANDARD_FACTORIES.marshaler_factories)
186
+ u_lst: list[UnmarshalerFactory] = list(DEFAULT_STANDARD_FACTORIES.unmarshaler_factories)
187
+
188
+ for f in factories:
189
+ k = False
190
+
191
+ if isinstance(f, MarshalerFactory):
192
+ m_lst[0:0] = [f]
193
+ k = True
194
+
195
+ if isinstance(f, UnmarshalerFactory):
196
+ u_lst[0:0] = [f]
197
+ k = True
131
198
 
132
- if isinstance(f, MarshalerFactory):
133
- STANDARD_MARSHALER_FACTORIES[0:0] = [f]
134
- k = True
199
+ if not k:
200
+ raise TypeError(f)
135
201
 
136
- if isinstance(f, UnmarshalerFactory):
137
- STANDARD_UNMARSHALER_FACTORIES[0:0] = [f]
138
- k = True
202
+ new = StandardFactories(
203
+ tuple(m_lst),
204
+ tuple(u_lst),
205
+ )
139
206
 
140
- if not k:
141
- raise TypeError(f)
207
+ if new != DEFAULT_STANDARD_FACTORIES:
208
+ DEFAULT_STANDARD_FACTORIES = new
omlish/secrets/all.py CHANGED
@@ -16,12 +16,3 @@ from .secrets import ( # noqa
16
16
  )
17
17
 
18
18
  ref = SecretRef
19
-
20
-
21
- ##
22
-
23
-
24
- from .. import lang as _lang # noqa
25
-
26
- # FIXME: only happens when 'all' is imported lol
27
- _lang.register_conditional_import('..marshal', '.marshal', __package__)
omlish/secrets/secrets.py CHANGED
@@ -20,6 +20,10 @@ import typing as ta
20
20
 
21
21
  from .. import dataclasses as dc
22
22
  from .. import lang
23
+ from .. import marshal as msh
24
+
25
+
26
+ msh.register_global_module_import('.marshal', __package__)
23
27
 
24
28
 
25
29
  log = logging.getLogger(__name__)
@@ -341,9 +345,3 @@ class EnvVarSecrets(Secrets):
341
345
  return dct.pop(ekey)
342
346
  else:
343
347
  return dct[ekey]
344
-
345
-
346
- ##
347
-
348
-
349
- lang.register_conditional_import('..marshal', '.marshal', __package__)
@@ -36,6 +36,6 @@ from .types import ( # noqa
36
36
  ##
37
37
 
38
38
 
39
- from ... import lang as _lang
39
+ from ... import marshal as _msh
40
40
 
41
- _lang.register_conditional_import('...marshal', '.marshal', __package__)
41
+ _msh.register_global_module_import('._marshal', __package__)
@@ -69,6 +69,6 @@ from .types import ( # noqa
69
69
  ##
70
70
 
71
71
 
72
- from ... import lang as _lang
72
+ from ... import marshal as _msh
73
73
 
74
- _lang.register_conditional_import('...marshal', '.marshal', __package__)
74
+ _msh.register_global_module_import('._marshal', __package__)
@@ -6,6 +6,6 @@ from .openapi import ( # noqa
6
6
  ##
7
7
 
8
8
 
9
- from ... import lang as _lang
9
+ from ... import marshal as _msh
10
10
 
11
- _lang.register_conditional_import('...marshal', '.marshal', __package__)
11
+ _msh.register_global_module_import('._marshal', __package__)
@@ -112,8 +112,10 @@ Q = StdBuilder()
112
112
  ##
113
113
 
114
114
 
115
- from ... import lang as _lang # noqa
115
+ from ... import marshal as _msh # noqa
116
+
117
+ _msh.register_global_module_import('._marshal', __package__)
116
118
 
117
- _lang.register_conditional_import('...marshal', '.marshal', __package__)
119
+ from ... import lang as _lang # noqa
118
120
 
119
121
  _lang.trigger_conditional_imports(__package__)
@@ -6,6 +6,6 @@ from .tabledefs import ( # noqa
6
6
  ##
7
7
 
8
8
 
9
- from ... import lang as _lang
9
+ from ... import marshal as _msh
10
10
 
11
- _lang.register_conditional_import('...marshal', '.marshal', __package__)
11
+ _msh.register_global_module_import('._marshal', __package__)
omlish/text/templating.py CHANGED
@@ -9,16 +9,18 @@ import string
9
9
  import typing as ta
10
10
 
11
11
  from .. import lang
12
- from .minja import MinjaTemplate
13
- from .minja import MinjaTemplateParam
14
- from .minja import compile_minja_template
15
12
 
16
13
 
17
14
  if ta.TYPE_CHECKING:
18
15
  import jinja2
16
+
17
+ from . import minja
18
+
19
19
  else:
20
20
  jinja2 = lang.proxy_import('jinja2')
21
21
 
22
+ minja = lang.proxy_import('.minja', __package__)
23
+
22
24
 
23
25
  ##
24
26
 
@@ -97,7 +99,7 @@ pep292_templater = Pep292Templater.from_string
97
99
 
98
100
  @dc.dataclass(frozen=True)
99
101
  class MinjaTemplater(Templater):
100
- tmpl: MinjaTemplate
102
+ tmpl: 'minja.MinjaTemplate'
101
103
 
102
104
  ENV_IDENT: ta.ClassVar[str] = 'env'
103
105
 
@@ -110,12 +112,12 @@ class MinjaTemplater(Templater):
110
112
  src: str,
111
113
  **ns: ta.Any,
112
114
  ) -> 'MinjaTemplater':
113
- tmpl = compile_minja_template(
115
+ tmpl = minja.compile_minja_template(
114
116
  src,
115
117
  [
116
- MinjaTemplateParam(cls.ENV_IDENT),
118
+ minja.MinjaTemplateParam(cls.ENV_IDENT),
117
119
  *[
118
- MinjaTemplateParam.new(k, v)
120
+ minja.MinjaTemplateParam.new(k, v)
119
121
  for k, v in ns.items()
120
122
  ],
121
123
  ],
@@ -1,54 +1,61 @@
1
- from .accessor import ( # noqa
2
- TypedValuesAccessor,
3
- )
1
+ from .. import lang as _lang
2
+
3
+
4
+ with _lang.auto_proxy_init(globals()) as _api_cap:
5
+ ##
4
6
 
5
- from .collection import ( # noqa
6
- DuplicateUniqueTypedValueError,
7
+ from .accessor import ( # noqa
8
+ TypedValuesAccessor,
9
+ )
7
10
 
8
- TypedValues,
11
+ from .collection import ( # noqa
12
+ DuplicateUniqueTypedValueError,
9
13
 
10
- collect,
11
- as_collection,
12
- )
14
+ TypedValues,
13
15
 
14
- from .consumer import ( # noqa
15
- UnconsumedTypedValuesError,
16
+ collect,
17
+ as_collection,
18
+ )
16
19
 
17
- TypedValuesConsumer,
20
+ from .consumer import ( # noqa
21
+ UnconsumedTypedValuesError,
18
22
 
19
- consume,
20
- )
23
+ TypedValuesConsumer,
21
24
 
22
- from .generic import ( # noqa
23
- TypedValueGeneric,
24
- )
25
+ consume,
26
+ )
25
27
 
26
- from .holder import ( # noqa
27
- TypedValueHolder,
28
- )
28
+ from .generic import ( # noqa
29
+ TypedValueGeneric,
30
+ )
29
31
 
30
- from .of_ import ( # noqa
31
- of,
32
- )
32
+ from .holder import ( # noqa
33
+ TypedValueHolder,
34
+ )
33
35
 
34
- from .reflect import ( # noqa
35
- reflect_typed_values_impls,
36
- )
36
+ from .of_ import ( # noqa
37
+ of,
38
+ )
37
39
 
38
- from .values import ( # noqa
39
- TypedValue,
40
+ from .reflect import ( # noqa
41
+ reflect_typed_values_impls,
42
+ )
40
43
 
41
- UniqueTypedValue,
44
+ from .values import ( # noqa
45
+ TypedValue,
42
46
 
43
- ScalarTypedValue,
47
+ UniqueTypedValue,
44
48
 
45
- UniqueScalarTypedValue,
46
- )
49
+ ScalarTypedValue,
50
+
51
+ UniqueScalarTypedValue,
52
+ )
47
53
 
48
54
 
49
55
  ##
50
56
 
51
57
 
52
- from .. import lang as _lang
58
+ from .. import marshal as _msh
59
+
53
60
 
54
- _lang.register_conditional_import('..marshal', '.marshal', __package__)
61
+ _msh.register_global_module_import('.marshal', __package__)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omlish
3
- Version: 0.0.0.dev416
3
+ Version: 0.0.0.dev418
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause