omdev 0.0.0.dev57__py3-none-any.whl → 0.0.0.dev59__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.

Potentially problematic release.


This version of omdev might be problematic. Click here for more details.

File without changes
File without changes
omdev/antlr/consts.py ADDED
@@ -0,0 +1,7 @@
1
+ ANTLR_VERSION = '4.13.2'
2
+ ANTLR_JAR_NAME = f'antlr-{ANTLR_VERSION}-complete.jar'
3
+ ANTLR_JAR_URL = f'https://www.antlr.org/download/{ANTLR_JAR_NAME}'
4
+ ANTLR_RUNTIME_PACKAGE = 'antlr4-python3-runtime'
5
+ ANTLR_GITHUB_REPO = 'antlr/antlr4'
6
+
7
+ ANTLR_RUNTIME_VENDOR = 'omlish.antlr._runtime'
omdev/antlr/gen.py ADDED
@@ -0,0 +1,110 @@
1
+ """
2
+ TODO:
3
+ - fix relpath in omlish/
4
+ - sem-bounded parallelism
5
+ """
6
+ import argparse
7
+ import os.path
8
+ import re
9
+ import shutil
10
+ import subprocess
11
+
12
+ from omlish import check
13
+ from omlish import lang
14
+
15
+ from ..cache import data as dcache
16
+ from .consts import ANTLR_JAR_URL
17
+ from .consts import ANTLR_RUNTIME_VENDOR
18
+
19
+
20
+ ANTLR_JAR_CACHE = dcache.UrlSpec(ANTLR_JAR_URL)
21
+
22
+
23
+ class GenPy:
24
+ def __init__(
25
+ self,
26
+ dir: str, # noqa
27
+ *,
28
+ out_subdir: str = '_antlr',
29
+ runtime_import: str = ANTLR_RUNTIME_VENDOR,
30
+ ) -> None:
31
+ super().__init__()
32
+ check.arg(not os.path.isabs(out_subdir) and '..' not in out_subdir)
33
+ self._dir = dir
34
+ self._out_subdir = out_subdir
35
+ self._runtime_import = runtime_import
36
+ self._out_dir = os.path.join(dir, out_subdir)
37
+
38
+ @lang.cached_function
39
+ def jar(self) -> str:
40
+ return dcache.default().get(ANTLR_JAR_CACHE)
41
+
42
+ def process_g4(self, g4_file: str) -> None:
43
+ subprocess.check_call([
44
+ 'java',
45
+ '-jar', self.jar(),
46
+ '-Dlanguage=Python3',
47
+ '-visitor',
48
+ '-o', self._out_subdir,
49
+ g4_file,
50
+ ], cwd=self._dir)
51
+
52
+ def process_py(self, py_file: str) -> None:
53
+ ap = os.path.join(self._out_dir, py_file)
54
+ with open(ap) as f:
55
+ in_lines = list(f)
56
+
57
+ out_lines = [
58
+ '# type: ignore\n',
59
+ '# ruff: noqa\n',
60
+ '# flake8: noqa\n',
61
+ ]
62
+ for l in in_lines:
63
+ l = re.sub(r'^(from antlr4)(.*)', rf'from {self._runtime_import}\2', l)
64
+ out_lines.append(l)
65
+
66
+ with open(ap, 'w') as f:
67
+ f.write(''.join(out_lines))
68
+
69
+ def run(self) -> None:
70
+ if os.path.exists(self._out_dir):
71
+ shutil.rmtree(self._out_dir)
72
+ os.mkdir(self._out_dir)
73
+ with open(os.path.join(self._out_dir, '__init__.py'), 'w'):
74
+ pass
75
+
76
+ for f in os.listdir(self._dir):
77
+ fp = os.path.join(self._dir, f)
78
+ if not os.path.isfile(fp):
79
+ continue
80
+ if f.endswith('.g4'):
81
+ self.process_g4(f)
82
+
83
+ for f in list(os.listdir(self._out_dir)):
84
+ fp = os.path.join(self._out_dir, f)
85
+ if not os.path.isfile(fp):
86
+ continue
87
+ if f.split('.')[-1] in ('interp', 'tokens'):
88
+ os.unlink(fp)
89
+ elif f != '__init__.py' and f.endswith('.py'):
90
+ self.process_py(f)
91
+
92
+
93
+ def _main() -> None:
94
+ parser = argparse.ArgumentParser()
95
+ parser.add_argument('roots', nargs='*')
96
+ args = parser.parse_args()
97
+
98
+ base_dir = os.getcwd()
99
+ if not os.path.isfile(os.path.join(base_dir, 'pyproject.toml')):
100
+ raise RuntimeError('Must run from project root')
101
+
102
+ for root_dir in args.roots:
103
+ print(f'Processing {root_dir}')
104
+ GenPy(
105
+ root_dir,
106
+ ).run()
107
+
108
+
109
+ if __name__ == '__main__':
110
+ _main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev57
3
+ Version: 0.0.0.dev59
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.dev57
15
+ Requires-Dist: omlish ==0.0.0.dev59
16
16
  Provides-Extra: all
17
17
  Requires-Dist: pycparser ~=2.22 ; extra == 'all'
18
18
  Requires-Dist: cffi ~=1.17 ; extra == 'all'
@@ -14,6 +14,10 @@ omdev/wheelfile.py,sha256=yfupGcGkbFlmzGzKU64k_vmOKpaKnUlDWxeGn2KdekU,10005
14
14
  omdev/amalg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  omdev/amalg/__main__.py,sha256=h94M-VqZ3AFBU2a8zOsjeKK7RF6uINhTHl6OiGbVMgw,163
16
16
  omdev/amalg/amalg.py,sha256=8tsrsKpgB54aOZ7CPQ6EoUIUYXylMvJpDOOJwbvSZ5E,14339
17
+ omdev/antlr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ omdev/antlr/consts.py,sha256=8pR6r0m0P3hAiyiAoJZ-nptd2GYbZ98mxwPL9cpaRuw,279
19
+ omdev/antlr/gen.py,sha256=QnPyVWUrJYqHoOc3XsXA8fJdoiwAj6pyUwdG-DVrIeA,2953
20
+ omdev/antlr/_antlr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
21
  omdev/cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
22
  omdev/cache/compute/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
23
  omdev/cache/compute/cache.py,sha256=pEbcTSQavhX7M0olzR8AOCtHx7tMnMnEDEfTPQVY5uE,3602
@@ -115,9 +119,9 @@ omdev/tools/piptools.py,sha256=-jR5q3w4sHqntxCLExFCBNIARB788FUsAbJ62PK2sBU,2774
115
119
  omdev/tools/proftools.py,sha256=xKSm_yPoCnfsvS3iT9MblDqFMuZmGfI3_koGj8amMyU,145
116
120
  omdev/tools/rst.py,sha256=6dWk8QZHoGiLSuBw3TKsXZjjFK6wWBEtPi9krdCLKKg,977
117
121
  omdev/tools/sqlrepl.py,sha256=tmFZh80-xsGM62dyQ7_UGLebChrj7IHbIPYBWDJMgVk,5741
118
- omdev-0.0.0.dev57.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
119
- omdev-0.0.0.dev57.dist-info/METADATA,sha256=Bc5g8JNkGTVplTCJJa3urQVje-2-pJgiAfOo1Z9-3mw,1252
120
- omdev-0.0.0.dev57.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
121
- omdev-0.0.0.dev57.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
122
- omdev-0.0.0.dev57.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
123
- omdev-0.0.0.dev57.dist-info/RECORD,,
122
+ omdev-0.0.0.dev59.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
123
+ omdev-0.0.0.dev59.dist-info/METADATA,sha256=DwUCqPNW2EXhsYnskKg_oppQTYWF_XQnnJpzjA2eJzg,1252
124
+ omdev-0.0.0.dev59.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
125
+ omdev-0.0.0.dev59.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
126
+ omdev-0.0.0.dev59.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
127
+ omdev-0.0.0.dev59.dist-info/RECORD,,