omdev 0.0.0.dev99__tar.gz → 0.0.0.dev100__tar.gz

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 omdev might be problematic. Click here for more details.

Files changed (152) hide show
  1. {omdev-0.0.0.dev99/omdev.egg-info → omdev-0.0.0.dev100}/PKG-INFO +2 -2
  2. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/.manifests.json +12 -12
  3. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/amalg/amalg.py +8 -5
  4. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/cmake.py +4 -4
  5. omdev-0.0.0.dev100/omdev/cexts/magic.py +7 -0
  6. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/scan.py +3 -3
  7. omdev-0.0.0.dev100/omdev/magic/__init__.py +28 -0
  8. omdev-0.0.0.dev100/omdev/magic/find.py +268 -0
  9. omdev-0.0.0.dev100/omdev/magic/magic.py +17 -0
  10. omdev-0.0.0.dev100/omdev/magic/prepare.py +27 -0
  11. omdev-0.0.0.dev100/omdev/magic/styles.py +33 -0
  12. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/manifests/build.py +6 -6
  13. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/lite.py +4 -4
  14. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/scripts.py +5 -6
  15. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/pkg.py +4 -4
  16. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/pyproject.py +319 -81
  17. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100/omdev.egg-info}/PKG-INFO +2 -2
  18. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev.egg-info/SOURCES.txt +5 -1
  19. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev.egg-info/requires.txt +1 -1
  20. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/pyproject.toml +2 -2
  21. omdev-0.0.0.dev99/omdev/cexts/magic.py +0 -7
  22. omdev-0.0.0.dev99/omdev/findmagic.py +0 -91
  23. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/LICENSE +0 -0
  24. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/MANIFEST.in +0 -0
  25. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/README.rst +0 -0
  26. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/__about__.py +0 -0
  27. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/__init__.py +0 -0
  28. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/amalg/__init__.py +0 -0
  29. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/amalg/__main__.py +0 -0
  30. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/antlr/__init__.py +0 -0
  31. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/antlr/_antlr/__init__.py +0 -0
  32. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/antlr/consts.py +0 -0
  33. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/antlr/gen.py +0 -0
  34. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/bracepy.py +0 -0
  35. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/__init__.py +0 -0
  36. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/__init__.py +0 -0
  37. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/cache.py +0 -0
  38. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/contexts.py +0 -0
  39. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/currents.py +0 -0
  40. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/fns.py +0 -0
  41. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/resolvers.py +0 -0
  42. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/storage.py +0 -0
  43. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/compute/types.py +0 -0
  44. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/__init__.py +0 -0
  45. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/actions.py +0 -0
  46. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/cache.py +0 -0
  47. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/consts.py +0 -0
  48. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/defaults.py +0 -0
  49. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/manifests.py +0 -0
  50. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cache/data/specs.py +0 -0
  51. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/__init__.py +0 -0
  52. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_boilerplate.cc +0 -0
  53. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/LICENSE +0 -0
  54. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/__init__.py +0 -0
  55. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/build_ext.py +0 -0
  56. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/compilers/__init__.py +0 -0
  57. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/compilers/ccompiler.py +0 -0
  58. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/compilers/options.py +0 -0
  59. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/compilers/unixccompiler.py +0 -0
  60. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/dir_util.py +0 -0
  61. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/errors.py +0 -0
  62. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/extension.py +0 -0
  63. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/file_util.py +0 -0
  64. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/modified.py +0 -0
  65. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/spawn.py +0 -0
  66. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/sysconfig.py +0 -0
  67. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/util.py +0 -0
  68. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/_distutils/version.py +0 -0
  69. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/build.py +0 -0
  70. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cexts/importhook.py +0 -0
  71. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/classdot.py +0 -0
  72. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/__init__.py +0 -0
  73. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/__main__.py +0 -0
  74. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/_pathhack.py +0 -0
  75. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/clicli.py +0 -0
  76. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/install.py +0 -0
  77. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/main.py +0 -0
  78. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/managers.py +0 -0
  79. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cli/types.py +0 -0
  80. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/clipboard/__init__.py +0 -0
  81. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/clipboard/clipboard.py +0 -0
  82. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/clipboard/darwin.py +0 -0
  83. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/cmake.py +0 -0
  84. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/findimports.py +0 -0
  85. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/git.py +0 -0
  86. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/imgur.py +0 -0
  87. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/__init__.py +0 -0
  88. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/__main__.py +0 -0
  89. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/cli.py +0 -0
  90. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/inspect.py +0 -0
  91. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/providers.py +0 -0
  92. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/pyenv.py +0 -0
  93. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/resolvers.py +0 -0
  94. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/standalone.py +0 -0
  95. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/system.py +0 -0
  96. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/interp/types.py +0 -0
  97. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/manifests/__init__.py +0 -0
  98. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/manifests/load.py +0 -0
  99. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/manifests/types.py +0 -0
  100. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/mypy/__init__.py +0 -0
  101. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/mypy/debug.py +0 -0
  102. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/packaging/__init__.py +0 -0
  103. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/packaging/names.py +0 -0
  104. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/packaging/requires.py +0 -0
  105. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/packaging/specifiers.py +0 -0
  106. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/packaging/versions.py +0 -0
  107. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/__init__.py +0 -0
  108. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/__main__.py +0 -0
  109. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/base.py +0 -0
  110. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/git.py +0 -0
  111. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/main.py +0 -0
  112. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/precheck/manifests.py +0 -0
  113. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/ptk/__init__.py +0 -0
  114. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/ptk/apps/__init__.py +0 -0
  115. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/ptk/apps/ncdu.py +0 -0
  116. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/__init__.py +0 -0
  117. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/__main__.py +0 -0
  118. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/cexts.py +0 -0
  119. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/cli.py +0 -0
  120. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/configs.py +0 -0
  121. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/pyproject/reqs.py +0 -0
  122. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/revisions.py +0 -0
  123. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/__init__.py +0 -0
  124. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/bumpversion.py +0 -0
  125. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/execrss.py +0 -0
  126. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/exectime.py +0 -0
  127. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/importtrace.py +0 -0
  128. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/interp.py +0 -0
  129. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/scripts/slowcat.py +0 -0
  130. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/secrets.py +0 -0
  131. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tokens.py +0 -0
  132. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/toml/__init__.py +0 -0
  133. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/toml/parser.py +0 -0
  134. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/toml/writer.py +0 -0
  135. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/__init__.py +0 -0
  136. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/doc.py +0 -0
  137. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/docker.py +0 -0
  138. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/git.py +0 -0
  139. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/importscan.py +0 -0
  140. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/mkrelimp.py +0 -0
  141. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/notebook.py +0 -0
  142. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/pawk/__init__.py +0 -0
  143. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/pawk/__main__.py +0 -0
  144. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/pawk/pawk.py +0 -0
  145. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/pip.py +0 -0
  146. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/prof.py +0 -0
  147. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/tools/sqlrepl.py +0 -0
  148. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev/wheelfile.py +0 -0
  149. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev.egg-info/dependency_links.txt +0 -0
  150. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev.egg-info/entry_points.txt +0 -0
  151. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/omdev.egg-info/top_level.txt +0 -0
  152. {omdev-0.0.0.dev99 → omdev-0.0.0.dev100}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev99
3
+ Version: 0.0.0.dev100
4
4
  Summary: omdev
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Operating System :: POSIX
13
13
  Requires-Python: >=3.12
14
14
  License-File: LICENSE
15
- Requires-Dist: omlish==0.0.0.dev99
15
+ Requires-Dist: omlish==0.0.0.dev100
16
16
  Provides-Extra: all
17
17
  Requires-Dist: black~=24.10; extra == "all"
18
18
  Requires-Dist: pycparser~=2.22; extra == "all"
@@ -71,18 +71,6 @@
71
71
  }
72
72
  }
73
73
  },
74
- {
75
- "module": ".findmagic",
76
- "attr": "_CLI_MODULE",
77
- "file": "omdev/findmagic.py",
78
- "line": 65,
79
- "value": {
80
- "$.cli.types.CliModule": {
81
- "cmd_name": "py/findmagic",
82
- "mod_name": "omdev.findmagic"
83
- }
84
- }
85
- },
86
74
  {
87
75
  "module": ".imgur",
88
76
  "attr": "_FOO_CLI_MODULE",
@@ -107,6 +95,18 @@
107
95
  }
108
96
  }
109
97
  },
98
+ {
99
+ "module": ".magic.find",
100
+ "attr": "_CLI_MODULE",
101
+ "file": "omdev/magic/find.py",
102
+ "line": 230,
103
+ "value": {
104
+ "$.cli.types.CliModule": {
105
+ "cmd_name": "py/findmagic",
106
+ "mod_name": "omdev.magic.find"
107
+ }
108
+ }
109
+ },
110
110
  {
111
111
  "module": ".precheck.__main__",
112
112
  "attr": "_CLI_MODULE",
@@ -41,7 +41,7 @@ from omlish import lang
41
41
  from omlish import logs
42
42
  from omlish.lite.runtime import REQUIRED_PYTHON_VERSION
43
43
 
44
- from .. import findmagic
44
+ from .. import magic
45
45
  from .. import tokens as tks
46
46
 
47
47
 
@@ -94,11 +94,14 @@ def strip_main_lines(cls: ta.Sequence[Tokens]) -> list[Tokens]:
94
94
 
95
95
 
96
96
  STRIPPED_HEADER_MAGICS = [
97
- '# @omlish-lite',
98
- '# @omlish-script',
97
+ '@omlish-lite',
98
+ '@omlish-script',
99
99
  ]
100
100
 
101
- STRIPPED_HEADER_PATS = [findmagic.compile_magic_pat(m) for m in STRIPPED_HEADER_MAGICS]
101
+ STRIPPED_HEADER_PAT = magic.compile_magic_style_pat(
102
+ magic.PY_MAGIC_STYLE,
103
+ keys=STRIPPED_HEADER_MAGICS,
104
+ )
102
105
 
103
106
 
104
107
  def strip_header_lines(hls: ta.Sequence[Tokens]) -> list[Tokens]:
@@ -107,7 +110,7 @@ def strip_header_lines(hls: ta.Sequence[Tokens]) -> list[Tokens]:
107
110
  out = []
108
111
  for l in hls:
109
112
  ls = tks.join_toks(l)
110
- if not any(p.fullmatch(ls) for p in STRIPPED_HEADER_PATS):
113
+ if not STRIPPED_HEADER_PAT.fullmatch(ls):
111
114
  out.append(l)
112
115
  return out
113
116
 
@@ -37,7 +37,7 @@ from omlish import lang
37
37
  from omlish import logs
38
38
 
39
39
  from .. import cmake
40
- from .. import findmagic
40
+ from .. import magic
41
41
  from ..cli import CliModule
42
42
  from .magic import CextMagic
43
43
 
@@ -137,10 +137,10 @@ class CmakeProjectGen:
137
137
  out.append(e)
138
138
  elif os.path.isdir(e):
139
139
  out.extend(
140
- findmagic.find_magic(
140
+ magic.find_magic_files(
141
+ CextMagic.STYLE,
141
142
  [e],
142
- [CextMagic.MAGIC_COMMENT],
143
- CextMagic.FILE_EXTENSIONS,
143
+ keys=[CextMagic.KEY],
144
144
  ),
145
145
  )
146
146
  else:
@@ -0,0 +1,7 @@
1
+ # @omlish-lite
2
+ from ..magic.styles import C_MAGIC_STYLE
3
+
4
+
5
+ class CextMagic:
6
+ KEY = '@omlish-cext'
7
+ STYLE = C_MAGIC_STYLE
@@ -15,7 +15,7 @@ def scan_one(
15
15
  input_path: str,
16
16
  **kwargs: ta.Any,
17
17
  ) -> None:
18
- if not any(input_path.endswith('.' + fx) for fx in CextMagic.FILE_EXTENSIONS):
18
+ if not any(input_path.endswith('.' + fx) for fx in CextMagic.STYLE.exts):
19
19
  return
20
20
 
21
21
  with open(input_path, 'rb') as f:
@@ -26,9 +26,9 @@ def scan_one(
26
26
  except UnicodeDecodeError:
27
27
  return
28
28
 
29
- sls = [l for l in src.splitlines() if l.startswith(CextMagic.MAGIC_COMMENT)]
29
+ sls = [l for l in src.splitlines() if l.startswith('// ' + CextMagic.KEY)] # FIXME
30
30
  for sl in sls:
31
- sas = sl[len(CextMagic.MAGIC_COMMENT):].split() # noqa
31
+ sas = sl[len(CextMagic.KEY) + 3:].split() # noqa
32
32
 
33
33
  log.info('Found ext: %s', input_path)
34
34
 
@@ -0,0 +1,28 @@
1
+ # @omlish-lite
2
+
3
+ from .find import ( # noqa
4
+ chop_magic_block,
5
+ chop_magic_lines,
6
+ compile_magic_style_pat,
7
+ find_magic,
8
+ find_magic_files,
9
+ find_magic_py_modules,
10
+ )
11
+
12
+ from .magic import ( # noqa
13
+ Magic,
14
+ )
15
+
16
+ from .prepare import ( # noqa
17
+ MagicPrepareError,
18
+ json_magic_preparer,
19
+ py_compile_magic_preparer,
20
+ py_eval_magic_preparer,
21
+ )
22
+
23
+ from .styles import ( # noqa
24
+ C_MAGIC_STYLE,
25
+ MAGIC_KEY_PREFIX,
26
+ MagicStyle,
27
+ PY_MAGIC_STYLE,
28
+ )
@@ -0,0 +1,268 @@
1
+ # ruff: noqa: UP006 UP007
2
+ import functools
3
+ import os.path
4
+ import re
5
+ import typing as ta
6
+
7
+ from .magic import Magic
8
+ from .prepare import MagicPrepareError
9
+ from .prepare import py_compile_magic_preparer
10
+ from .styles import C_MAGIC_STYLE
11
+ from .styles import PY_MAGIC_STYLE
12
+ from .styles import MagicStyle
13
+
14
+
15
+ ##
16
+
17
+
18
+ def compile_magic_style_pat(
19
+ style: MagicStyle,
20
+ *,
21
+ keys: ta.Optional[ta.Iterable[str]] = None,
22
+ ) -> re.Pattern:
23
+ ps: ta.List[str] = []
24
+ if style.line_prefix is not None:
25
+ ps.append(style.line_prefix)
26
+ if style.block_prefix_suffix is not None:
27
+ ps.append(style.block_prefix_suffix[0])
28
+ if not ps:
29
+ raise Exception('No prefixes')
30
+
31
+ ms: ta.List[str] = []
32
+ if keys is not None:
33
+ if isinstance(keys, str):
34
+ raise TypeError(keys)
35
+ for k in keys:
36
+ if not k.startswith(style.key_prefix):
37
+ raise Exception(f'Key does not start with prefix: {k!r} {style.key_prefix!r}')
38
+ ms.extend([re.escape(p + k) for p in ps])
39
+ else:
40
+ ms = [re.escape(p + style.key_prefix) + r'\S*' for p in ps]
41
+ if not ms:
42
+ raise Exception('No matchers')
43
+
44
+ b = '|'.join(f'({m})' for m in ms)
45
+ s = '^(' + b + r')($|(\s.*))'
46
+ return re.compile(s)
47
+
48
+
49
+ ##
50
+
51
+
52
+ def chop_magic_lines(
53
+ magic_key: str,
54
+ prefix: str,
55
+ lines: ta.Iterable[str],
56
+ ) -> ta.Optional[ta.List[str]]:
57
+ out: ta.List[str] = []
58
+ for i, line in enumerate(lines):
59
+ if not i:
60
+ if not line.startswith(prefix + magic_key):
61
+ return None
62
+ out.append(line[len(prefix) + len(magic_key) + 1:])
63
+ else:
64
+ if not line.startswith(prefix):
65
+ return None
66
+ out.append(line[len(prefix):])
67
+ return out
68
+
69
+
70
+ def chop_magic_block(
71
+ magic_key: str,
72
+ prefix: str,
73
+ suffix: str,
74
+ lines: ta.Iterable[str],
75
+ ) -> ta.Optional[ta.List[str]]:
76
+ out: ta.List[str] = []
77
+ for i, line in enumerate(lines):
78
+ if not i:
79
+ if not line.startswith(prefix + magic_key):
80
+ return None
81
+ s = line[len(prefix) + len(magic_key) + 1:]
82
+ if s.rstrip().endswith(suffix):
83
+ out.append(s.rstrip()[:-len(suffix)])
84
+ break
85
+ out.append(s)
86
+ elif line.rstrip().endswith(suffix):
87
+ out.append(line.rstrip()[:-len(suffix)])
88
+ break
89
+ else:
90
+ out.append(line)
91
+ return out
92
+
93
+
94
+ ##
95
+
96
+
97
+ def find_magic(
98
+ style: MagicStyle,
99
+ lines: ta.Sequence[str],
100
+ *,
101
+ file: ta.Optional[str] = None,
102
+ preparer: ta.Callable[[str], ta.Any] = py_compile_magic_preparer,
103
+ ) -> ta.List[Magic]:
104
+ out: ta.List[Magic] = []
105
+
106
+ start = 0
107
+ while start < len(lines):
108
+ start_line = lines[start]
109
+
110
+ chopper: ta.Callable[[ta.Iterable[str]], ta.Optional[ta.List[str]]]
111
+ if (
112
+ style.line_prefix is not None and
113
+ start_line.startswith(style.line_prefix + style.key_prefix)
114
+ ):
115
+ key = start_line[len(style.line_prefix):].split()[0]
116
+ chopper = functools.partial(
117
+ chop_magic_lines,
118
+ key,
119
+ style.line_prefix,
120
+ )
121
+
122
+ elif (
123
+ style.block_prefix_suffix is not None and
124
+ start_line.startswith(style.block_prefix_suffix[0] + style.key_prefix)
125
+ ):
126
+ key = start_line[len(style.block_prefix_suffix[0]):].split()[0]
127
+ chopper = functools.partial(
128
+ chop_magic_block,
129
+ key,
130
+ *style.block_prefix_suffix,
131
+ )
132
+
133
+ else:
134
+ start += 1
135
+ continue
136
+
137
+ end = start
138
+ magic: ta.Optional[Magic] = None
139
+ while end < len(lines):
140
+ block_lines = chopper(lines[start:end + 1])
141
+ if block_lines is None:
142
+ raise Exception(f'Failed to find magic block terminator : {file=} {start=} {end=}')
143
+
144
+ block_src = ''.join(block_lines)
145
+ if not block_src:
146
+ prepared = None
147
+ else:
148
+ try:
149
+ prepared = preparer(block_src)
150
+ except MagicPrepareError:
151
+ end += 1
152
+ continue
153
+
154
+ magic = Magic(
155
+ key=key,
156
+ file=file,
157
+ start_line=start + 1,
158
+ end_line=end + 1,
159
+ body=block_src,
160
+ prepared=prepared,
161
+ )
162
+ break
163
+
164
+ if magic is None:
165
+ raise Exception(f'Failed to find magic block terminator : {file=} {start=} {end=}')
166
+
167
+ out.append(magic)
168
+ start = end + 1
169
+
170
+ return out
171
+
172
+
173
+ ##
174
+
175
+
176
+ def find_magic_files(
177
+ style: MagicStyle,
178
+ roots: ta.Sequence[str],
179
+ *,
180
+ keys: ta.Optional[ta.Iterable[str]] = None,
181
+ ) -> ta.Iterator[str]:
182
+ if isinstance(roots, str):
183
+ raise TypeError(roots)
184
+
185
+ pat = compile_magic_style_pat(
186
+ style,
187
+ keys=keys,
188
+ )
189
+
190
+ for root in roots:
191
+ for dp, dns, fns in os.walk(root): # noqa
192
+ for fn in fns:
193
+ if not any(fn.endswith(f'.{x}') for x in style.exts):
194
+ continue
195
+
196
+ fp = os.path.join(dp, fn)
197
+ try:
198
+ with open(fp) as f:
199
+ src = f.read()
200
+ except UnicodeDecodeError:
201
+ continue
202
+
203
+ if not any(pat.fullmatch(l) for l in src.splitlines()):
204
+ continue
205
+
206
+ yield fp
207
+
208
+
209
+ def find_magic_py_modules(
210
+ roots: ta.Sequence[str],
211
+ *,
212
+ style: MagicStyle = PY_MAGIC_STYLE,
213
+ **kwargs: ta.Any,
214
+ ) -> ta.Iterator[str]:
215
+ for fp in find_magic_files(style, roots, **kwargs):
216
+ dp = os.path.dirname(fp)
217
+ fn = os.path.basename(fp)
218
+
219
+ if fn == '__init__.py':
220
+ yield dp.replace(os.sep, '.')
221
+ elif fn.endswith('.py'):
222
+ yield fp[:-3].replace(os.sep, '.')
223
+ else:
224
+ yield fp
225
+
226
+
227
+ ##
228
+
229
+
230
+ # @omlish-manifest
231
+ _CLI_MODULE = {'$omdev.cli.types.CliModule': {
232
+ 'cmd_name': 'py/findmagic',
233
+ 'mod_name': __name__,
234
+ }}
235
+
236
+
237
+ if __name__ == '__main__':
238
+ def _main(argv=None) -> None:
239
+ import argparse
240
+
241
+ arg_parser = argparse.ArgumentParser()
242
+ arg_parser.add_argument('--style', '-s', default='py')
243
+ arg_parser.add_argument('--key', '-k', dest='keys', action='append')
244
+ arg_parser.add_argument('--modules', action='store_true')
245
+ arg_parser.add_argument('roots', nargs='*')
246
+ args = arg_parser.parse_args(argv)
247
+
248
+ style = {
249
+ 'py': PY_MAGIC_STYLE,
250
+ 'c': C_MAGIC_STYLE,
251
+ }[args.style]
252
+
253
+ kw: dict = dict(
254
+ roots=args.roots,
255
+ style=style,
256
+ keys=args.keys,
257
+ )
258
+
259
+ fn: ta.Callable
260
+ if args.modules:
261
+ fn = find_magic_py_modules
262
+ else:
263
+ fn = find_magic_files
264
+
265
+ for out in fn(**kw):
266
+ print(out)
267
+
268
+ _main()
@@ -0,0 +1,17 @@
1
+ # ruff: noqa: UP007
2
+ import dataclasses as dc
3
+ import typing as ta
4
+
5
+
6
+ @dc.dataclass(frozen=True)
7
+ class Magic:
8
+ key: str
9
+
10
+ file: ta.Optional[str]
11
+
12
+ start_line: int
13
+ end_line: int
14
+
15
+ body: str
16
+
17
+ prepared: ta.Any
@@ -0,0 +1,27 @@
1
+ import json
2
+ import typing as ta
3
+
4
+
5
+ class MagicPrepareError(Exception):
6
+ pass
7
+
8
+
9
+ def py_compile_magic_preparer(src: str) -> ta.Any:
10
+ try:
11
+ prepared = compile(f'({src})', '<magic>', 'eval')
12
+ except SyntaxError:
13
+ raise MagicPrepareError # noqa
14
+ return prepared
15
+
16
+
17
+ def py_eval_magic_preparer(src: str) -> ta.Any:
18
+ code = py_compile_magic_preparer(src)
19
+ return eval(code) # noqa
20
+
21
+
22
+ def json_magic_preparer(src: str) -> ta.Any:
23
+ try:
24
+ prepared = json.loads(src)
25
+ except json.JSONDecodeError:
26
+ raise MagicPrepareError # noqa
27
+ return prepared
@@ -0,0 +1,33 @@
1
+ # ruff: noqa: UP006 UP007
2
+ import dataclasses as dc
3
+ import typing as ta
4
+
5
+
6
+ MAGIC_KEY_PREFIX = '@omlish-'
7
+
8
+
9
+ @dc.dataclass(frozen=True)
10
+ class MagicStyle:
11
+ name: str
12
+
13
+ exts: ta.FrozenSet[str] = frozenset()
14
+
15
+ key_prefix: str = MAGIC_KEY_PREFIX
16
+
17
+ line_prefix: ta.Optional[str] = None
18
+ block_prefix_suffix: ta.Optional[ta.Tuple[str, str]] = None
19
+
20
+
21
+ PY_MAGIC_STYLE = MagicStyle(
22
+ name='py',
23
+ exts=frozenset(['py']),
24
+ line_prefix='# ',
25
+ )
26
+
27
+
28
+ C_MAGIC_STYLE = MagicStyle(
29
+ name='c',
30
+ exts=frozenset(['c', 'cc', 'cpp']),
31
+ line_prefix='// ',
32
+ block_prefix_suffix=('/* ', '*/'),
33
+ )
@@ -32,7 +32,7 @@ from omlish.lite.json import json_dumps_pretty
32
32
  from omlish.lite.logs import configure_standard_logging
33
33
  from omlish.lite.logs import log
34
34
 
35
- from .. import findmagic
35
+ from .. import magic
36
36
  from .load import ManifestLoader
37
37
  from .types import Manifest
38
38
  from .types import ManifestOrigin
@@ -44,7 +44,7 @@ T = ta.TypeVar('T')
44
44
  ##
45
45
 
46
46
 
47
- MANIFEST_MAGIC = '# @omlish-manifest'
47
+ MANIFEST_MAGIC_KEY = '@omlish-manifest'
48
48
 
49
49
  _MANIFEST_GLOBAL_PAT = re.compile(r'^(?P<name>[A-Za-z_][A-Za-z0-9_]*)\s*=.*')
50
50
 
@@ -148,7 +148,7 @@ class ManifestBuilder:
148
148
  origins: ta.List[ManifestOrigin] = []
149
149
  lines = src.splitlines(keepends=True)
150
150
  for i, l in enumerate(lines):
151
- if l.startswith(MANIFEST_MAGIC):
151
+ if l.startswith('# ' + MANIFEST_MAGIC_KEY):
152
152
  if (m := _MANIFEST_GLOBAL_PAT.match(nl := lines[i + 1])) is None:
153
153
  raise Exception(nl)
154
154
 
@@ -235,10 +235,10 @@ class ManifestBuilder:
235
235
  if not os.path.isdir(pkg_dir) or not os.path.isfile(os.path.join(pkg_dir, '__init__.py')):
236
236
  raise Exception(pkg_dir)
237
237
 
238
- files = sorted(findmagic.find_magic(
238
+ files = sorted(magic.find_magic_files(
239
+ magic.PY_MAGIC_STYLE,
239
240
  [pkg_dir],
240
- [MANIFEST_MAGIC],
241
- ['py'],
241
+ keys=[MANIFEST_MAGIC_KEY],
242
242
  ))
243
243
  manifests: ta.List[Manifest] = list(itertools.chain.from_iterable(await asyncio.gather(*[
244
244
  self._spawn(
@@ -8,10 +8,10 @@ import subprocess
8
8
  import textwrap
9
9
  import typing as ta
10
10
 
11
- from omdev import findmagic
12
11
  from omlish import cached
13
12
  from omlish.lite.subprocesses import subprocess_maybe_shell_wrap_exec
14
13
 
14
+ from .. import magic
15
15
  from .base import Precheck
16
16
  from .base import PrecheckContext
17
17
 
@@ -121,10 +121,10 @@ class LitePython8Precheck(Precheck['LitePython8Precheck.Config']):
121
121
  return vs
122
122
 
123
123
  async def run(self) -> ta.AsyncGenerator[Precheck.Violation, None]:
124
- for fp in findmagic.find_magic(
124
+ for fp in magic.find_magic_files(
125
+ magic.PY_MAGIC_STYLE,
125
126
  self._context.src_roots,
126
- ['# @omlish-lite'],
127
- ['py'],
127
+ keys=['@omlish-lite'],
128
128
  ):
129
129
  with open(fp) as f: # noqa # FIXME
130
130
  src = f.read()
@@ -3,9 +3,8 @@ import os
3
3
  import stat
4
4
  import typing as ta
5
5
 
6
- from omdev import findimports
7
- from omdev import findmagic
8
-
6
+ from .. import findimports
7
+ from .. import magic
9
8
  from .base import Precheck
10
9
  from .base import PrecheckContext
11
10
 
@@ -22,10 +21,10 @@ class ScriptDepsPrecheck(Precheck['ScriptDepsPrecheck.Config']):
22
21
  super().__init__(context, config)
23
22
 
24
23
  async def run(self) -> ta.AsyncGenerator[Precheck.Violation, None]:
25
- for fp in findmagic.find_magic(
24
+ for fp in magic.find_magic_files(
25
+ magic.PY_MAGIC_STYLE,
26
26
  self._context.src_roots,
27
- ['# @omlish-script'],
28
- ['py'],
27
+ keys=['@omlish-script'],
29
28
  ):
30
29
  if not (stat.S_IXUSR & os.stat(fp).st_mode):
31
30
  yield Precheck.Violation(self, f'script {fp} is not executable')
@@ -40,7 +40,7 @@ from omlish.lite.logs import log
40
40
  from omlish.lite.subprocesses import subprocess_check_call
41
41
 
42
42
  from ..cexts.magic import CextMagic
43
- from ..findmagic import find_magic
43
+ from ..magic.find import find_magic_files
44
44
  from ..revisions import GitRevisionAdder
45
45
  from ..toml.writer import TomlWriter
46
46
 
@@ -403,10 +403,10 @@ class _PyprojectCextPackageGenerator(BasePyprojectPackageGenerator):
403
403
 
404
404
  @cached_nullary
405
405
  def find_cext_srcs(self) -> ta.Sequence[str]:
406
- return sorted(find_magic(
406
+ return sorted(find_magic_files(
407
+ CextMagic.STYLE,
407
408
  [self._dir_name],
408
- [CextMagic.MAGIC_COMMENT],
409
- CextMagic.FILE_EXTENSIONS,
409
+ keys=[CextMagic.KEY],
410
410
  ))
411
411
 
412
412
  #