omdev 0.0.0.dev404__py3-none-any.whl → 0.0.0.dev406__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.
omdev/cli/main.py CHANGED
@@ -6,7 +6,6 @@ TODO:
6
6
  """
7
7
  import argparse
8
8
  import dataclasses as dc
9
- import os
10
9
  import runpy
11
10
  import sys
12
11
  import typing as ta
@@ -62,20 +61,20 @@ class CliCmdSet:
62
61
  def _make_entry(self, cmd: CliCmd) -> Entry:
63
62
  help_path: StrTuple | None
64
63
 
65
- if isinstance(cmd.cmd_name, str):
66
- ns = [cmd.cmd_name]
64
+ if isinstance(cmd.name, str):
65
+ ns = [cmd.name]
67
66
  else:
68
- ns = list(cmd.cmd_name)
67
+ ns = list(cmd.name)
69
68
  exec_paths = [tuple(n.split('/')) for n in ns]
70
69
 
71
- if isinstance(cmd.cmd_name, str) and cmd.cmd_name[0] == '_':
70
+ if isinstance(cmd.name, str) and cmd.name[0] == '_':
72
71
  help_path = None
73
72
 
74
73
  elif isinstance(cmd, CliFunc):
75
74
  help_path = ('-', *exec_paths[0])
76
75
 
77
76
  elif isinstance(cmd, CliModule):
78
- help_path = (cmd.mod_name.partition('.')[0], *exec_paths[0])
77
+ help_path = (cmd.module.partition('.')[0], *exec_paths[0])
79
78
 
80
79
  else:
81
80
  raise TypeError(cmd)
@@ -129,10 +128,10 @@ class CliCmdSet:
129
128
  if h in c:
130
129
  raise NameError(e)
131
130
 
132
- if isinstance(e.cmd.cmd_name, str):
133
- l = [e.cmd.cmd_name]
131
+ if isinstance(e.cmd.name, str):
132
+ l = [e.cmd.name]
134
133
  else:
135
- l = list(e.cmd.cmd_name)
134
+ l = list(e.cmd.name)
136
135
 
137
136
  s = (
138
137
  f'{l[0].split("/")[-1]}'
@@ -184,26 +183,24 @@ def _build_arg_parser() -> argparse.ArgumentParser:
184
183
 
185
184
 
186
185
  def _build_cmd_set(args: ta.Any) -> CliCmdSet:
187
- ldr = ManifestLoader(
188
- **ManifestLoader.kwargs_from_entry_point(
189
- globals(),
190
- **GlobalManifestLoader.default_kwargs(),
191
- ),
192
- )
186
+ ldr_cfg = GlobalManifestLoader.default_config()
193
187
 
194
- #
188
+ ldr_cfg |= ManifestLoader.config_from_entry_point(globals())
189
+
190
+ if args.cli_pkg_root:
191
+ ldr_cfg |= ManifestLoader.Config(
192
+ package_scan_root_dirs=args.cli_pkg_root,
193
+ discover_packages=False,
194
+ )
195
195
 
196
- pkgs = ldr.scan_or_discover_packages(
197
- specified_root_dirs=args.cli_pkg_root,
198
- fallback_root_dir=os.getcwd(),
199
- )
196
+ GlobalManifestLoader.initialize(ldr_cfg)
200
197
 
201
198
  #
202
199
 
203
200
  lst: list[CliCmd] = []
204
201
 
205
- for m in ldr.load(*pkgs, only=[CliModule]):
206
- lst.append(check.isinstance(m.value(), CliModule))
202
+ for mv in GlobalManifestLoader.load_values_of(CliModule):
203
+ lst.append(check.isinstance(mv, CliModule))
207
204
 
208
205
  lst.extend(_CLI_FUNCS)
209
206
 
@@ -259,7 +256,7 @@ def _main() -> ta.Any:
259
256
  cmd = sel.cmd
260
257
  if isinstance(cmd, CliModule):
261
258
  sys.argv = [args.cmd, *(sel.args or ())]
262
- runpy._run_module_as_main(cmd.mod_name) # type: ignore # noqa
259
+ runpy._run_module_as_main(cmd.module) # type: ignore # noqa
263
260
  return 0
264
261
 
265
262
  elif isinstance(cmd, CliFunc):
omdev/cli/types.py CHANGED
@@ -9,19 +9,19 @@ import typing as ta
9
9
 
10
10
  @dc.dataclass(frozen=True)
11
11
  class CliCmd:
12
- cmd_name: ta.Union[str, ta.Sequence[str]]
12
+ name: ta.Union[str, ta.Sequence[str]]
13
13
 
14
14
  @property
15
15
  def primary_name(self) -> str:
16
- if isinstance(self.cmd_name, str):
17
- return self.cmd_name
16
+ if isinstance(self.name, str):
17
+ return self.name
18
18
  else:
19
- return self.cmd_name[0]
19
+ return self.name[0]
20
20
 
21
21
 
22
22
  @dc.dataclass(frozen=True)
23
23
  class CliModule(CliCmd):
24
- mod_name: str
24
+ module: str
25
25
 
26
26
 
27
27
  @dc.dataclass(frozen=True)
@@ -1515,13 +1515,13 @@ class _ModuleManifestDumper:
1515
1515
  manifest_dct = self._build_manifest_dct(manifest)
1516
1516
 
1517
1517
  cls = type(manifest)
1518
- key = f'${cls.__module__}.{cls.__qualname__}'
1518
+ key = f'!{cls.__module__}.{cls.__qualname__}'
1519
1519
 
1520
1520
  return {key: manifest_dct}
1521
1521
 
1522
1522
  elif isinstance(manifest, collections.abc.Mapping):
1523
1523
  [(key, manifest_dct)] = manifest.items()
1524
- if not key.startswith('$'): # noqa
1524
+ if not key.startswith('!'): # noqa
1525
1525
  raise Exception(f'Bad key: {key}')
1526
1526
 
1527
1527
  if not isinstance(manifest_dct, collections.abc.Mapping):
@@ -1571,7 +1571,7 @@ class _ModuleManifestDumper:
1571
1571
 
1572
1572
  manifest_dct = self._build_manifest_dct(manifest)
1573
1573
 
1574
- key = f'${cls.__module__}.{cls.__qualname__}'
1574
+ key = f'!{cls.__module__}.{cls.__qualname__}'
1575
1575
  return {key: manifest_dct}
1576
1576
 
1577
1577
  #
@@ -172,6 +172,9 @@ class ManifestBuilder:
172
172
  def prepare(s: str) -> ta.Any:
173
173
  if s.startswith('$.'):
174
174
  s = f'{fm.mod_base}.{s[2:]}'
175
+ elif s.startswith('.'):
176
+ # s = f'{fm.mod_base}.{s[2:]}'
177
+ raise NotImplementedError
175
178
  return magic.py_compile_magic_preparer(s)
176
179
 
177
180
  magics = magic.find_magic(
@@ -189,6 +192,9 @@ class ManifestBuilder:
189
192
  body = m.body
190
193
  if body.startswith('$.'):
191
194
  body = f'{fm.mod_base}.{body[2:]}'
195
+ elif body.startswith('.'):
196
+ # body = f'{fm.mod_base}.{body[2:]}'
197
+ raise NotImplementedError
192
198
 
193
199
  pat_match = check.not_none(_INLINE_MANIFEST_CLS_NAME_PAT.match(body))
194
200
  cls_name = check.non_empty_str(pat_match.groupdict()['cls_name'])
@@ -214,8 +220,8 @@ class ManifestBuilder:
214
220
  if issubclass(cls, ModAttrManifest):
215
221
  attr_name = extract_manifest_target_name(lines, m.end_line)
216
222
  inl_kw.update({
217
- 'mod_name': fm.mod_name,
218
- 'attr_name': attr_name,
223
+ 'module': fm.mod_name,
224
+ 'attr': attr_name,
219
225
  })
220
226
 
221
227
  origin = ManifestOrigin(
@@ -328,14 +334,14 @@ class ManifestBuilder:
328
334
  if not (
329
335
  isinstance(value, ta.Mapping) and
330
336
  len(value) == 1 and
331
- all(isinstance(k, str) and k.startswith('$') and len(k) > 1 for k in value)
337
+ all(isinstance(k, str) and k.startswith('!') and len(k) > 1 for k in value)
332
338
  ):
333
- raise TypeError(f'Manifest values must be mappings of strings starting with $: {value!r}')
339
+ raise TypeError(f'Manifest values must be mappings of strings starting with !: {value!r}')
334
340
 
335
341
  [(key, value_dct)] = value.items()
336
342
  kb, _, kr = key[1:].partition('.') # noqa
337
343
  if kb == fm.mod_base: # noqa
338
- key = f'$.{kr}'
344
+ key = f'!.{kr}'
339
345
  value = {key: value_dct}
340
346
 
341
347
  out.append(Manifest(**{
@@ -429,7 +435,7 @@ def check_package_manifests(
429
435
  for entry in manifests_json:
430
436
  manifest = Manifest(**entry)
431
437
  [(key, value_dct)] = manifest.value.items()
432
- if key.startswith('$.'):
433
- key = f'${name}{key[1:]}'
438
+ if key.startswith('!.'):
439
+ key = f'!{name}{key[1:]}'
434
440
  cls = GlobalManifestLoader.instance()._load_class(key) # noqa
435
441
  value = GlobalManifestLoader.instance()._instantiate_value(cls, **value_dct) # noqa
@@ -67,13 +67,13 @@ class _ModuleManifestDumper:
67
67
  manifest_dct = self._build_manifest_dct(manifest)
68
68
 
69
69
  cls = type(manifest)
70
- key = f'${cls.__module__}.{cls.__qualname__}'
70
+ key = f'!{cls.__module__}.{cls.__qualname__}'
71
71
 
72
72
  return {key: manifest_dct}
73
73
 
74
74
  elif isinstance(manifest, collections.abc.Mapping):
75
75
  [(key, manifest_dct)] = manifest.items()
76
- if not key.startswith('$'): # noqa
76
+ if not key.startswith('!'): # noqa
77
77
  raise Exception(f'Bad key: {key}')
78
78
 
79
79
  if not isinstance(manifest_dct, collections.abc.Mapping):
@@ -123,7 +123,7 @@ class _ModuleManifestDumper:
123
123
 
124
124
  manifest_dct = self._build_manifest_dct(manifest)
125
125
 
126
- key = f'${cls.__module__}.{cls.__qualname__}'
126
+ key = f'!{cls.__module__}.{cls.__qualname__}'
127
127
  return {key: manifest_dct}
128
128
 
129
129
  #
@@ -23,6 +23,6 @@ class ManifestsPrecheck(Precheck['ManifestsPrecheck.Config']):
23
23
  async def run(self) -> ta.AsyncGenerator[Precheck.Violation]:
24
24
  for src_root in sorted(self._context.src_roots):
25
25
  try:
26
- GlobalManifestLoader.load(src_root)
26
+ GlobalManifestLoader.load(packages=[src_root])
27
27
  except Exception as e: # noqa
28
28
  yield Precheck.Violation(self, f'Error loading manifest for {src_root}: {e!r}')
omdev/py/attrdocs.py CHANGED
@@ -158,9 +158,9 @@ def extract_attr_docs(src: str) -> ta.Mapping[str, AttrDoc]:
158
158
 
159
159
 
160
160
  # @omlish-manifest
161
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
162
- 'cmd_name': 'py/attrdocs',
163
- 'mod_name': __name__,
161
+ _CLI_MODULE = {'!.cli.types.CliModule': {
162
+ 'name': 'py/attrdocs',
163
+ 'module': __name__,
164
164
  }}
165
165
 
166
166
 
omdev/py/bracepy.py CHANGED
@@ -92,9 +92,9 @@ def translate_brace_python(
92
92
 
93
93
 
94
94
  # @omlish-manifest
95
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
96
- 'cmd_name': 'bracepy',
97
- 'mod_name': __name__,
95
+ _CLI_MODULE = {'!.cli.types.CliModule': {
96
+ 'name': 'bracepy',
97
+ 'module': __name__,
98
98
  }}
99
99
 
100
100
 
omdev/py/classdot.py CHANGED
@@ -61,9 +61,9 @@ def _main() -> None:
61
61
 
62
62
 
63
63
  # @omlish-manifest
64
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
65
- 'cmd_name': 'py/classdot',
66
- 'mod_name': __name__,
64
+ _CLI_MODULE = {'!.cli.types.CliModule': {
65
+ 'name': 'py/classdot',
66
+ 'module': __name__,
67
67
  }}
68
68
 
69
69
 
omdev/py/findimports.py CHANGED
@@ -134,9 +134,9 @@ class ImportFinder:
134
134
 
135
135
 
136
136
  # @omlish-manifest
137
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
138
- 'cmd_name': 'py/findimports',
139
- 'mod_name': __name__,
137
+ _CLI_MODULE = {'!.cli.types.CliModule': {
138
+ 'name': 'py/findimports',
139
+ 'module': __name__,
140
140
  }}
141
141
 
142
142
 
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env python3
2
+ # ruff: noqa: UP045
3
+ # @omlish-lite
2
4
  # @omlish-script
3
5
  import argparse
4
6
  import inspect
@@ -8,6 +10,7 @@ import statistics
8
10
  import subprocess
9
11
  import sys
10
12
  import tempfile
13
+ import typing as ta
11
14
 
12
15
 
13
16
  ##
@@ -16,7 +19,7 @@ import tempfile
16
19
  def _run(
17
20
  src: str,
18
21
  *,
19
- setup: str | None = None,
22
+ setup: 'ta.Optional[str]' = None,
20
23
  time: bool = False,
21
24
  rss: bool = False,
22
25
  modules: bool = False,
@@ -33,8 +36,8 @@ def _run(
33
36
  if modules:
34
37
  import sys # noqa
35
38
 
36
- def get_modules() -> set[str]:
37
- return set(sys.modules)
39
+ def get_modules() -> 'ta.Sequence[str]':
40
+ return list(sys.modules)
38
41
 
39
42
  #
40
43
 
@@ -51,7 +54,7 @@ def _run(
51
54
  start_rss = get_rss() # noqa
52
55
 
53
56
  if modules:
54
- start_modules = get_modules() # noqa
57
+ start_modules = set(get_modules()) # noqa
55
58
 
56
59
  if time:
57
60
  start_time = get_time() # noqa
@@ -76,7 +79,7 @@ def _run(
76
79
  return {
77
80
  **({'time': (end_time - start_time)} if time else {}), # noqa
78
81
  **({'rss': (end_rss - start_rss)} if rss else {}), # noqa
79
- **({'modules': sorted(end_modules - start_modules)} if modules else {}), # noqa
82
+ **({'modules': [m for m in end_modules if m not in start_modules]} if modules else {}), # noqa
80
83
  }
81
84
 
82
85
 
@@ -84,9 +87,9 @@ def _run(
84
87
 
85
88
 
86
89
  # @omlish-manifest
87
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
88
- 'cmd_name': 'py/execstat',
89
- 'mod_name': __name__,
90
+ _CLI_MODULE = {'!.cli.types.CliModule': {
91
+ 'name': 'py/execstat',
92
+ 'module': __name__,
90
93
  }}
91
94
 
92
95
 
@@ -99,6 +102,7 @@ def _main() -> None:
99
102
  parser.add_argument('-t', '--time', action='store_true')
100
103
  parser.add_argument('-r', '--rss', action='store_true')
101
104
  parser.add_argument('-m', '--modules', action='store_true')
105
+ parser.add_argument('-M', '--modules-ordered', action='store_true')
102
106
 
103
107
  parser.add_argument('-n', '--num-runs', type=int, default=1)
104
108
 
@@ -136,7 +140,7 @@ def _main() -> None:
136
140
  if i == 0:
137
141
  run_kw.update(
138
142
  rss=bool(args.rss),
139
- modules=bool(args.modules),
143
+ modules=bool(args.modules) or bool(args.modules_ordered),
140
144
  )
141
145
 
142
146
  payload = '\n'.join([
@@ -183,7 +187,11 @@ def _main() -> None:
183
187
 
184
188
  if args.modules:
185
189
  out.update({
186
- 'modules': results[0]['modules'],
190
+ 'modules': sorted(results[0]['modules']),
191
+ })
192
+ if args.modules_ordered:
193
+ out.update({
194
+ 'modules_ordered': results[0]['modules'],
187
195
  })
188
196
 
189
197
  print(json.dumps(out, indent=2))
@@ -489,9 +489,9 @@ class SqliteWriter:
489
489
 
490
490
 
491
491
  # @omlish-manifest
492
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
493
- 'cmd_name': 'py/importtrace',
494
- 'mod_name': __name__,
492
+ _CLI_MODULE = {'!.cli.types.CliModule': {
493
+ 'name': 'py/importtrace',
494
+ 'module': __name__,
495
495
  }}
496
496
 
497
497
 
omdev/py/srcheaders.py CHANGED
@@ -63,9 +63,9 @@ def get_py_header_lines(src: str) -> list[PyHeaderLine]:
63
63
 
64
64
 
65
65
  # @omlish-manifest
66
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
67
- 'cmd_name': 'py/srcheaders',
68
- 'mod_name': __name__,
66
+ _CLI_MODULE = {'!.cli.types.CliModule': {
67
+ 'name': 'py/srcheaders',
68
+ 'module': __name__,
69
69
  }}
70
70
 
71
71