ai-editor-tree-engine-dev 1.0.176__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 (121) hide show
  1. ai_editor_tree_engine_dev-1.0.176.dist-info/METADATA +35 -0
  2. ai_editor_tree_engine_dev-1.0.176.dist-info/RECORD +121 -0
  3. ai_editor_tree_engine_dev-1.0.176.dist-info/WHEEL +5 -0
  4. ai_editor_tree_engine_dev-1.0.176.dist-info/licenses/LICENSE +21 -0
  5. ai_editor_tree_engine_dev-1.0.176.dist-info/top_level.txt +1 -0
  6. tree_engine/PUBLIC_API.md +161 -0
  7. tree_engine/__init__.py +327 -0
  8. tree_engine/checks/__init__.py +60 -0
  9. tree_engine/checks/builtin/__init__.py +5 -0
  10. tree_engine/checks/builtin/compile_check.py +53 -0
  11. tree_engine/checks/builtin/csv_syntax.py +51 -0
  12. tree_engine/checks/builtin/docstrings.py +211 -0
  13. tree_engine/checks/builtin/encoding.py +55 -0
  14. tree_engine/checks/builtin/fleet_rules.py +227 -0
  15. tree_engine/checks/builtin/format_syntax.py +82 -0
  16. tree_engine/checks/builtin/jsonl_syntax.py +49 -0
  17. tree_engine/checks/builtin/shipped.py +52 -0
  18. tree_engine/checks/builtin/syntax.py +118 -0
  19. tree_engine/checks/builtin/xml_wellformed.py +51 -0
  20. tree_engine/checks/chain.py +332 -0
  21. tree_engine/checks/external/__init__.py +5 -0
  22. tree_engine/checks/external/_base.py +61 -0
  23. tree_engine/checks/external/bandit.py +53 -0
  24. tree_engine/checks/external/black.py +48 -0
  25. tree_engine/checks/external/flake8.py +38 -0
  26. tree_engine/checks/external/isort.py +38 -0
  27. tree_engine/checks/external/mypy.py +45 -0
  28. tree_engine/checks/external/ruff.py +45 -0
  29. tree_engine/checks/external/runner.py +197 -0
  30. tree_engine/checks/model.py +110 -0
  31. tree_engine/checks/options.py +73 -0
  32. tree_engine/checks/plugin.py +171 -0
  33. tree_engine/checks/registry.py +349 -0
  34. tree_engine/core/address.py +376 -0
  35. tree_engine/core/identifier_map.py +266 -0
  36. tree_engine/core/identity.py +226 -0
  37. tree_engine/core/instrumentation.py +399 -0
  38. tree_engine/core/integrity.py +341 -0
  39. tree_engine/core/integrity_full.py +382 -0
  40. tree_engine/core/journal.py +260 -0
  41. tree_engine/core/journal_compose.py +571 -0
  42. tree_engine/core/live_tree.py +785 -0
  43. tree_engine/core/locking.py +188 -0
  44. tree_engine/core/move.py +585 -0
  45. tree_engine/core/move_references.py +323 -0
  46. tree_engine/core/node_types.py +408 -0
  47. tree_engine/core/nodes.py +348 -0
  48. tree_engine/core/offsets.py +24 -0
  49. tree_engine/core/operations.py +825 -0
  50. tree_engine/core/plugin_boundary.py +160 -0
  51. tree_engine/core/position_map.py +263 -0
  52. tree_engine/core/position_transfer.py +512 -0
  53. tree_engine/core/range_refresh.py +366 -0
  54. tree_engine/core/reference_cache.py +360 -0
  55. tree_engine/core/references.py +223 -0
  56. tree_engine/core/reparse.py +378 -0
  57. tree_engine/core/short_id.py +296 -0
  58. tree_engine/core/subtree_apply.py +397 -0
  59. tree_engine/core/subtree_copy.py +399 -0
  60. tree_engine/core/transactions.py +397 -0
  61. tree_engine/core/trivia.py +396 -0
  62. tree_engine/core/updates.py +398 -0
  63. tree_engine/core/validation.py +377 -0
  64. tree_engine/errors.py +104 -0
  65. tree_engine/exceptions.py +376 -0
  66. tree_engine/facade.py +4524 -0
  67. tree_engine/plugins/_statements.py +369 -0
  68. tree_engine/plugins/bsl/block_edit.py +449 -0
  69. tree_engine/plugins/bsl/blocks.py +127 -0
  70. tree_engine/plugins/bsl/checker.py +297 -0
  71. tree_engine/plugins/bsl/dialects.py +303 -0
  72. tree_engine/plugins/bsl/generator.py +481 -0
  73. tree_engine/plugins/bsl/import_map.py +995 -0
  74. tree_engine/plugins/bsl/plugin.py +452 -0
  75. tree_engine/plugins/contract.py +355 -0
  76. tree_engine/plugins/cpp/import_map.py +505 -0
  77. tree_engine/plugins/cpp/languages.py +99 -0
  78. tree_engine/plugins/cpp/plugin.py +501 -0
  79. tree_engine/plugins/csv_format.py +676 -0
  80. tree_engine/plugins/detachable.py +156 -0
  81. tree_engine/plugins/fallback.py +421 -0
  82. tree_engine/plugins/ini_format.py +330 -0
  83. tree_engine/plugins/json_format.py +813 -0
  84. tree_engine/plugins/json_pointer.py +203 -0
  85. tree_engine/plugins/jsonl_format.py +392 -0
  86. tree_engine/plugins/markdown_format.py +748 -0
  87. tree_engine/plugins/onec_query_format.py +61 -0
  88. tree_engine/plugins/parse_position.py +54 -0
  89. tree_engine/plugins/plain_text.py +1543 -0
  90. tree_engine/plugins/python/export_map.py +306 -0
  91. tree_engine/plugins/python/import_map.py +429 -0
  92. tree_engine/plugins/python/plugin.py +1710 -0
  93. tree_engine/plugins/registry.py +497 -0
  94. tree_engine/plugins/scan.py +87 -0
  95. tree_engine/plugins/selection.py +228 -0
  96. tree_engine/plugins/sql_format.py +61 -0
  97. tree_engine/plugins/toml_format.py +1072 -0
  98. tree_engine/plugins/xml_format.py +911 -0
  99. tree_engine/plugins/yaml/builder.py +49 -0
  100. tree_engine/plugins/yaml/emitter.py +225 -0
  101. tree_engine/plugins/yaml/flow.py +227 -0
  102. tree_engine/plugins/yaml/plugin.py +458 -0
  103. tree_engine/plugins/yaml/ranges.py +52 -0
  104. tree_engine/plugins/yaml/reader.py +359 -0
  105. tree_engine/plugins/yaml/scanner.py +298 -0
  106. tree_engine/query/adapter.py +283 -0
  107. tree_engine/query/engine.py +853 -0
  108. tree_engine/query/inspection.py +498 -0
  109. tree_engine/query/outline.py +288 -0
  110. tree_engine/query/predicates.py +263 -0
  111. tree_engine/query/rendered_lines.py +46 -0
  112. tree_engine/query/results.py +206 -0
  113. tree_engine/query/selector.py +400 -0
  114. tree_engine/query/xml_query.py +747 -0
  115. tree_engine/storage/codec.py +400 -0
  116. tree_engine/storage/document_bridge.py +579 -0
  117. tree_engine/storage/file_txn.py +459 -0
  118. tree_engine/storage/history.py +106 -0
  119. tree_engine/storage/lifecycle.py +622 -0
  120. tree_engine/storage/schema.py +403 -0
  121. tree_engine/storage/session_guard.py +398 -0
@@ -0,0 +1,327 @@
1
+ """``tree_engine`` -- the public import surface of the ``ai-editor-tree-engine`` distribution.
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+
6
+ Before this module existed, ``src/tree_engine`` had no ``__init__.py`` anywhere and was a pure
7
+ PEP 420 namespace package. Two consequences followed, both bad, and one of them is bug 46d83446:
8
+
9
+ 1. ``from tree_engine import X`` (the natural way any consumer -- another service, a plugin, a
10
+ test -- reaches the engine) failed outright, because a namespace package has no module body to
11
+ hang re-exports off; only ``from tree_engine.facade import X`` worked, and nothing advertised
12
+ that requirement.
13
+ 2. A namespace package's ``__path__`` is the *union* of every ``tree_engine`` directory found
14
+ across ``sys.path`` -- so a checkout's ``src/tree_engine`` and an already-installed
15
+ ``ai-editor-tree-engine`` distribution in the same interpreter's site-packages silently merge
16
+ into one package, with whichever directory sorts first on ``sys.path`` winning per-submodule.
17
+ A real package (this file) stops the merge: the first ``tree_engine`` directory found on
18
+ ``sys.path`` is used whole, exactly as every other regular Python package behaves.
19
+
20
+ This module re-exports the same public names :mod:`tree_engine.facade` already declares in its
21
+ own ``__all__`` (the single public entry point, {p037}), plus the public exception hierarchy and
22
+ the frozen error-code catalog, so a consumer never has to import a ``tree_engine.*`` submodule
23
+ directly. Per the standalone law (p003), nothing here -- or anywhere else under
24
+ ``src/tree_engine`` -- imports ``ai_editor``, ``mcp_proxy`` or ``code_analysis_server``;
25
+ ``pipeline check-boundary-check`` enforces that mechanically.
26
+
27
+ Import order matters only for readability here, not for correctness: ``tree_engine.errors`` and
28
+ ``tree_engine.exceptions`` both import cleanly with zero dependency on ``tree_engine.facade``, and
29
+ ``tree_engine.facade`` does not import this package (``tree_engine``) itself, so there is no
30
+ import cycle to break with lazy/deferred imports -- a cold ``python -c "import tree_engine;
31
+ tree_engine.drill_down"`` is the check that keeps this true; see
32
+ ``pipeline/checks/check_engine_public_import_surface_6e609b97.py``
33
+ (``engine_public_import_surface_6e609b97``).
34
+
35
+ ``tree_engine.facade.query`` is re-exported here under a DIFFERENT name, ``run_query`` -- never
36
+ bind a top-level ``query`` attribute on this package, or it collides with the real
37
+ ``tree_engine.query`` SUBPACKAGE (``tree_engine.query.engine``/``.inspection``/``.outline``/
38
+ ``.results``); see the comment beside the ``run_query`` import below for the exact mechanism.
39
+
40
+ Every one of these imports reaches ``tree_engine.facade``, which unconditionally imports
41
+ ``tree_engine.query.engine`` -> ``lark`` -- so `lark` is a hard runtime dependency of `import
42
+ tree_engine` itself (a base dependency of the ``ai-editor-tree-engine`` distribution, not an
43
+ extra), not merely of calling ``run_query``/``drill_down``. There is no lark-less partial import
44
+ of this package.
45
+ """
46
+
47
+ from __future__ import annotations
48
+
49
+ from tree_engine.errors import ErrorCode, ErrorLayer, ERROR_CODE_LAYER, error_layer
50
+ from tree_engine.exceptions import (
51
+ CODE_TO_EXCEPTION,
52
+ ChecksumMismatch,
53
+ ConcurrentSourceModification,
54
+ ConcurrentTreeModification,
55
+ CoreLayerException,
56
+ CycleDetected,
57
+ DocumentVersionConflict,
58
+ FormatContentParseFailed,
59
+ FormatExtensionConflict,
60
+ FormatFragmentParseFailed,
61
+ FormatPluginContractError,
62
+ FormatPluginNotFound,
63
+ FormatUnknownExtension,
64
+ InvalidParentType,
65
+ InvalidPosition,
66
+ InvalidSelector,
67
+ NodeIdConflict,
68
+ NodeNotFound,
69
+ PluginCapabilityNotSupported,
70
+ PluginLayerException,
71
+ ShortIdConflict,
72
+ StorageIOError,
73
+ CheckConfigInvalid,
74
+ CheckToolCrashed,
75
+ CheckToolMissing,
76
+ CheckToolTimeout,
77
+ StorageLayerException,
78
+ TreeEngineException,
79
+ TreePayloadInvalid,
80
+ TreeSchemaUnsupported,
81
+ UnresolvedReference,
82
+ UnsupportedTranslation,
83
+ exception_for_code,
84
+ )
85
+ from tree_engine.facade import (
86
+ Address,
87
+ AddressRemap,
88
+ ApplySubtreeResult,
89
+ Checkpoint,
90
+ CheckpointKind,
91
+ CopiedDocument,
92
+ HistoryPort,
93
+ IdentifierMap,
94
+ IdentifierStyle,
95
+ MoveResult,
96
+ MutationResult,
97
+ NodeAddress,
98
+ NodeIdentifiers,
99
+ OpenBranch,
100
+ OpenedTree,
101
+ OutlineResponse,
102
+ PLAIN_TEXT_FORMAT_ID,
103
+ QueryMatch,
104
+ SOURCE_FULL,
105
+ SOURCE_NONE,
106
+ SOURCE_PREVIEW,
107
+ StorageFacade,
108
+ inherit_ownership,
109
+ TreeDocument,
110
+ TreeWriteIntent,
111
+ WrittenPair,
112
+ apply_subtree,
113
+ copy_subtree,
114
+ count_fragment_nodes,
115
+ delete,
116
+ drill_down,
117
+ dumps,
118
+ format_capabilities,
119
+ identifier_map,
120
+ identifiers,
121
+ identity_by_path_snapshot,
122
+ insert,
123
+ edit_attributes,
124
+ edit_content,
125
+ format_hook,
126
+ list_extensions,
127
+ list_formats,
128
+ load,
129
+ loads,
130
+ move,
131
+ node_identifier,
132
+ node_ref,
133
+ node_source_text,
134
+ open_bytes,
135
+ open_file,
136
+ reference_notation,
137
+ register_format_plugin,
138
+ replace,
139
+ replace_node_id,
140
+ replace_source,
141
+ reparse,
142
+ resolve_address,
143
+ save,
144
+ set_attribute,
145
+ set_body,
146
+ set_root_trailing_separator,
147
+ write,
148
+ )
149
+ # `tree_engine.facade.query` is deliberately NOT re-exported under its own name here: binding a
150
+ # `query` ATTRIBUTE on this package would collide with the `tree_engine.query` SUBPACKAGE
151
+ # (`tree_engine.query.engine`/`.inspection`/`.outline`/`.results`) the moment anything imports it
152
+ # -- and something always does, because the import above (`from tree_engine.facade import
153
+ # node_source_text, ...`) already runs `facade.py`, which itself does
154
+ # `from tree_engine.query.engine import query as _query` at module scope. That nested import binds
155
+ # `tree_engine.query` to the SUBPACKAGE as a side effect of Python's own import machinery (a
156
+ # submodule import always sets an attribute of the same name on its parent package); rebinding
157
+ # `query` here afterwards to the facade FUNCTION would silently overwrite that, and then
158
+ # `import tree_engine.query.inspection as m` -- which resolves via attribute traversal
159
+ # (`tree_engine.query.inspection`), not via `sys.modules` -- breaks with "cannot import name
160
+ # 'inspection' from 'query'" because `tree_engine.query` is no longer a module. The facade
161
+ # function is exposed here as `run_query` instead, leaving `tree_engine.query` alone as the real
162
+ # subpackage; `tree_engine.facade.query` itself is unchanged. See
163
+ # `tests/test_tree_engine_public_import_surface.py`.
164
+ from tree_engine.facade import query as run_query
165
+
166
+ __all__ = [
167
+ # tree_engine.facade -- the single public entry point ({p037}).
168
+ "TreeDocument",
169
+ "Address",
170
+ "load",
171
+ "save",
172
+ "node_source_text",
173
+ "reparse",
174
+ "replace_source",
175
+ "identity_by_path_snapshot",
176
+ "loads",
177
+ "dumps",
178
+ "run_query",
179
+ "drill_down",
180
+ "insert",
181
+ "count_fragment_nodes",
182
+ "delete",
183
+ "replace",
184
+ "move",
185
+ "copy_subtree",
186
+ "apply_subtree",
187
+ "set_attribute",
188
+ "set_body",
189
+ "set_root_trailing_separator",
190
+ "replace_node_id",
191
+ "resolve_address",
192
+ "register_format_plugin",
193
+ "edit_attributes",
194
+ "edit_content",
195
+ "format_hook",
196
+ "list_extensions",
197
+ "list_formats",
198
+ "format_capabilities",
199
+ "open_bytes",
200
+ "open_file",
201
+ "write",
202
+ "SOURCE_NONE",
203
+ "SOURCE_PREVIEW",
204
+ "SOURCE_FULL",
205
+ "PLAIN_TEXT_FORMAT_ID",
206
+ "AddressRemap",
207
+ "ApplySubtreeResult",
208
+ "Checkpoint",
209
+ "CheckpointKind",
210
+ "CopiedDocument",
211
+ "HistoryPort",
212
+ "MoveResult",
213
+ "MutationResult",
214
+ "NodeAddress",
215
+ "OpenBranch",
216
+ "OpenedTree",
217
+ "OutlineResponse",
218
+ "QueryMatch",
219
+ "StorageFacade",
220
+ "inherit_ownership",
221
+ "TreeWriteIntent",
222
+ "WrittenPair",
223
+ "IdentifierMap",
224
+ "IdentifierStyle",
225
+ "NodeIdentifiers",
226
+ "identifier_map",
227
+ "identifiers",
228
+ "node_identifier",
229
+ "node_ref",
230
+ "reference_notation",
231
+ # tree_engine.errors -- the frozen error-code catalog ({p023}).
232
+ "ErrorCode",
233
+ "ErrorLayer",
234
+ "ERROR_CODE_LAYER",
235
+ "error_layer",
236
+ # tree_engine.exceptions -- the typed public-API exception hierarchy.
237
+ "TreeEngineException",
238
+ "CoreLayerException",
239
+ "PluginLayerException",
240
+ "StorageLayerException",
241
+ "NodeNotFound",
242
+ "NodeIdConflict",
243
+ "ShortIdConflict",
244
+ "DocumentVersionConflict",
245
+ "InvalidSelector",
246
+ "InvalidPosition",
247
+ "InvalidParentType",
248
+ "CycleDetected",
249
+ "UnresolvedReference",
250
+ "ConcurrentTreeModification",
251
+ "FormatUnknownExtension",
252
+ "FormatExtensionConflict",
253
+ "FormatPluginNotFound",
254
+ "PluginCapabilityNotSupported",
255
+ "FormatContentParseFailed",
256
+ "FormatFragmentParseFailed",
257
+ "FormatPluginContractError",
258
+ "UnsupportedTranslation",
259
+ "TreePayloadInvalid",
260
+ "TreeSchemaUnsupported",
261
+ "ChecksumMismatch",
262
+ "ConcurrentSourceModification",
263
+ "StorageIOError",
264
+ "CheckConfigInvalid",
265
+ "CheckToolCrashed",
266
+ "CheckToolMissing",
267
+ "CheckToolTimeout",
268
+ "CODE_TO_EXCEPTION",
269
+ "exception_for_code",
270
+ # distribution version ({p032}).
271
+ "__version__",
272
+ ]
273
+
274
+
275
+ def _read_distribution_version() -> str:
276
+ """Return the ``ai-editor-tree-engine`` distribution version.
277
+
278
+ Two sources, tried in THIS order -- the adjacent checkout file first, installed package
279
+ metadata second -- because a checkout is not always at the version last built into the active
280
+ venv, and the checkout is the one telling the truth about what code is actually running:
281
+
282
+ 1. The distribution's own ``VERSION`` file, the same file ``src/pyproject.toml``'s
283
+ ``[tool.setuptools.dynamic] version`` sources from, resolved next to this ``__init__.py``
284
+ (``src/tree_engine/../VERSION`` == ``src/VERSION``) -- but ONLY when a checkout marker,
285
+ ``src/pyproject.toml`` itself, sits right beside it. A bare ``VERSION`` file with no
286
+ adjacent ``pyproject.toml`` is not this distribution's checkout: ``site-packages`` is a
287
+ directory shared by every installed package, and nothing stops some unrelated package (or
288
+ a leftover build artifact) from dropping its OWN stray ``VERSION`` file at the top of it --
289
+ ``Path(__file__).resolve().parent.parent`` for an INSTALLED copy resolves to
290
+ ``site-packages`` itself, not this distribution's checkout root, so reading whatever
291
+ happens to sit there without checking whose it is would silently report a foreign version.
292
+ Present in every REAL checkout, including this repository's own ``PYTHONPATH``-based
293
+ local/CAS workflow and the CI step that imports the package straight out of ``src/`` before
294
+ it is ever built. A checkout bumped to a new ``VERSION`` while an OLDER build of the same
295
+ distribution still sits installed in the active venv must report the checkout's number, not
296
+ the stale installed one -- otherwise every check comparing ``tree_engine.__version__``
297
+ against the checkout's ``VERSION`` file (e.g. ``check_engine_public_import_surface_6e609b97``)
298
+ goes red on every version bump until the venv happens to be reinstalled.
299
+ 2. :func:`importlib.metadata.version`, when there is no adjacent, checkout-marked ``VERSION``
300
+ file to read -- the normal shape for a package installed FROM A BUILT WHEEL rather than run
301
+ out of a checkout: a wheel ships neither a ``VERSION`` file nor a ``pyproject.toml`` (only
302
+ ``tree_engine/*.py`` plus dist-info, see ``test_wheel_build_contains_tree_engine_standalone``),
303
+ so this is what a real consumer installing the published distribution actually hits.
304
+ """
305
+ from pathlib import Path
306
+
307
+ package_root = Path(__file__).resolve().parent.parent
308
+ version_file = package_root / "VERSION"
309
+ checkout_marker = package_root / "pyproject.toml"
310
+
311
+ if checkout_marker.exists():
312
+ try:
313
+ return version_file.read_text(encoding="utf-8").strip()
314
+ except OSError:
315
+ pass
316
+
317
+ try:
318
+ from importlib.metadata import version
319
+
320
+ return version("ai-editor-tree-engine")
321
+ except Exception:
322
+ pass
323
+
324
+ return "0+unknown"
325
+
326
+
327
+ __version__ = _read_distribution_version()
@@ -0,0 +1,60 @@
1
+ """``tree_engine.checks``: file checks as a library (TODO 15a86bcb).
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+
6
+ The checkers are implemented: the builtin ones (syntax, xml_wellformed, compile, docstrings, encoding, the four
7
+ fleet rules, and the format checkers csv, jsonl, sql, onec_query, bsl) and the six external tools, with the default
8
+ chain table and the chain runner (sync and async). This package is
9
+ a pure library: no database, project root, worktree or server configuration.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from tree_engine.checks.builtin.syntax import check_syntax
15
+ from tree_engine.checks.chain import (
16
+ ChainElement,
17
+ CheckChainRegistry,
18
+ default_chain_table,
19
+ run_chain,
20
+ run_chain_async,
21
+ validate_chain_mapping,
22
+ )
23
+ from tree_engine.checks.model import CheckOutcome, Diagnostic, Severity
24
+ from tree_engine.checks.plugin import CheckerMetadata, CheckerPlugin, CheckRequest
25
+ from tree_engine.checks.registry import (
26
+ checker_capabilities,
27
+ skipped_checkers,
28
+ list_checkers,
29
+ register_checker_plugin,
30
+ )
31
+ from tree_engine.exceptions import (
32
+ CheckConfigInvalid,
33
+ CheckToolCrashed,
34
+ CheckToolMissing,
35
+ CheckToolTimeout,
36
+ )
37
+
38
+ __all__ = [
39
+ "Severity",
40
+ "Diagnostic",
41
+ "CheckOutcome",
42
+ "CheckerMetadata",
43
+ "CheckRequest",
44
+ "CheckerPlugin",
45
+ "ChainElement",
46
+ "register_checker_plugin",
47
+ "list_checkers",
48
+ "checker_capabilities",
49
+ "skipped_checkers",
50
+ "check_syntax",
51
+ "validate_chain_mapping",
52
+ "CheckChainRegistry",
53
+ "default_chain_table",
54
+ "run_chain",
55
+ "run_chain_async",
56
+ "CheckToolCrashed",
57
+ "CheckToolTimeout",
58
+ "CheckToolMissing",
59
+ "CheckConfigInvalid",
60
+ ]
@@ -0,0 +1,5 @@
1
+ """Built-in checkers shipped with ``tree_engine.checks``.
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+ """
@@ -0,0 +1,53 @@
1
+ """The ``compile`` builtin checker: what ``compile()`` rejects after the parser accepted (group G4).
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+
6
+ ``return`` outside a function, ``await`` outside an async function and similar errors are found by
7
+ the compiler, not the parser. The code is compiled, never executed.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import List
13
+
14
+ from tree_engine.checks.model import Diagnostic, Severity
15
+ from tree_engine.checks.plugin import CheckerMetadata, CheckerPlugin, CheckRequest, KIND_BUILTIN
16
+
17
+ __all__ = ["CompileChecker"]
18
+
19
+
20
+ class CompileChecker(CheckerPlugin):
21
+ """Reports the ``SyntaxError`` / ``ValueError`` of ``compile(source, path, "exec")``."""
22
+
23
+ _METADATA = CheckerMetadata(
24
+ check_id="compile",
25
+ kind=KIND_BUILTIN,
26
+ contract_version="1",
27
+ file_extensions=(".py",),
28
+ format_ids=("python",),
29
+ )
30
+
31
+ @property
32
+ def metadata(self) -> CheckerMetadata:
33
+ return self._METADATA
34
+
35
+ def check(self, request: CheckRequest) -> List[Diagnostic]:
36
+ try:
37
+ compile(request.source, request.path or "<string>", "exec", dont_inherit=True)
38
+ except (SyntaxError, ValueError) as exc:
39
+ line = getattr(exc, "lineno", None)
40
+ column = getattr(exc, "offset", None)
41
+ message = getattr(exc, "msg", None) or str(exc)
42
+ return [
43
+ Diagnostic(
44
+ tool="compile",
45
+ code="COMPILE-SYNTAX" if isinstance(exc, SyntaxError) else "COMPILE-VALUE",
46
+ severity=Severity.ERROR,
47
+ message=str(message),
48
+ path=request.path,
49
+ line=line if isinstance(line, int) and line >= 1 else 1,
50
+ column=column if isinstance(column, int) and column >= 1 else 1,
51
+ )
52
+ ]
53
+ return []
@@ -0,0 +1,51 @@
1
+ """The ``csv_syntax`` builtin checker: can the file be read as csv (decision D-CC, owner order 2026-11-04).
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+
6
+ Declared by the csv format plugin through ``checker_plugin``; the registry finds it by itself. Findings are
7
+ ``SYNTAX-CSV``: an unterminated quoted field or text after a closing quote, positioned at that construct, and
8
+ invalid UTF-8, positioned at the first bad byte (1-based line and column, D-BM).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import List
14
+
15
+ from tree_engine.checks.model import Diagnostic, Severity
16
+ from tree_engine.checks.plugin import CheckerMetadata, CheckerPlugin, CheckRequest, KIND_BUILTIN
17
+ from tree_engine.plugins.csv_format import csv_failure
18
+
19
+ __all__ = ["CsvSyntaxChecker"]
20
+
21
+
22
+ class CsvSyntaxChecker(CheckerPlugin):
23
+ """Reports the first reason a csv file cannot be parsed."""
24
+
25
+ _METADATA = CheckerMetadata(
26
+ check_id="csv_syntax",
27
+ kind=KIND_BUILTIN,
28
+ contract_version="1",
29
+ file_extensions=(".csv",),
30
+ format_ids=("csv",),
31
+ )
32
+
33
+ @property
34
+ def metadata(self) -> CheckerMetadata:
35
+ return self._METADATA
36
+
37
+ def check(self, request: CheckRequest) -> List[Diagnostic]:
38
+ failure = csv_failure(request.source)
39
+ if failure is None:
40
+ return []
41
+ return [
42
+ Diagnostic(
43
+ tool="csv_syntax",
44
+ code="SYNTAX-CSV",
45
+ severity=Severity.ERROR,
46
+ message=failure["message"],
47
+ path=request.path,
48
+ line=failure["line"],
49
+ column=failure["column"],
50
+ )
51
+ ]