codeanalyzer-python 0.3.0__py3-none-any.whl → 0.3.1__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.
@@ -1,245 +0,0 @@
1
- ################################################################################
2
- # Copyright IBM Corporation 2025
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- ################################################################################
16
-
17
- """The declarative Neo4j schema catalog — the single in-repo source of truth for
18
- the graph contract (node labels, their keys and typed properties, relationship
19
- types and their endpoints). ``--emit schema`` serializes this (with the DDL from
20
- :mod:`codeanalyzer.neo4j.schema`) to a machine-readable ``schema.json``, and the
21
- conformance test (``test/test_neo4j_schema.py``) asserts the real emitter never
22
- produces a label / relationship / property that isn't declared here — so this
23
- file cannot silently drift from :mod:`codeanalyzer.neo4j.project`.
24
-
25
- SCHEMA_VERSION is the contract version: bump MAJOR on a breaking change
26
- (renamed/removed label, relationship or key), MINOR on an additive change (new
27
- label/rel/property). It is stamped onto the ``:PyApplication`` node of every
28
- emitted graph so any consumer can detect a producer/consumer mismatch at runtime.
29
- """
30
- from __future__ import annotations
31
-
32
- from dataclasses import dataclass, field
33
- from typing import Dict, List
34
-
35
- from codeanalyzer.neo4j.schema import CONSTRAINTS, INDEXES
36
-
37
- SCHEMA_VERSION = "1.1.0"
38
-
39
- # PropType ∈ {"string", "integer", "float", "boolean", "string[]", "integer[]"}.
40
-
41
-
42
- @dataclass
43
- class NodeLabel:
44
- label: str # the specific label (also the catalog key)
45
- merge_label: str # the label the uniqueness constraint / MERGE is on
46
- key: str
47
- properties: Dict[str, str]
48
-
49
-
50
- @dataclass
51
- class RelType:
52
- type: str
53
- from_labels: List[str]
54
- to_labels: List[str]
55
- properties: Dict[str, str] = field(default_factory=dict)
56
-
57
-
58
- # Labels layered onto a node in addition to its primary/specific label.
59
- MARKER_LABELS: List[str] = []
60
-
61
- _SPAN = {"start_line": "integer", "end_line": "integer"}
62
-
63
-
64
- NODE_LABELS: List[NodeLabel] = [
65
- NodeLabel(
66
- "PyApplication",
67
- "PyApplication",
68
- "name",
69
- {"name": "string", "schema_version": "string"},
70
- ),
71
- NodeLabel(
72
- "PyModule",
73
- "PyModule",
74
- "file_key",
75
- {
76
- "file_key": "string",
77
- "module_name": "string",
78
- "content_hash": "string",
79
- "last_modified": "float",
80
- "file_size": "integer",
81
- "_module": "string",
82
- },
83
- ),
84
- NodeLabel(
85
- "PyClass",
86
- "PySymbol",
87
- "signature",
88
- {
89
- "signature": "string",
90
- "name": "string",
91
- "code": "string",
92
- "base_classes": "string[]",
93
- "docstring": "string",
94
- **_SPAN,
95
- "_module": "string",
96
- },
97
- ),
98
- NodeLabel(
99
- "PyCallable",
100
- "PySymbol",
101
- "signature",
102
- {
103
- "signature": "string",
104
- "name": "string",
105
- "path": "string",
106
- "return_type": "string",
107
- "cyclomatic_complexity": "integer",
108
- "code": "string",
109
- "code_start_line": "integer",
110
- **_SPAN,
111
- "docstring": "string",
112
- "decorators": "string[]",
113
- "parameters_json": "string",
114
- "accessed_symbols_json": "string",
115
- "_module": "string",
116
- },
117
- ),
118
- NodeLabel(
119
- "PyExternal",
120
- "PySymbol",
121
- "signature",
122
- {"signature": "string", "name": "string", "module": "string"},
123
- ),
124
- NodeLabel("PyPackage", "PyPackage", "name", {"name": "string"}),
125
- NodeLabel(
126
- "PyDecorator",
127
- "PyDecorator",
128
- "name",
129
- {"name": "string"},
130
- ),
131
- NodeLabel(
132
- "PyCallSite",
133
- "PyCallSite",
134
- "id",
135
- {
136
- "id": "string",
137
- "method_name": "string",
138
- "receiver_expr": "string",
139
- "receiver_type": "string",
140
- "argument_types": "string[]",
141
- "return_type": "string",
142
- "callee_signature": "string",
143
- "is_constructor_call": "boolean",
144
- "start_line": "integer",
145
- "start_column": "integer",
146
- "end_line": "integer",
147
- "end_column": "integer",
148
- "_module": "string",
149
- },
150
- ),
151
- NodeLabel(
152
- "PyAttribute",
153
- "PyAttribute",
154
- "id",
155
- {
156
- "id": "string",
157
- "name": "string",
158
- "type": "string",
159
- "docstring": "string",
160
- **_SPAN,
161
- "_module": "string",
162
- },
163
- ),
164
- NodeLabel(
165
- "PyVariable",
166
- "PyVariable",
167
- "id",
168
- {
169
- "id": "string",
170
- "name": "string",
171
- "type": "string",
172
- "initializer": "string",
173
- "scope": "string",
174
- **_SPAN,
175
- "_module": "string",
176
- },
177
- ),
178
- ]
179
-
180
- _DECL_TARGETS = ["PyClass", "PyCallable"]
181
-
182
-
183
- REL_TYPES: List[RelType] = [
184
- RelType("PY_HAS_MODULE", ["PyApplication"], ["PyModule"]),
185
- RelType("PY_DECLARES", ["PyModule", "PyClass", "PyCallable"], _DECL_TARGETS),
186
- RelType("PY_HAS_METHOD", ["PyClass"], ["PyCallable"]),
187
- RelType("PY_HAS_ATTRIBUTE", ["PyClass"], ["PyAttribute"]),
188
- RelType("PY_DECLARES_VAR", ["PyModule", "PyCallable"], ["PyVariable"]),
189
- RelType("PY_HAS_CALLSITE", ["PyCallable"], ["PyCallSite"]),
190
- RelType("PY_RESOLVES_TO", ["PyCallSite"], ["PyCallable", "PyExternal"]),
191
- RelType(
192
- "PY_CALLS",
193
- ["PyCallable", "PyExternal"],
194
- ["PyCallable", "PyExternal"],
195
- {"weight": "integer", "provenance": "string[]"},
196
- ),
197
- RelType("PY_EXTENDS", ["PyClass"], ["PyClass"]),
198
- RelType(
199
- "PY_IMPORTS",
200
- ["PyModule"],
201
- ["PyPackage"],
202
- {"imported_names": "string[]", "aliases": "string[]"},
203
- ),
204
- RelType("PY_DECORATED_BY", ["PyCallable"], ["PyDecorator"]),
205
- ]
206
-
207
-
208
- @dataclass
209
- class SchemaDocument:
210
- schema_version: str
211
- generator: str
212
- marker_labels: List[str]
213
- node_labels: List[NodeLabel]
214
- relationship_types: List[RelType]
215
- constraints: List[str]
216
- indexes: List[str]
217
-
218
-
219
- def build_schema_document() -> dict:
220
- """Build the full machine-readable schema document emitted by ``--emit schema``."""
221
- return {
222
- "schema_version": SCHEMA_VERSION,
223
- "generator": "codeanalyzer-python",
224
- "marker_labels": list(MARKER_LABELS),
225
- "node_labels": [
226
- {
227
- "label": n.label,
228
- "merge_label": n.merge_label,
229
- "key": n.key,
230
- "properties": n.properties,
231
- }
232
- for n in NODE_LABELS
233
- ],
234
- "relationship_types": [
235
- {
236
- "type": r.type,
237
- "from": r.from_labels,
238
- "to": r.to_labels,
239
- "properties": r.properties,
240
- }
241
- for r in REL_TYPES
242
- ],
243
- "constraints": list(CONSTRAINTS),
244
- "indexes": list(INDEXES),
245
- }