omlish 0.0.0.dev398__py3-none-any.whl → 0.0.0.dev400__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 (37) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/bootstrap/__init__.py +2 -2
  3. omlish/collections/__init__.py +135 -149
  4. omlish/configs/formats.py +6 -2
  5. omlish/diag/lsof.py +4 -3
  6. omlish/funcs/builders.py +2 -1
  7. omlish/lang/__init__.py +26 -5
  8. omlish/lang/imports/__init__.py +0 -0
  9. omlish/lang/imports/conditional.py +33 -0
  10. omlish/lang/imports/lazy.py +66 -0
  11. omlish/lang/imports/proxyinit.py +445 -0
  12. omlish/lang/imports/resolution.py +86 -0
  13. omlish/lang/imports/traversal.py +104 -0
  14. omlish/lang/lazyglobals.py +59 -0
  15. omlish/lang/resources.py +1 -1
  16. omlish/lite/imports.py +1 -1
  17. omlish/lite/reprs.py +2 -1
  18. omlish/manifests/base.py +2 -1
  19. omlish/manifests/loading.py +1 -1
  20. omlish/marshal/__init__.py +2 -2
  21. omlish/os/pidfiles/pinning.py +2 -1
  22. omlish/secrets/all.py +2 -2
  23. omlish/secrets/secrets.py +1 -1
  24. omlish/specs/jsonrpc/__init__.py +2 -2
  25. omlish/specs/jsonschema/__init__.py +2 -2
  26. omlish/specs/openapi/__init__.py +2 -2
  27. omlish/sql/api/__init__.py +2 -2
  28. omlish/sql/queries/__init__.py +3 -9
  29. omlish/sql/tabledefs/__init__.py +2 -2
  30. omlish/typedvalues/__init__.py +2 -2
  31. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/METADATA +1 -1
  32. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/RECORD +36 -30
  33. omlish/lang/imports.py +0 -418
  34. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/WHEEL +0 -0
  35. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/entry_points.txt +0 -0
  36. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/licenses/LICENSE +0 -0
  37. {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/top_level.txt +0 -0
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev398'
2
- __revision__ = '36ad9ea49db19a697cb584dc80f1fac002db95f3'
1
+ __version__ = '0.0.0.dev400'
2
+ __revision__ = '4e9cb702d1d048bb8211070b471983d3b4d7bb6d'
3
3
 
4
4
 
5
5
  #
@@ -37,6 +37,6 @@ from .sys import ( # noqa
37
37
  ##
38
38
 
39
39
 
40
- from ..lang.imports import _register_conditional_import # noqa
40
+ from .. import lang as _lang
41
41
 
42
- _register_conditional_import('..marshal', '.marshal', __package__)
42
+ _lang.register_conditional_import('..marshal', '.marshal', __package__)
@@ -1,165 +1,151 @@
1
1
  # ruff: noqa: I001
2
- import typing as _ta
3
-
4
2
  from .. import lang as _lang
5
3
 
6
4
 
7
- from .bimap import ( # noqa
8
- BiMap,
9
-
10
- make_bi_map,
11
- )
12
-
13
- from .coerce import ( # noqa
14
- abs_set,
15
- abs_set_of,
16
- abs_set_of_or_none,
17
- abs_set_or_none,
18
- frozenset_,
19
- frozenset_of,
20
- frozenset_of_or_none,
21
- frozenset_or_none,
22
- map, # noqa
23
- map_of,
24
- map_of_or_none,
25
- map_or_none,
26
- opt_abs_set,
27
- opt_abs_set_of,
28
- opt_frozenset,
29
- opt_frozenset_of,
30
- opt_map,
31
- opt_map_of,
32
- opt_seq,
33
- opt_seq_of,
34
- seq,
35
- seq_of,
36
- seq_of_or_none,
37
- seq_or_none,
38
- )
39
-
40
- from .frozen import ( # noqa
41
- Frozen,
42
- FrozenDict,
43
- FrozenList,
44
- frozendict,
45
- frozenlist,
46
- )
47
-
48
- from .hasheq import ( # noqa
49
- HashEq,
50
- HashEqMap,
51
- HashEq_,
52
- hash_eq,
53
- )
54
-
55
- from .identity import ( # noqa
56
- IdentityKeyDict,
57
- IdentitySet,
58
- IdentityWeakKeyDictionary,
59
- IdentityWeakSet,
60
- )
61
-
62
- if _ta.TYPE_CHECKING:
63
- from . import kv
64
- else:
65
- kv = _lang.proxy_import('.kv', __package__)
66
-
67
- from .mappings import ( # noqa
68
- MissingDict,
69
- TypeMap,
70
- DynamicTypeMap,
71
- guarded_map_update,
72
- multikey_dict,
73
- )
74
-
75
- from .multimaps import ( # noqa
76
- MultiMap,
77
-
78
- SequenceMultiMap,
79
- AbstractSetMultiMap,
80
-
81
- BiMultiMap,
82
- InverseBiMultiMap,
83
-
84
- SequenceBiMultiMap,
85
- AbstractSetBiMultiMap,
86
-
87
- TupleBiMultiMap,
88
- seq_bi_multi_map,
89
-
90
- FrozensetBiMultiMap,
91
- abs_set_bi_multi_map,
92
- )
93
-
94
- from .ordered import ( # noqa
95
- OrderedFrozenSet,
96
- OrderedSet,
97
- )
98
-
99
- from .persistent.persistent import ( # noqa
100
- PersistentMap,
101
- PersistentMapping,
102
- )
103
-
104
- if _ta.TYPE_CHECKING:
5
+ with _lang.auto_proxy_init(globals()):
6
+ ##
7
+
8
+ from .bimap import ( # noqa
9
+ BiMap,
10
+
11
+ make_bi_map,
12
+ )
13
+
14
+ from .coerce import ( # noqa
15
+ abs_set,
16
+ abs_set_of,
17
+ abs_set_of_or_none,
18
+ abs_set_or_none,
19
+ frozenset_,
20
+ frozenset_of,
21
+ frozenset_of_or_none,
22
+ frozenset_or_none,
23
+ map, # noqa
24
+ map_of,
25
+ map_of_or_none,
26
+ map_or_none,
27
+ opt_abs_set,
28
+ opt_abs_set_of,
29
+ opt_frozenset,
30
+ opt_frozenset_of,
31
+ opt_map,
32
+ opt_map_of,
33
+ opt_seq,
34
+ opt_seq_of,
35
+ seq,
36
+ seq_of,
37
+ seq_of_or_none,
38
+ seq_or_none,
39
+ )
40
+
41
+ from .frozen import ( # noqa
42
+ Frozen,
43
+ FrozenDict,
44
+ FrozenList,
45
+ frozendict,
46
+ frozenlist,
47
+ )
48
+
49
+ from .hasheq import ( # noqa
50
+ HashEq,
51
+ HashEqMap,
52
+ HashEq_,
53
+ hash_eq,
54
+ )
55
+
56
+ from .identity import ( # noqa
57
+ IdentityKeyDict,
58
+ IdentitySet,
59
+ IdentityWeakKeyDictionary,
60
+ IdentityWeakSet,
61
+ )
62
+
63
+ from . import kv # noqa
64
+
65
+ from .mappings import ( # noqa
66
+ MissingDict,
67
+ TypeMap,
68
+ DynamicTypeMap,
69
+ guarded_map_update,
70
+ multikey_dict,
71
+ )
72
+
73
+ from .multimaps import ( # noqa
74
+ MultiMap,
75
+
76
+ SequenceMultiMap,
77
+ AbstractSetMultiMap,
78
+
79
+ BiMultiMap,
80
+ InverseBiMultiMap,
81
+
82
+ SequenceBiMultiMap,
83
+ AbstractSetBiMultiMap,
84
+
85
+ TupleBiMultiMap,
86
+ seq_bi_multi_map,
87
+
88
+ FrozensetBiMultiMap,
89
+ abs_set_bi_multi_map,
90
+ )
91
+
92
+ from .ordered import ( # noqa
93
+ OrderedFrozenSet,
94
+ OrderedSet,
95
+ )
96
+
97
+ from .persistent.persistent import ( # noqa
98
+ PersistentMap,
99
+ PersistentMapping,
100
+ )
101
+
105
102
  from .persistent.treapmap import ( # noqa
106
103
  TreapDict,
107
104
  TreapMap,
108
105
  new_treap_dict,
109
106
  new_treap_map,
110
107
  )
111
- else:
112
- _lang.proxy_init(globals(), '.persistent.treapmap', [
113
- 'TreapMap',
114
- 'new_treap_map',
115
- ])
116
108
 
117
- from .ranked import ( # noqa
118
- RankedSeq,
119
- RankedSetSeq,
120
- )
109
+ from .ranked import ( # noqa
110
+ RankedSeq,
111
+ RankedSetSeq,
112
+ )
121
113
 
122
- if _ta.TYPE_CHECKING:
123
114
  from .sorted.skiplist import ( # noqa
124
115
  SkipList,
125
116
  SkipListDict,
126
117
  )
127
- else:
128
- _lang.proxy_init(globals(), '.sorted.skiplist', [
129
- 'SkipList',
130
- 'SkipListDict',
131
- ])
132
-
133
- from .sorted.sorted import ( # noqa
134
- SortedCollection,
135
- SortedItems,
136
- SortedIter,
137
- SortedListDict,
138
- SortedMapping,
139
- SortedMutableMapping,
140
- )
141
-
142
- from .trie import ( # noqa
143
- Trie,
144
- )
145
-
146
- from .unmodifiable import ( # noqa
147
- Unmodifiable,
148
- UnmodifiableMapping,
149
- UnmodifiableSequence,
150
- UnmodifiableSet,
151
- )
152
-
153
- from .utils import ( # noqa
154
- PartitionResult,
155
- all_equal,
156
- all_not_equal,
157
- indexes,
158
- key_cmp,
159
- make_map,
160
- make_map_by,
161
- multi_map,
162
- multi_map_by,
163
- partition,
164
- unique,
165
- )
118
+
119
+ from .sorted.sorted import ( # noqa
120
+ SortedCollection,
121
+ SortedItems,
122
+ SortedIter,
123
+ SortedListDict,
124
+ SortedMapping,
125
+ SortedMutableMapping,
126
+ )
127
+
128
+ from .trie import ( # noqa
129
+ Trie,
130
+ )
131
+
132
+ from .unmodifiable import ( # noqa
133
+ Unmodifiable,
134
+ UnmodifiableMapping,
135
+ UnmodifiableSequence,
136
+ UnmodifiableSet,
137
+ )
138
+
139
+ from .utils import ( # noqa
140
+ PartitionResult,
141
+ all_equal,
142
+ all_not_equal,
143
+ indexes,
144
+ key_cmp,
145
+ make_map,
146
+ make_map_by,
147
+ multi_map,
148
+ multi_map_by,
149
+ partition,
150
+ unique,
151
+ )
omlish/configs/formats.py CHANGED
@@ -150,14 +150,18 @@ class YamlConfigLoader(ConfigLoader[YamlConfigData]):
150
150
  file_exts = ('yaml', 'yml')
151
151
 
152
152
  def load_str(self, s: str) -> YamlConfigData:
153
- return YamlConfigData(__import__('yaml').safe_load(s))
153
+ import yaml # noqa
154
+
155
+ return YamlConfigData(yaml.safe_load(s))
154
156
 
155
157
 
156
158
  class YamlConfigRenderer(ConfigRenderer[YamlConfigData]):
157
159
  data_cls = YamlConfigData
158
160
 
159
161
  def render(self, d: YamlConfigData) -> str:
160
- return __import__('yaml').safe_dump(d.obj)
162
+ import yaml # noqa
163
+
164
+ return yaml.safe_dump(d.obj)
161
165
 
162
166
 
163
167
  ##
omlish/diag/lsof.py CHANGED
@@ -243,20 +243,21 @@ class LsofCommand(SubprocessRunnable[ta.List[LsofItem]]):
243
243
 
244
244
  if __name__ == '__main__':
245
245
  def _main() -> None:
246
- argparse = __import__('argparse')
246
+ import argparse # noqa
247
+ import importlib # noqa
248
+ import json # noqa
249
+
247
250
  parser = argparse.ArgumentParser()
248
251
  parser.add_argument('--pid', '-p', type=int)
249
252
  parser.add_argument('file', nargs='?')
250
253
  args = parser.parse_args()
251
254
 
252
- importlib = __import__('importlib')
253
255
  subprocesses = importlib.import_module('..subprocesses.sync', package=__package__).subprocesses
254
256
  items = LsofCommand(
255
257
  pid=args.pid,
256
258
  file=args.file,
257
259
  ).run(subprocesses)
258
260
 
259
- json = __import__('json')
260
261
  marshal_obj = importlib.import_module('..lite.marshal', package=__package__).marshal_obj
261
262
  print(json.dumps(marshal_obj(items), indent=2))
262
263
 
omlish/funcs/builders.py CHANGED
@@ -70,7 +70,8 @@ class DebugFnBuilder(FnBuilder):
70
70
  if self._given_src_dir is not None:
71
71
  return self._given_src_dir
72
72
  else:
73
- return __import__('tempfile').mkdtemp(prefix=f'_{self.__class__.__name__}_{os.getpid()}__') # noqa
73
+ import tempfile # noqa
74
+ return tempfile.mkdtemp(prefix=f'_{self.__class__.__name__}_{os.getpid()}__') # noqa
74
75
 
75
76
  @cached_nullary
76
77
  def _install_sys_path(self) -> None:
omlish/lang/__init__.py CHANGED
@@ -219,16 +219,33 @@ from .generators import ( # noqa
219
219
  nextgen,
220
220
  )
221
221
 
222
- from .imports import ( # noqa
223
- LazyGlobals,
224
- can_import,
225
- get_real_module_name,
226
- import_all,
222
+ from .imports.conditional import ( # noqa
223
+ register_conditional_import,
224
+ trigger_conditional_imports,
225
+ )
226
+
227
+ from .imports.lazy import ( # noqa
227
228
  lazy_import,
228
229
  proxy_import,
230
+ )
231
+
232
+ from .imports.proxyinit import ( # noqa
229
233
  proxy_init,
234
+
235
+ AutoProxyInitError,
236
+ AutoProxyInitErrors,
237
+ auto_proxy_init,
238
+ )
239
+
240
+ from .imports.resolution import ( # noqa
241
+ can_import,
242
+ get_real_module_name,
230
243
  resolve_import_name,
231
244
  try_import,
245
+ )
246
+
247
+ from .imports.traversal import ( # noqa
248
+ import_all,
232
249
  yield_import_all,
233
250
  yield_importable,
234
251
  )
@@ -251,6 +268,10 @@ from .iterables import ( # noqa
251
268
  take,
252
269
  )
253
270
 
271
+ from .lazyglobals import ( # noqa
272
+ LazyGlobals,
273
+ )
274
+
254
275
  from .maysyncs import ( # noqa
255
276
  MaysyncP,
256
277
 
File without changes
@@ -0,0 +1,33 @@
1
+ import sys
2
+
3
+ from .resolution import resolve_import_name
4
+
5
+
6
+ ##
7
+
8
+
9
+ # dict[str, None] to preserve insertion order - we don't have OrderedSet here
10
+ _REGISTERED_CONDITIONAL_IMPORTS: dict[str, dict[str, None] | None] = {}
11
+
12
+
13
+ def register_conditional_import(when: str, then: str, package: str | None = None) -> None:
14
+ wn = resolve_import_name(when, package)
15
+ tn = resolve_import_name(then, package)
16
+ if tn in sys.modules:
17
+ return
18
+ if wn in sys.modules:
19
+ __import__(tn)
20
+ else:
21
+ tns = _REGISTERED_CONDITIONAL_IMPORTS.setdefault(wn, {})
22
+ if tns is None:
23
+ raise Exception(f'Conditional import trigger already cleared: {wn=} {tn=}')
24
+ tns[tn] = None
25
+
26
+
27
+ def trigger_conditional_imports(package: str) -> None:
28
+ tns = _REGISTERED_CONDITIONAL_IMPORTS.get(package, {})
29
+ if tns is None:
30
+ raise Exception(f'Conditional import trigger already cleared: {package=}')
31
+ _REGISTERED_CONDITIONAL_IMPORTS[package] = None
32
+ for tn in tns:
33
+ __import__(tn)
@@ -0,0 +1,66 @@
1
+ import importlib.util
2
+ import types
3
+ import typing as ta
4
+
5
+
6
+ ##
7
+
8
+
9
+ def lazy_import(
10
+ name: str,
11
+ package: str | None = None,
12
+ *,
13
+ optional: bool = False,
14
+ cache_failure: bool = False,
15
+ ) -> ta.Callable[[], ta.Any]:
16
+ result = not_set = object()
17
+
18
+ def inner():
19
+ nonlocal result
20
+
21
+ if result is not not_set:
22
+ if isinstance(result, Exception):
23
+ raise result
24
+ return result
25
+
26
+ try:
27
+ mod = importlib.import_module(name, package=package)
28
+
29
+ except Exception as e:
30
+ if optional:
31
+ if cache_failure:
32
+ result = None
33
+ return None
34
+
35
+ if cache_failure:
36
+ result = e
37
+ raise
38
+
39
+ result = mod
40
+ return mod
41
+
42
+ return inner
43
+
44
+
45
+ def proxy_import(
46
+ name: str,
47
+ package: str | None = None,
48
+ extras: ta.Iterable[str] | None = None,
49
+ ) -> types.ModuleType:
50
+ if isinstance(extras, str):
51
+ raise TypeError(extras)
52
+
53
+ omod = None
54
+
55
+ def __getattr__(att): # noqa
56
+ nonlocal omod
57
+ if omod is None:
58
+ omod = importlib.import_module(name, package=package)
59
+ if extras:
60
+ for x in extras:
61
+ importlib.import_module(f'{name}.{x}', package=package)
62
+ return getattr(omod, att)
63
+
64
+ lmod = types.ModuleType(name)
65
+ lmod.__getattr__ = __getattr__ # type: ignore
66
+ return lmod