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.
- omlish/__about__.py +2 -2
- omlish/bootstrap/__init__.py +2 -2
- omlish/collections/__init__.py +135 -149
- omlish/configs/formats.py +6 -2
- omlish/diag/lsof.py +4 -3
- omlish/funcs/builders.py +2 -1
- omlish/lang/__init__.py +26 -5
- omlish/lang/imports/__init__.py +0 -0
- omlish/lang/imports/conditional.py +33 -0
- omlish/lang/imports/lazy.py +66 -0
- omlish/lang/imports/proxyinit.py +445 -0
- omlish/lang/imports/resolution.py +86 -0
- omlish/lang/imports/traversal.py +104 -0
- omlish/lang/lazyglobals.py +59 -0
- omlish/lang/resources.py +1 -1
- omlish/lite/imports.py +1 -1
- omlish/lite/reprs.py +2 -1
- omlish/manifests/base.py +2 -1
- omlish/manifests/loading.py +1 -1
- omlish/marshal/__init__.py +2 -2
- omlish/os/pidfiles/pinning.py +2 -1
- omlish/secrets/all.py +2 -2
- omlish/secrets/secrets.py +1 -1
- omlish/specs/jsonrpc/__init__.py +2 -2
- omlish/specs/jsonschema/__init__.py +2 -2
- omlish/specs/openapi/__init__.py +2 -2
- omlish/sql/api/__init__.py +2 -2
- omlish/sql/queries/__init__.py +3 -9
- omlish/sql/tabledefs/__init__.py +2 -2
- omlish/typedvalues/__init__.py +2 -2
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/RECORD +36 -30
- omlish/lang/imports.py +0 -418
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev398.dist-info → omlish-0.0.0.dev400.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/bootstrap/__init__.py
CHANGED
@@ -37,6 +37,6 @@ from .sys import ( # noqa
|
|
37
37
|
##
|
38
38
|
|
39
39
|
|
40
|
-
from ..
|
40
|
+
from .. import lang as _lang
|
41
41
|
|
42
|
-
|
42
|
+
_lang.register_conditional_import('..marshal', '.marshal', __package__)
|
omlish/collections/__init__.py
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
from .mappings import ( # noqa
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
)
|
74
|
-
|
75
|
-
from .multimaps import ( # noqa
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
)
|
93
|
-
|
94
|
-
from .ordered import ( # noqa
|
95
|
-
|
96
|
-
|
97
|
-
)
|
98
|
-
|
99
|
-
from .persistent.persistent import ( # noqa
|
100
|
-
|
101
|
-
|
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
|
-
|
119
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|