@gate-forge/pack-sqlalchemy 0.24.0 → 0.25.1
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.
package/dist/detector.js
CHANGED
|
@@ -294,11 +294,17 @@ export function createSqlalchemyDetector(options = {}) {
|
|
|
294
294
|
},
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
-
/**
|
|
297
|
+
/**
|
|
298
|
+
* Categories this detector derives internal claims for. The first three are
|
|
299
|
+
* entry points that reach a writer of the table. `unreferenced` is a table
|
|
300
|
+
* that no serving module names; granting it trusts only alembic-shaped
|
|
301
|
+
* revision modules as operator code, because they are not read for it.
|
|
302
|
+
*/
|
|
298
303
|
const INTERNAL_ENTRY_CATEGORIES = {
|
|
299
304
|
migration: true,
|
|
300
305
|
'maintenance-command': true,
|
|
301
306
|
worker: true,
|
|
307
|
+
unreferenced: true,
|
|
302
308
|
};
|
|
303
309
|
/**
|
|
304
310
|
* The internal entry-point categories the trusted policy grants this detector
|
package/dist/detector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,aAAa,GAId,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,GAKpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,WA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AAC;QACzF,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,KAAK,cAAc;YAAE,SAAS;QAChD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,yBAAyB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,sDAAsD,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,0FAA0F;AAC1F,SAAS,aAAa,CAAC,IAAuB,EAAE,UAA6B;IAC3E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,IAAI,EAAE,+BAA+B,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,qDAAqD;AACrD,SAAS,WAAW,CAAC,KAAgB;IACnC,OAAO,KAAK,KAAK,gBAAgB,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gate-forge/pack-sqlalchemy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "SQLAlchemy CRUD discovery pack: AST-only python detector (GPP/3), in-process TS discover entry, configurable plane mapping, entity-adapter schema.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"test": "vitest run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@gate-forge/core": "^0.
|
|
33
|
-
"@gate-forge/plugin-protocol": "^0.
|
|
32
|
+
"@gate-forge/core": "^0.25.1",
|
|
33
|
+
"@gate-forge/plugin-protocol": "^0.25.1",
|
|
34
34
|
"yaml": "^2.8.1",
|
|
35
35
|
"zod": "^4.1.5"
|
|
36
36
|
},
|
|
@@ -16,8 +16,9 @@ Usage:
|
|
|
16
16
|
# root: scan root (default: process cwd, which the CLI sets to the
|
|
17
17
|
# repo root); every discover path resolves under it.
|
|
18
18
|
# --internal-entry-categories=LIST: comma list of migration,
|
|
19
|
-
# maintenance-command, worker; the host passes the
|
|
20
|
-
#
|
|
19
|
+
# maintenance-command, worker, unreferenced; the host passes the
|
|
20
|
+
# trusted internal categories it grants. Absent: no internal claims
|
|
21
|
+
# are derived.
|
|
21
22
|
"""
|
|
22
23
|
|
|
23
24
|
from __future__ import annotations
|
|
@@ -35,7 +36,7 @@ except ImportError: # monorepo bootstrap: ../plugin-protocol/python
|
|
|
35
36
|
from gateforge_sqlalchemy_detector import PLUGIN_ID, VERSION
|
|
36
37
|
|
|
37
38
|
|
|
38
|
-
_ENTRY_CATEGORIES = ("migration", "maintenance-command", "worker")
|
|
39
|
+
_ENTRY_CATEGORIES = ("migration", "maintenance-command", "worker", "unreferenced")
|
|
39
40
|
_CATEGORY_FLAG = "--internal-entry-categories="
|
|
40
41
|
_scan_root: Path | None = None
|
|
41
42
|
_categories: tuple[str, ...] = ()
|
|
@@ -4,6 +4,10 @@ A table is internal for an entry-point category when an entry point of that
|
|
|
4
4
|
category reaches a writer of the table. Every list below is closed: a shape
|
|
5
5
|
that is not named gives no edge and no writer, and so no signal.
|
|
6
6
|
|
|
7
|
+
The ``unreferenced`` category is no entry-point category. It is derived from a
|
|
8
|
+
whole-scan reference check (``_References``): a table that no serving module
|
|
9
|
+
names can be written by no request.
|
|
10
|
+
|
|
7
11
|
The walk works on ``ast`` only. Nothing here imports or runs the scanned code.
|
|
8
12
|
"""
|
|
9
13
|
|
|
@@ -11,12 +15,21 @@ from __future__ import annotations
|
|
|
11
15
|
|
|
12
16
|
import ast
|
|
13
17
|
import re
|
|
14
|
-
from collections import Counter
|
|
18
|
+
from collections import Counter, defaultdict
|
|
15
19
|
|
|
16
20
|
from . import PLUGIN_ID
|
|
17
21
|
from .scan import _module_to_relpath, _signal, loc
|
|
18
22
|
|
|
19
23
|
SA_MODULES = frozenset({"sqlalchemy", "sqlalchemy.orm"})
|
|
24
|
+
TABLE_NAMES = frozenset({"Table", "table"})
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _in_sa_family(module):
|
|
28
|
+
"""D2: the root is ``sqlmodel`` or contains ``alchemy`` (sqlalchemy, flask_sqlalchemy, geoalchemy2, ...)."""
|
|
29
|
+
root = module.split(".")[0]
|
|
30
|
+
return root == "sqlmodel" or "alchemy" in root
|
|
31
|
+
|
|
32
|
+
|
|
20
33
|
# A `__main__` block that reaches one of these starts a server: no entry point.
|
|
21
34
|
SERVER_NAMES = frozenset({"run", "serve", "serve_forever"})
|
|
22
35
|
WRITE_CALLS = frozenset({"insert", "update", "delete"})
|
|
@@ -29,10 +42,30 @@ LITERAL_WRITE = re.compile(
|
|
|
29
42
|
re.IGNORECASE,
|
|
30
43
|
)
|
|
31
44
|
SCOPE_NODES = (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Lambda)
|
|
45
|
+
# Decorators that hand a method to no other code. Any other decorator inside a
|
|
46
|
+
# table class counts as a reference to that class.
|
|
47
|
+
INERT_DECORATORS = frozenset({
|
|
48
|
+
"property", "classmethod", "staticmethod", "hybrid_property", "hybrid_method",
|
|
49
|
+
"validates", "declared_attr", "reconstructor",
|
|
50
|
+
})
|
|
51
|
+
INERT_ACCESSORS = frozenset({"setter", "expression", "deleter"})
|
|
52
|
+
# Attributes that walk the mapper or metadata registry: a table reached that way is named nowhere.
|
|
53
|
+
REGISTRY_ATTRS = frozenset({"sorted_tables", "mappers", "_class_registry", "__subclasses__"})
|
|
54
|
+
WORD = re.compile(r"[A-Za-z0-9_]+")
|
|
55
|
+
DOTTED_HEAD = re.compile(r"[A-Za-z0-9_.]+")
|
|
56
|
+
FORMAT_FIELD = re.compile(r"\{[^{}]*\}|%(?:\(\w*\))?[A-Za-z]")
|
|
57
|
+
# An inserting statement whose target holds an interpolation (``\0`` in a
|
|
58
|
+
# ``_template`` text), anchored like LITERAL_WRITE. A computed schema before a
|
|
59
|
+
# literal table is no match: the literal names the table.
|
|
60
|
+
COMPUTED_WRITE = re.compile(
|
|
61
|
+
r'^\s*(?:INSERT\s+INTO|MERGE\s+INTO|\\?COPY)\s+'
|
|
62
|
+
r'(?:[\w"\0]+\s*\.\s*)*[\w"]*\0[\w"\0]*(?![\w"\0]|\s*\.)',
|
|
63
|
+
re.IGNORECASE,
|
|
64
|
+
)
|
|
32
65
|
|
|
33
66
|
|
|
34
|
-
def reachability_signals(indexes, trees, tables, categories):
|
|
35
|
-
"""Derives one ``internality`` signal per (table,
|
|
67
|
+
def reachability_signals(indexes, trees, tables, categories, others, root):
|
|
68
|
+
"""Derives one ``internality`` signal per (table, category) that holds.
|
|
36
69
|
|
|
37
70
|
Args:
|
|
38
71
|
indexes: ``{relpath: FileIndex}`` for every scanned, non-test file.
|
|
@@ -40,13 +73,22 @@ def reachability_signals(indexes, trees, tables, categories):
|
|
|
40
73
|
tables: ``[(relpath, class_qname_or_None, table_name)]`` for every
|
|
41
74
|
table resource: a declarative class (qname set) or a ``Table()``
|
|
42
75
|
call (qname None).
|
|
43
|
-
categories: The
|
|
44
|
-
``
|
|
76
|
+
categories: The categories to derive, a subset of ``migration``,
|
|
77
|
+
``maintenance-command``, ``worker`` and ``unreferenced``. The
|
|
78
|
+
first three give a signal at each entry point that reaches a
|
|
79
|
+
writer of the table. ``unreferenced`` gives a signal at the
|
|
80
|
+
definition of each table that no serving module names; granting
|
|
81
|
+
it trusts only alembic-shaped revision modules as operator code,
|
|
82
|
+
and scripts are serving code (see ``_References``). A run void for it
|
|
83
|
+
gives non-certifying signals naming each construct instead.
|
|
84
|
+
others: Relpaths of the non-test inputs that are not in ``indexes``.
|
|
85
|
+
Read as bytes, and only for ``unreferenced``.
|
|
86
|
+
root: The scan root ``others`` resolve under.
|
|
45
87
|
|
|
46
88
|
Returns:
|
|
47
89
|
list[dict]: ``ClassificationSignal`` documents (unsorted).
|
|
48
90
|
"""
|
|
49
|
-
return _Walker(indexes, trees, tables).signals(categories)
|
|
91
|
+
return _Walker(indexes, trees, tables).signals(categories, others, root)
|
|
50
92
|
|
|
51
93
|
|
|
52
94
|
def _own_nodes(stmts):
|
|
@@ -116,6 +158,26 @@ def _has_revision(tree):
|
|
|
116
158
|
return False
|
|
117
159
|
|
|
118
160
|
|
|
161
|
+
def _is_alembic_revision(tree):
|
|
162
|
+
"""True for an alembic-shaped revision module.
|
|
163
|
+
|
|
164
|
+
Four module-level facts: a string ``revision``, a ``down_revision``
|
|
165
|
+
binding, ``def upgrade``, and ``import alembic`` or ``from alembic import ...``.
|
|
166
|
+
"""
|
|
167
|
+
down = upgrade = imported = False
|
|
168
|
+
for stmt in tree.body:
|
|
169
|
+
if isinstance(stmt, (ast.Assign, ast.AnnAssign)) and stmt.value is not None:
|
|
170
|
+
targets = stmt.targets if isinstance(stmt, ast.Assign) else [stmt.target]
|
|
171
|
+
down = down or any(isinstance(t, ast.Name) and t.id == "down_revision" for t in targets)
|
|
172
|
+
elif isinstance(stmt, ast.FunctionDef):
|
|
173
|
+
upgrade = upgrade or stmt.name == "upgrade"
|
|
174
|
+
elif isinstance(stmt, ast.Import):
|
|
175
|
+
imported = imported or any(alias.name == "alembic" for alias in stmt.names)
|
|
176
|
+
elif isinstance(stmt, ast.ImportFrom):
|
|
177
|
+
imported = imported or (stmt.level == 0 and stmt.module == "alembic")
|
|
178
|
+
return down and upgrade and imported and _has_revision(tree)
|
|
179
|
+
|
|
180
|
+
|
|
119
181
|
def _is_celery_class_call(node, imports):
|
|
120
182
|
"""True for a call to ``celery.Celery``, however celery was imported."""
|
|
121
183
|
if not isinstance(node, ast.Call):
|
|
@@ -200,9 +262,9 @@ def _table_key(table):
|
|
|
200
262
|
return (table[0], table[1] or "", table[2])
|
|
201
263
|
|
|
202
264
|
|
|
203
|
-
def _table_signal(table,
|
|
265
|
+
def _table_signal(table, assertion, location, basis="code-positive"):
|
|
204
266
|
relpath, symbol, name = table
|
|
205
|
-
signal = _signal("internality",
|
|
267
|
+
signal = _signal("internality", assertion, basis, PLUGIN_ID, location, name, symbol)
|
|
206
268
|
if symbol is not None:
|
|
207
269
|
# A declarative class target carries its symbol only: the bare table
|
|
208
270
|
# name would bind the signal to every same-named table in the scan.
|
|
@@ -210,6 +272,92 @@ def _table_signal(table, category, location):
|
|
|
210
272
|
return signal
|
|
211
273
|
|
|
212
274
|
|
|
275
|
+
def _inert_decorator(dec):
|
|
276
|
+
target = dec.func if isinstance(dec, ast.Call) else dec
|
|
277
|
+
if isinstance(target, ast.Name):
|
|
278
|
+
return target.id in INERT_DECORATORS
|
|
279
|
+
return isinstance(target, ast.Attribute) and target.attr in INERT_ACCESSORS
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _binds_all(stmt):
|
|
283
|
+
"""True for a statement that binds ``__all__``."""
|
|
284
|
+
if isinstance(stmt, ast.Assign):
|
|
285
|
+
targets = stmt.targets
|
|
286
|
+
elif isinstance(stmt, (ast.AnnAssign, ast.AugAssign)):
|
|
287
|
+
targets = [stmt.target]
|
|
288
|
+
else:
|
|
289
|
+
return False
|
|
290
|
+
return any(isinstance(t, ast.Name) and t.id == "__all__" for t in targets)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _template(node):
|
|
294
|
+
"""The text of a string expression, with ``\\0`` for each part that is computed.
|
|
295
|
+
|
|
296
|
+
F-strings and ``+`` chains are flattened left to right. A ``{...}`` or
|
|
297
|
+
``%s`` field in a literal part is computed too: ``.format`` or ``%`` fills
|
|
298
|
+
it later, wherever that happens.
|
|
299
|
+
"""
|
|
300
|
+
parts, stack = [], [node]
|
|
301
|
+
while stack:
|
|
302
|
+
cur = stack.pop()
|
|
303
|
+
text = _str_const(cur)
|
|
304
|
+
if text is not None:
|
|
305
|
+
parts.append(FORMAT_FIELD.sub("\0", text))
|
|
306
|
+
elif isinstance(cur, ast.JoinedStr):
|
|
307
|
+
stack.extend(reversed(cur.values))
|
|
308
|
+
elif isinstance(cur, ast.BinOp) and isinstance(cur.op, ast.Add):
|
|
309
|
+
stack.extend((cur.right, cur.left))
|
|
310
|
+
else:
|
|
311
|
+
parts.append("\0")
|
|
312
|
+
return "".join(parts)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _dotted_suffixes(rel):
|
|
316
|
+
"""Every dotted name a scanned file can be imported under.
|
|
317
|
+
|
|
318
|
+
The relation of ``_module_to_relpath``, without its one-match rule: for an
|
|
319
|
+
exemption or a guard, an ambiguous name has to count for every file.
|
|
320
|
+
"""
|
|
321
|
+
parts = rel[: -len(".py")].split("/")
|
|
322
|
+
if parts[-1] == "__init__":
|
|
323
|
+
parts.pop()
|
|
324
|
+
return [".".join(parts[i:]) for i in range(len(parts))]
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _importable(node):
|
|
328
|
+
"""Dotted names a node may import: an import's modules, or the dotted head of a string.
|
|
329
|
+
|
|
330
|
+
A string counts for its head when it ends there or goes on with ``:``
|
|
331
|
+
(``"pkg.mod:app"``), and for every shorter prefix that ends before a ``.``.
|
|
332
|
+
"""
|
|
333
|
+
if isinstance(node, ast.Import):
|
|
334
|
+
texts = [alias.name for alias in node.names]
|
|
335
|
+
elif isinstance(node, ast.ImportFrom):
|
|
336
|
+
base = node.module or ""
|
|
337
|
+
texts = [f"{base}.{alias.name}".lstrip(".") for alias in node.names]
|
|
338
|
+
if node.level:
|
|
339
|
+
# The package a relative import resolves under is unknown: every name it mentions counts.
|
|
340
|
+
texts += [*base.split("."), *(alias.name for alias in node.names)]
|
|
341
|
+
else:
|
|
342
|
+
text = _str_const(node)
|
|
343
|
+
texts = [] if text is None else [text]
|
|
344
|
+
for text in texts:
|
|
345
|
+
match = DOTTED_HEAD.match(text)
|
|
346
|
+
if match is None:
|
|
347
|
+
continue
|
|
348
|
+
head = match.group()
|
|
349
|
+
yield from (head[:i] for i, char in enumerate(head) if char == ".")
|
|
350
|
+
if match.end() == len(text) or text[match.end()] == ":":
|
|
351
|
+
yield head
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _note(index, token, where):
|
|
355
|
+
"""Adds ``where`` to the entry of ``token``; an index holds only the tokens asked for."""
|
|
356
|
+
entry = index.get(token)
|
|
357
|
+
if entry is not None:
|
|
358
|
+
entry.add(where)
|
|
359
|
+
|
|
360
|
+
|
|
213
361
|
class _Walker:
|
|
214
362
|
"""Resolves entry points, call edges and writers over one scan's indexes."""
|
|
215
363
|
|
|
@@ -441,6 +589,59 @@ class _Walker:
|
|
|
441
589
|
return True
|
|
442
590
|
return False
|
|
443
591
|
|
|
592
|
+
def _is_functools_wraps(self, rel, dec):
|
|
593
|
+
"""True for a ``functools.wraps(...)`` or ``wraps(...)`` decorator call, functools being the import."""
|
|
594
|
+
if not isinstance(dec, ast.Call):
|
|
595
|
+
return False
|
|
596
|
+
func = dec.func
|
|
597
|
+
if isinstance(func, ast.Attribute) and func.attr == "wraps" and isinstance(func.value, ast.Name):
|
|
598
|
+
ref = self.indexes[rel].imports.get(func.value.id)
|
|
599
|
+
return ref is not None and ref.level == 0 and ref.module == "functools" and ref.name is None
|
|
600
|
+
if isinstance(func, ast.Name):
|
|
601
|
+
ref = self.indexes[rel].imports.get(func.id)
|
|
602
|
+
return ref is not None and ref.level == 0 and ref.module == "functools" and ref.name == "wraps"
|
|
603
|
+
return False
|
|
604
|
+
|
|
605
|
+
def _decorator_bodies(self, rel, fdef, seen):
|
|
606
|
+
"""Wrapper bodies that module-level decorators of ``fdef`` return and ``seen`` has not yet met.
|
|
607
|
+
|
|
608
|
+
``@F(...)`` follows two nested returns (F returns D, D returns the wrapper); ``@F`` and
|
|
609
|
+
``@mod.F`` follow one (F returns the wrapper). Each returning body is a single
|
|
610
|
+
``return <name>`` of a def bound once in its own scope; each returned def may carry
|
|
611
|
+
only ``functools.wraps`` decorators. Anything else yields no edge.
|
|
612
|
+
"""
|
|
613
|
+
bodies = []
|
|
614
|
+
for dec in fdef.decorator_list:
|
|
615
|
+
factory = isinstance(dec, ast.Call)
|
|
616
|
+
callee = self._callee(rel, dec if factory else ast.Call(func=dec, args=[], keywords=[]))
|
|
617
|
+
if callee is None:
|
|
618
|
+
continue
|
|
619
|
+
frel, fname = callee
|
|
620
|
+
outer, scope = None, self.funcs[frel][fname]
|
|
621
|
+
for _ in range(2 if factory else 1):
|
|
622
|
+
own = list(_own_nodes(scope.body))
|
|
623
|
+
returns = [node for node in own if isinstance(node, ast.Return)]
|
|
624
|
+
if len(returns) != 1 or not isinstance(returns[0].value, ast.Name):
|
|
625
|
+
break
|
|
626
|
+
name = returns[0].value.id
|
|
627
|
+
defs = [
|
|
628
|
+
node
|
|
629
|
+
for node in own
|
|
630
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name == name
|
|
631
|
+
]
|
|
632
|
+
if _bound_count(own, name) != 1 or len(defs) != 1:
|
|
633
|
+
break
|
|
634
|
+
nested = defs[0]
|
|
635
|
+
if not all(self._is_functools_wraps(frel, d) for d in nested.decorator_list):
|
|
636
|
+
break
|
|
637
|
+
outer, scope = scope, nested
|
|
638
|
+
else:
|
|
639
|
+
key = (frel, f"{outer.name}.<wrapper>@{scope.lineno}")
|
|
640
|
+
if key not in seen:
|
|
641
|
+
seen.add(key)
|
|
642
|
+
bodies.append((frel, list(_own_nodes(scope.body)), scope))
|
|
643
|
+
return bodies
|
|
644
|
+
|
|
444
645
|
def _closure(self, rel, stmts, fn):
|
|
445
646
|
"""The entry body plus every module-level body it reaches, in BFS order.
|
|
446
647
|
|
|
@@ -450,6 +651,7 @@ class _Walker:
|
|
|
450
651
|
seen = set()
|
|
451
652
|
if fn is not None:
|
|
452
653
|
seen.add((rel, fn.name))
|
|
654
|
+
bodies.extend(self._decorator_bodies(rel, fn, seen))
|
|
453
655
|
index = 0
|
|
454
656
|
while index < len(bodies):
|
|
455
657
|
cur_rel, own, _ = bodies[index]
|
|
@@ -464,6 +666,7 @@ class _Walker:
|
|
|
464
666
|
crel, cname = callee
|
|
465
667
|
cfn = self.funcs[crel][cname]
|
|
466
668
|
bodies.append((crel, list(_own_nodes(cfn.body)), cfn))
|
|
669
|
+
bodies.extend(self._decorator_bodies(crel, cfn, seen))
|
|
467
670
|
return bodies
|
|
468
671
|
|
|
469
672
|
def _starts_server(self, bodies):
|
|
@@ -500,9 +703,12 @@ class _Walker:
|
|
|
500
703
|
found.sort(key=lambda e: (e[0], e[1].lineno, e[1].col_offset))
|
|
501
704
|
return found
|
|
502
705
|
|
|
503
|
-
def signals(self, categories):
|
|
706
|
+
def signals(self, categories, others, root):
|
|
504
707
|
out = []
|
|
505
708
|
for category in sorted(set(categories)):
|
|
709
|
+
if category == "unreferenced":
|
|
710
|
+
out.extend(_References(self, others, root).signals())
|
|
711
|
+
continue
|
|
506
712
|
emitted = set()
|
|
507
713
|
for rel, node, bodies in self._entries(category):
|
|
508
714
|
tables = set()
|
|
@@ -514,3 +720,238 @@ class _Walker:
|
|
|
514
720
|
emitted.add(table)
|
|
515
721
|
out.append(_table_signal(table, category, loc(rel, node)))
|
|
516
722
|
return out
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
class _References:
|
|
726
|
+
"""Finds the tables no serving module names (the ``unreferenced`` category).
|
|
727
|
+
|
|
728
|
+
A statement that creates a row names its table where it is built: by class
|
|
729
|
+
symbol, by ``Table`` variable or by table-name text. A table that no
|
|
730
|
+
serving module names is therefore written by no request.
|
|
731
|
+
|
|
732
|
+
A reference to a target is a ``Name`` or attribute equal to its symbol, an
|
|
733
|
+
import of the symbol under another name, or a string that holds the symbol
|
|
734
|
+
or the table name as a word (any letter case). A non-Python input counts
|
|
735
|
+
for the table name as a word. Not references: the nodes of the target's
|
|
736
|
+
own class, the ``Table(...)`` call's own name, docstrings and other bare
|
|
737
|
+
strings, and the ``__all__`` value.
|
|
738
|
+
|
|
739
|
+
Operator-only modules are skipped, for references and for the guard:
|
|
740
|
+
alembic-shaped revision modules (``_is_alembic_revision``) that no other
|
|
741
|
+
scanned module imports or names in a string. Every other module is
|
|
742
|
+
serving code, scripts included: nothing in the scan shows what launches one.
|
|
743
|
+
|
|
744
|
+
The guard: a construct that can reach a table without naming it (see
|
|
745
|
+
``_visit``) voids the run. A void run emits no ``unreferenced`` signal; it
|
|
746
|
+
gives each target nothing names one non-certifying signal per construct
|
|
747
|
+
(``signals``), so the core can name the construct but never certify.
|
|
748
|
+
"""
|
|
749
|
+
|
|
750
|
+
def __init__(self, walker, others, root):
|
|
751
|
+
self.walker = walker
|
|
752
|
+
self.void = [] # (relpath, node, construct kind) per construct that can reach a table unnamed
|
|
753
|
+
self._bindings_by_rel = {} # file -> (import bindings, other binding counts, star import)
|
|
754
|
+
self.classes = {} # a target's ClassDef -> its symbol
|
|
755
|
+
self.own = set() # ids of a Table() target's own binding name and name argument
|
|
756
|
+
self.targets = self._targets()
|
|
757
|
+
# token -> where it is named: a target's ClassDef, or None for anywhere else.
|
|
758
|
+
self.idents = {symbol: set() for _, symbol, _ in self.targets}
|
|
759
|
+
self.words = {word.lower(): set() for table, symbol, _ in self.targets for word in (symbol, table[2])}
|
|
760
|
+
self.modules = {name for rel in walker.trees for name in _dotted_suffixes(rel)}
|
|
761
|
+
operator_only = self._operator_only()
|
|
762
|
+
for rel, tree in walker.trees.items():
|
|
763
|
+
if rel not in operator_only:
|
|
764
|
+
self._read(rel, tree)
|
|
765
|
+
names = {table[2].lower() for table, _, _ in self.targets}
|
|
766
|
+
# Without a target there is no signal to withhold: the other inputs stay unread.
|
|
767
|
+
for rel in others if names else ():
|
|
768
|
+
# latin-1 maps every byte to one character, so ASCII words survive any encoding.
|
|
769
|
+
text = (root / rel).read_bytes().decode("latin-1").lower()
|
|
770
|
+
for name in names.intersection(WORD.findall(text)):
|
|
771
|
+
self.words[name].add(None)
|
|
772
|
+
|
|
773
|
+
def _targets(self):
|
|
774
|
+
"""``(table, symbol, definition)`` for each table a signal can name, in table order.
|
|
775
|
+
|
|
776
|
+
A declarative class goes by its simple name. A ``Table()`` call goes by
|
|
777
|
+
the one module-level name bound to it, and only when no other table
|
|
778
|
+
shares its table name: its signal carries the bare name. A symbol or
|
|
779
|
+
table name that is not a plain ASCII word is left out.
|
|
780
|
+
"""
|
|
781
|
+
walker = self.walker
|
|
782
|
+
named = Counter(table[2] for table in walker.tables)
|
|
783
|
+
found = []
|
|
784
|
+
for table in sorted(set(walker.tables), key=_table_key):
|
|
785
|
+
rel, qname, name = table
|
|
786
|
+
if qname is not None:
|
|
787
|
+
node = next(rec.node for rec in walker.indexes[rel].classes if rec.qname == qname)
|
|
788
|
+
symbol, own = qname.rsplit(".", 1)[-1], ()
|
|
789
|
+
elif named[name] == 1:
|
|
790
|
+
node = next(call["node"] for call in walker.indexes[rel].table_calls if call["table_name"] == name)
|
|
791
|
+
bound = [
|
|
792
|
+
stmt.targets[0]
|
|
793
|
+
for stmt in walker.trees[rel].body
|
|
794
|
+
if isinstance(stmt, ast.Assign)
|
|
795
|
+
and stmt.value is node
|
|
796
|
+
and len(stmt.targets) == 1
|
|
797
|
+
and isinstance(stmt.targets[0], ast.Name)
|
|
798
|
+
]
|
|
799
|
+
if not bound or walker.module_bound[rel][bound[0].id] != 1:
|
|
800
|
+
continue
|
|
801
|
+
symbol, own = bound[0].id, (id(bound[0]), id(node.args[0]))
|
|
802
|
+
else:
|
|
803
|
+
continue
|
|
804
|
+
if WORD.fullmatch(symbol) is None or WORD.fullmatch(name) is None:
|
|
805
|
+
continue
|
|
806
|
+
if qname is not None:
|
|
807
|
+
self.classes[node] = symbol
|
|
808
|
+
self.own.update(own)
|
|
809
|
+
found.append((table, symbol, node))
|
|
810
|
+
return found
|
|
811
|
+
|
|
812
|
+
def _operator_only(self):
|
|
813
|
+
"""Alembic-shaped revision modules that no other module imports or names in a string."""
|
|
814
|
+
walker = self.walker
|
|
815
|
+
candidates = {rel: _dotted_suffixes(rel) for rel, tree in walker.trees.items() if _is_alembic_revision(tree)}
|
|
816
|
+
namers = {name: set() for names in candidates.values() for name in names}
|
|
817
|
+
for rel, tree in walker.trees.items():
|
|
818
|
+
for node in ast.walk(tree):
|
|
819
|
+
if isinstance(node, (ast.Import, ast.ImportFrom, ast.Constant)):
|
|
820
|
+
for name in _importable(node):
|
|
821
|
+
_note(namers, name, rel)
|
|
822
|
+
return {rel for rel, names in candidates.items() if not any(namers[name] - {rel} for name in names)}
|
|
823
|
+
|
|
824
|
+
def _read(self, rel, tree):
|
|
825
|
+
"""Notes one serving module's names and string words, each with the target class it sits in."""
|
|
826
|
+
stack = [(stmt, None) for stmt in tree.body if not _binds_all(stmt)]
|
|
827
|
+
while stack:
|
|
828
|
+
node, region = stack.pop()
|
|
829
|
+
if id(node) in self.own or (isinstance(node, ast.Expr) and _str_const(node.value) is not None):
|
|
830
|
+
continue
|
|
831
|
+
decorators = getattr(node, "decorator_list", [])
|
|
832
|
+
if region is None and node in self.classes:
|
|
833
|
+
# A decorator hands the class to other code, which then holds it unnamed.
|
|
834
|
+
if decorators:
|
|
835
|
+
self.idents[self.classes[node]].add(None)
|
|
836
|
+
stack.extend((child, None if child in decorators else node) for child in ast.iter_child_nodes(node))
|
|
837
|
+
continue
|
|
838
|
+
if region is not None and not all(_inert_decorator(dec) for dec in decorators):
|
|
839
|
+
# The same for a method: its body may build the class's rows without a name.
|
|
840
|
+
self.idents[self.classes[region]].add(None)
|
|
841
|
+
self._visit(rel, node, region)
|
|
842
|
+
stack.extend((child, region) for child in ast.iter_child_nodes(node))
|
|
843
|
+
|
|
844
|
+
def _visit(self, rel, node, region):
|
|
845
|
+
"""Notes the reference one node makes; records in ``void`` a construct that can reach a table unnamed."""
|
|
846
|
+
text = _str_const(node)
|
|
847
|
+
if isinstance(node, ast.Name):
|
|
848
|
+
_note(self.idents, node.id, region)
|
|
849
|
+
elif isinstance(node, ast.Attribute):
|
|
850
|
+
_note(self.idents, node.attr, region)
|
|
851
|
+
if node.attr in REGISTRY_ATTRS or (node.attr == "tables" and _final_name(node.value) == "metadata"):
|
|
852
|
+
self.void.append((rel, node, "registry-walk"))
|
|
853
|
+
elif isinstance(node, ast.alias) and node.asname is not None:
|
|
854
|
+
# ``from models import Row as R``: the uses then say ``R``, never ``Row``.
|
|
855
|
+
_note(self.idents, node.name, region)
|
|
856
|
+
elif isinstance(node, ast.Call):
|
|
857
|
+
kind = self._computed_lookup(rel, node)
|
|
858
|
+
if kind is not None:
|
|
859
|
+
self.void.append((rel, node, kind))
|
|
860
|
+
elif text is not None:
|
|
861
|
+
for word in WORD.findall(text.lower()):
|
|
862
|
+
_note(self.words, word, region)
|
|
863
|
+
if isinstance(node, (ast.Constant, ast.JoinedStr, ast.BinOp)) and COMPUTED_WRITE.match(_template(node)):
|
|
864
|
+
self.void.append((rel, node, "computed-write"))
|
|
865
|
+
|
|
866
|
+
def _bindings(self, rel, name):
|
|
867
|
+
"""The import bindings of ``name`` in ``rel``, as ``(module, imported, level)``, and how many other bindings it has.
|
|
868
|
+
|
|
869
|
+
One walk per file. Parameters count as other bindings. A star import
|
|
870
|
+
binds names the walk cannot see, so it counts for every name.
|
|
871
|
+
"""
|
|
872
|
+
if rel not in self._bindings_by_rel:
|
|
873
|
+
imports, others, star = defaultdict(list), Counter(), False
|
|
874
|
+
for node in ast.walk(self.walker.trees[rel]):
|
|
875
|
+
if isinstance(node, ast.Import):
|
|
876
|
+
for alias in node.names:
|
|
877
|
+
head = alias.name.split(".")[0]
|
|
878
|
+
imports[alias.asname or head].append((alias.name if alias.asname else head, None, 0))
|
|
879
|
+
elif isinstance(node, ast.ImportFrom):
|
|
880
|
+
star = star or any(alias.name == "*" for alias in node.names)
|
|
881
|
+
for alias in node.names:
|
|
882
|
+
if alias.name != "*":
|
|
883
|
+
imports[alias.asname or alias.name].append((node.module or "", alias.name, node.level))
|
|
884
|
+
elif isinstance(node, ast.arg):
|
|
885
|
+
others[node.arg] += 1
|
|
886
|
+
else:
|
|
887
|
+
others.update(_bound_names([node]))
|
|
888
|
+
self._bindings_by_rel[rel] = (imports, others, star)
|
|
889
|
+
imports, others, star = self._bindings_by_rel[rel]
|
|
890
|
+
return imports.get(name, []), others[name] + int(star)
|
|
891
|
+
|
|
892
|
+
def _may_be_scanned(self, dotted):
|
|
893
|
+
"""True when a scanned module is ``dotted`` or one of its dotted prefixes: it could re-export SQLAlchemy's Table."""
|
|
894
|
+
parts = dotted.split(".")
|
|
895
|
+
return any(".".join(parts[:i]) in self.modules for i in range(1, len(parts) + 1))
|
|
896
|
+
|
|
897
|
+
def _table_callee(self, rel, func):
|
|
898
|
+
"""``sqlalchemy``, ``foreign`` or ``unknown`` for a callee that may build a table; None for any other callee.
|
|
899
|
+
|
|
900
|
+
D1=a, D2=a. ``sqlalchemy``: an absolute import of the callee's root name
|
|
901
|
+
from the SQLAlchemy family names ``Table`` or ``table`` (a bare callee)
|
|
902
|
+
or the callee's final name is one of them (an attribute). ``foreign``:
|
|
903
|
+
the root is bound only by absolute imports outside the family that no
|
|
904
|
+
scanned module can re-export. ``unknown``: anything else.
|
|
905
|
+
"""
|
|
906
|
+
final = _final_name(func)
|
|
907
|
+
root = func
|
|
908
|
+
while isinstance(root, ast.Attribute):
|
|
909
|
+
root = root.value
|
|
910
|
+
if not isinstance(root, ast.Name):
|
|
911
|
+
return "unknown" if final in TABLE_NAMES else None
|
|
912
|
+
imports, others = self._bindings(rel, root.id)
|
|
913
|
+
bare = isinstance(func, ast.Name)
|
|
914
|
+
if any(
|
|
915
|
+
level == 0 and _in_sa_family(module) and ((imported in TABLE_NAMES) if bare else (final in TABLE_NAMES))
|
|
916
|
+
for module, imported, level in imports
|
|
917
|
+
):
|
|
918
|
+
return "sqlalchemy"
|
|
919
|
+
if final not in TABLE_NAMES:
|
|
920
|
+
return None
|
|
921
|
+
foreign = all(
|
|
922
|
+
level == 0
|
|
923
|
+
and not _in_sa_family(module)
|
|
924
|
+
and not self._may_be_scanned(f"{module}.{imported}" if imported else module)
|
|
925
|
+
for module, imported, level in imports
|
|
926
|
+
)
|
|
927
|
+
return "foreign" if imports and not others and foreign else "unknown"
|
|
928
|
+
|
|
929
|
+
def _computed_lookup(self, rel, call):
|
|
930
|
+
"""The construct kind of a table constructor (``_table_callee``) with a non-literal first argument, ``computed-table``, or of ``getattr(<scanned module>, <non-literal>)``, ``module-getattr``; None otherwise."""
|
|
931
|
+
func, args = call.func, call.args
|
|
932
|
+
if self._table_callee(rel, func) in ("sqlalchemy", "unknown"):
|
|
933
|
+
return "computed-table" if args and _str_const(args[0]) is None else None
|
|
934
|
+
if not (isinstance(func, ast.Name) and func.id == "getattr" and len(args) >= 2 and isinstance(args[0], ast.Name)):
|
|
935
|
+
return None
|
|
936
|
+
ref = self.walker.indexes[rel].imports.get(args[0].id)
|
|
937
|
+
if ref is None or _str_const(args[1]) is not None:
|
|
938
|
+
return None
|
|
939
|
+
module = ref.module if ref.name is None else f"{ref.module}.{ref.name}".lstrip(".")
|
|
940
|
+
return "module-getattr" if module in self.modules else None
|
|
941
|
+
|
|
942
|
+
def signals(self):
|
|
943
|
+
"""One signal per target nothing names, at its definition. A void run gives each such target one non-certifying signal per construct instead."""
|
|
944
|
+
sites = {}
|
|
945
|
+
for rel, node, kind in self.void:
|
|
946
|
+
sites.setdefault((rel, node.lineno, kind), node)
|
|
947
|
+
out = []
|
|
948
|
+
for table, symbol, node in self.targets:
|
|
949
|
+
named = self.idents[symbol] | self.words[symbol.lower()] | self.words[table[2].lower()]
|
|
950
|
+
if named - {node}:
|
|
951
|
+
continue
|
|
952
|
+
if not sites:
|
|
953
|
+
out.append(_table_signal(table, "unreferenced", loc(table[0], node)))
|
|
954
|
+
for key in sorted(sites):
|
|
955
|
+
assertion = {"voidCategory": "unreferenced", "construct": key[2]}
|
|
956
|
+
out.append(_table_signal(table, assertion, loc(key[0], sites[key]), "code-negative-closed-world"))
|
|
957
|
+
return out
|
|
@@ -1966,6 +1966,9 @@ def scan(
|
|
|
1966
1966
|
{rel: idx.tree for rel, idx in indexes.items()},
|
|
1967
1967
|
table_refs,
|
|
1968
1968
|
categories,
|
|
1969
|
+
# Inputs that are not parsed Python can still name a table.
|
|
1970
|
+
[path for path in relpaths if path not in indexes and not _is_test_path(path)],
|
|
1971
|
+
base,
|
|
1969
1972
|
)
|
|
1970
1973
|
)
|
|
1971
1974
|
|