@gate-forge/pack-sqlalchemy 0.23.0 → 0.25.0

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
- /** Entry-point categories this detector derives internal claims for. */
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
@@ -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,WAAW,EAAE,MAAM,cAAc,CAAC;AAE1E,yEAAyE;AACzE,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,C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,IAAI,KAAK,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;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.23.0",
3
+ "version": "0.25.0",
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.23.0",
33
- "@gate-forge/plugin-protocol": "^0.23.0",
32
+ "@gate-forge/core": "^0.25.0",
33
+ "@gate-forge/plugin-protocol": "^0.25.0",
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 trusted internal
20
- # entry points it grants. Absent: no internal claims are derived.
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
 
@@ -29,10 +33,30 @@ LITERAL_WRITE = re.compile(
29
33
  re.IGNORECASE,
30
34
  )
31
35
  SCOPE_NODES = (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Lambda)
36
+ # Decorators that hand a method to no other code. Any other decorator inside a
37
+ # table class counts as a reference to that class.
38
+ INERT_DECORATORS = frozenset({
39
+ "property", "classmethod", "staticmethod", "hybrid_property", "hybrid_method",
40
+ "validates", "declared_attr", "reconstructor",
41
+ })
42
+ INERT_ACCESSORS = frozenset({"setter", "expression", "deleter"})
43
+ # Attributes that walk the mapper or metadata registry: a table reached that way is named nowhere.
44
+ REGISTRY_ATTRS = frozenset({"sorted_tables", "mappers", "_class_registry", "__subclasses__"})
45
+ WORD = re.compile(r"[A-Za-z0-9_]+")
46
+ DOTTED_HEAD = re.compile(r"[A-Za-z0-9_.]+")
47
+ FORMAT_FIELD = re.compile(r"\{[^{}]*\}|%(?:\(\w*\))?[A-Za-z]")
48
+ # An inserting statement whose target holds an interpolation (``\0`` in a
49
+ # ``_template`` text), anchored like LITERAL_WRITE. A computed schema before a
50
+ # literal table is no match: the literal names the table.
51
+ COMPUTED_WRITE = re.compile(
52
+ r'^\s*(?:INSERT\s+INTO|MERGE\s+INTO|\\?COPY)\s+'
53
+ r'(?:[\w"\0]+\s*\.\s*)*[\w"]*\0[\w"\0]*(?![\w"\0]|\s*\.)',
54
+ re.IGNORECASE,
55
+ )
32
56
 
33
57
 
34
- def reachability_signals(indexes, trees, tables, categories):
35
- """Derives one ``internality`` signal per (table, entry category) reached.
58
+ def reachability_signals(indexes, trees, tables, categories, others, root):
59
+ """Derives one ``internality`` signal per (table, category) that holds.
36
60
 
37
61
  Args:
38
62
  indexes: ``{relpath: FileIndex}`` for every scanned, non-test file.
@@ -40,13 +64,21 @@ def reachability_signals(indexes, trees, tables, categories):
40
64
  tables: ``[(relpath, class_qname_or_None, table_name)]`` for every
41
65
  table resource: a declarative class (qname set) or a ``Table()``
42
66
  call (qname None).
43
- categories: The entry-point categories to derive, a subset of
44
- ``migration``, ``maintenance-command`` and ``worker``.
67
+ categories: The categories to derive, a subset of ``migration``,
68
+ ``maintenance-command``, ``worker`` and ``unreferenced``. The
69
+ first three give a signal at each entry point that reaches a
70
+ writer of the table. ``unreferenced`` gives a signal at the
71
+ definition of each table that no serving module names; granting
72
+ it trusts only alembic-shaped revision modules as operator code,
73
+ and scripts are serving code (see ``_References``).
74
+ others: Relpaths of the non-test inputs that are not in ``indexes``.
75
+ Read as bytes, and only for ``unreferenced``.
76
+ root: The scan root ``others`` resolve under.
45
77
 
46
78
  Returns:
47
79
  list[dict]: ``ClassificationSignal`` documents (unsorted).
48
80
  """
49
- return _Walker(indexes, trees, tables).signals(categories)
81
+ return _Walker(indexes, trees, tables).signals(categories, others, root)
50
82
 
51
83
 
52
84
  def _own_nodes(stmts):
@@ -116,6 +148,26 @@ def _has_revision(tree):
116
148
  return False
117
149
 
118
150
 
151
+ def _is_alembic_revision(tree):
152
+ """True for an alembic-shaped revision module.
153
+
154
+ Four module-level facts: a string ``revision``, a ``down_revision``
155
+ binding, ``def upgrade``, and ``import alembic`` or ``from alembic import ...``.
156
+ """
157
+ down = upgrade = imported = False
158
+ for stmt in tree.body:
159
+ if isinstance(stmt, (ast.Assign, ast.AnnAssign)) and stmt.value is not None:
160
+ targets = stmt.targets if isinstance(stmt, ast.Assign) else [stmt.target]
161
+ down = down or any(isinstance(t, ast.Name) and t.id == "down_revision" for t in targets)
162
+ elif isinstance(stmt, ast.FunctionDef):
163
+ upgrade = upgrade or stmt.name == "upgrade"
164
+ elif isinstance(stmt, ast.Import):
165
+ imported = imported or any(alias.name == "alembic" for alias in stmt.names)
166
+ elif isinstance(stmt, ast.ImportFrom):
167
+ imported = imported or (stmt.level == 0 and stmt.module == "alembic")
168
+ return down and upgrade and imported and _has_revision(tree)
169
+
170
+
119
171
  def _is_celery_class_call(node, imports):
120
172
  """True for a call to ``celery.Celery``, however celery was imported."""
121
173
  if not isinstance(node, ast.Call):
@@ -188,6 +240,14 @@ def _binding_source(own, name):
188
240
  return None
189
241
 
190
242
 
243
+ def _is_cursor(own, fn, name):
244
+ """True when ``name`` is bound exactly once in the scope, to ``X.cursor()``, and is no parameter."""
245
+ if _bound_count(own, name) != 1 or any(p.arg == name for p in _param_nodes(fn)):
246
+ return False
247
+ source = _binding_source(own, name)
248
+ return isinstance(source, ast.Call) and isinstance(source.func, ast.Attribute) and source.func.attr == "cursor"
249
+
250
+
191
251
  def _table_key(table):
192
252
  return (table[0], table[1] or "", table[2])
193
253
 
@@ -202,6 +262,92 @@ def _table_signal(table, category, location):
202
262
  return signal
203
263
 
204
264
 
265
+ def _inert_decorator(dec):
266
+ target = dec.func if isinstance(dec, ast.Call) else dec
267
+ if isinstance(target, ast.Name):
268
+ return target.id in INERT_DECORATORS
269
+ return isinstance(target, ast.Attribute) and target.attr in INERT_ACCESSORS
270
+
271
+
272
+ def _binds_all(stmt):
273
+ """True for a statement that binds ``__all__``."""
274
+ if isinstance(stmt, ast.Assign):
275
+ targets = stmt.targets
276
+ elif isinstance(stmt, (ast.AnnAssign, ast.AugAssign)):
277
+ targets = [stmt.target]
278
+ else:
279
+ return False
280
+ return any(isinstance(t, ast.Name) and t.id == "__all__" for t in targets)
281
+
282
+
283
+ def _template(node):
284
+ """The text of a string expression, with ``\\0`` for each part that is computed.
285
+
286
+ F-strings and ``+`` chains are flattened left to right. A ``{...}`` or
287
+ ``%s`` field in a literal part is computed too: ``.format`` or ``%`` fills
288
+ it later, wherever that happens.
289
+ """
290
+ parts, stack = [], [node]
291
+ while stack:
292
+ cur = stack.pop()
293
+ text = _str_const(cur)
294
+ if text is not None:
295
+ parts.append(FORMAT_FIELD.sub("\0", text))
296
+ elif isinstance(cur, ast.JoinedStr):
297
+ stack.extend(reversed(cur.values))
298
+ elif isinstance(cur, ast.BinOp) and isinstance(cur.op, ast.Add):
299
+ stack.extend((cur.right, cur.left))
300
+ else:
301
+ parts.append("\0")
302
+ return "".join(parts)
303
+
304
+
305
+ def _dotted_suffixes(rel):
306
+ """Every dotted name a scanned file can be imported under.
307
+
308
+ The relation of ``_module_to_relpath``, without its one-match rule: for an
309
+ exemption or a guard, an ambiguous name has to count for every file.
310
+ """
311
+ parts = rel[: -len(".py")].split("/")
312
+ if parts[-1] == "__init__":
313
+ parts.pop()
314
+ return [".".join(parts[i:]) for i in range(len(parts))]
315
+
316
+
317
+ def _importable(node):
318
+ """Dotted names a node may import: an import's modules, or the dotted head of a string.
319
+
320
+ A string counts for its head when it ends there or goes on with ``:``
321
+ (``"pkg.mod:app"``), and for every shorter prefix that ends before a ``.``.
322
+ """
323
+ if isinstance(node, ast.Import):
324
+ texts = [alias.name for alias in node.names]
325
+ elif isinstance(node, ast.ImportFrom):
326
+ base = node.module or ""
327
+ texts = [f"{base}.{alias.name}".lstrip(".") for alias in node.names]
328
+ if node.level:
329
+ # The package a relative import resolves under is unknown: every name it mentions counts.
330
+ texts += [*base.split("."), *(alias.name for alias in node.names)]
331
+ else:
332
+ text = _str_const(node)
333
+ texts = [] if text is None else [text]
334
+ for text in texts:
335
+ match = DOTTED_HEAD.match(text)
336
+ if match is None:
337
+ continue
338
+ head = match.group()
339
+ yield from (head[:i] for i, char in enumerate(head) if char == ".")
340
+ if match.end() == len(text) or text[match.end()] == ":":
341
+ yield head
342
+
343
+
344
+ def _note(index, token, where):
345
+ """Adds ``where`` to the entry of ``token``; an index holds only the tokens asked for."""
346
+ entry = index.get(token)
347
+ if entry is not None:
348
+ entry.add(where)
349
+
350
+
205
351
  class _Walker:
206
352
  """Resolves entry points, call edges and writers over one scan's indexes."""
207
353
 
@@ -293,9 +439,20 @@ class _Walker:
293
439
  return hits[0] if len(hits) == 1 else None
294
440
 
295
441
  def _table_of(self, rel, own, fn, node):
296
- """The table an expression denotes: a model, ``M.__table__``, or ``table("lit")``."""
442
+ """The table an expression denotes.
443
+
444
+ A model, ``M.__table__``, ``table("lit")``, or a name bound exactly
445
+ once in the function to ``table("lit")``.
446
+ """
297
447
  if isinstance(node, ast.Name):
298
- return self._class_table(rel, node.id)
448
+ is_param = any(p.arg == node.id for p in _param_nodes(fn))
449
+ source = _binding_source(own, node.id)
450
+ if not is_param and source is None:
451
+ return self._class_table(rel, node.id)
452
+ # A parameter or a plain binding in this scope decides, not a model of that name.
453
+ if fn is None or is_param or _bound_count(own, node.id) != 1 or not isinstance(source, ast.Call):
454
+ return None
455
+ return self._table_of(rel, own, fn, source)
299
456
  if isinstance(node, ast.Attribute) and node.attr == "__table__" and isinstance(node.value, ast.Name):
300
457
  return self._class_table(rel, node.value.id)
301
458
  if isinstance(node, ast.Call) and self._sa_symbol(rel, node.func, own, fn) == "table" and node.args:
@@ -365,7 +522,7 @@ class _Walker:
365
522
  return []
366
523
 
367
524
  def _method_writes(self, rel, own, fn, call):
368
- """Writes made by a method call: ``X.__table__.insert()``, alembic ops and session adds."""
525
+ """Writes made by a method call: ``X.__table__.insert()``, alembic ops, cursor literals and session adds."""
369
526
  func = call.func
370
527
  if func.attr in WRITE_CALLS and isinstance(func.value, ast.Attribute) and func.value.attr == "__table__":
371
528
  return _listed(self._table_of(rel, own, fn, func.value))
@@ -375,6 +532,8 @@ class _Walker:
375
532
  return _listed(self._table_of(rel, own, fn, call.args[0]))
376
533
  if func.attr == "execute" and self._is_alembic_op(rel, func.value):
377
534
  return self._literal_write(_str_const(call.args[0]))
535
+ if func.attr == "execute" and isinstance(func.value, ast.Name) and _is_cursor(own, fn, func.value.id):
536
+ return self._literal_write(_str_const(call.args[0]))
378
537
  if (
379
538
  func.attr in SESSION_ADD_CALLS
380
539
  and isinstance(func.value, ast.Name)
@@ -420,6 +579,59 @@ class _Walker:
420
579
  return True
421
580
  return False
422
581
 
582
+ def _is_functools_wraps(self, rel, dec):
583
+ """True for a ``functools.wraps(...)`` or ``wraps(...)`` decorator call, functools being the import."""
584
+ if not isinstance(dec, ast.Call):
585
+ return False
586
+ func = dec.func
587
+ if isinstance(func, ast.Attribute) and func.attr == "wraps" and isinstance(func.value, ast.Name):
588
+ ref = self.indexes[rel].imports.get(func.value.id)
589
+ return ref is not None and ref.level == 0 and ref.module == "functools" and ref.name is None
590
+ if isinstance(func, ast.Name):
591
+ ref = self.indexes[rel].imports.get(func.id)
592
+ return ref is not None and ref.level == 0 and ref.module == "functools" and ref.name == "wraps"
593
+ return False
594
+
595
+ def _decorator_bodies(self, rel, fdef, seen):
596
+ """Wrapper bodies that module-level decorators of ``fdef`` return and ``seen`` has not yet met.
597
+
598
+ ``@F(...)`` follows two nested returns (F returns D, D returns the wrapper); ``@F`` and
599
+ ``@mod.F`` follow one (F returns the wrapper). Each returning body is a single
600
+ ``return <name>`` of a def bound once in its own scope; each returned def may carry
601
+ only ``functools.wraps`` decorators. Anything else yields no edge.
602
+ """
603
+ bodies = []
604
+ for dec in fdef.decorator_list:
605
+ factory = isinstance(dec, ast.Call)
606
+ callee = self._callee(rel, dec if factory else ast.Call(func=dec, args=[], keywords=[]))
607
+ if callee is None:
608
+ continue
609
+ frel, fname = callee
610
+ outer, scope = None, self.funcs[frel][fname]
611
+ for _ in range(2 if factory else 1):
612
+ own = list(_own_nodes(scope.body))
613
+ returns = [node for node in own if isinstance(node, ast.Return)]
614
+ if len(returns) != 1 or not isinstance(returns[0].value, ast.Name):
615
+ break
616
+ name = returns[0].value.id
617
+ defs = [
618
+ node
619
+ for node in own
620
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name == name
621
+ ]
622
+ if _bound_count(own, name) != 1 or len(defs) != 1:
623
+ break
624
+ nested = defs[0]
625
+ if not all(self._is_functools_wraps(frel, d) for d in nested.decorator_list):
626
+ break
627
+ outer, scope = scope, nested
628
+ else:
629
+ key = (frel, f"{outer.name}.<wrapper>@{scope.lineno}")
630
+ if key not in seen:
631
+ seen.add(key)
632
+ bodies.append((frel, list(_own_nodes(scope.body)), scope))
633
+ return bodies
634
+
423
635
  def _closure(self, rel, stmts, fn):
424
636
  """The entry body plus every module-level body it reaches, in BFS order.
425
637
 
@@ -429,6 +641,7 @@ class _Walker:
429
641
  seen = set()
430
642
  if fn is not None:
431
643
  seen.add((rel, fn.name))
644
+ bodies.extend(self._decorator_bodies(rel, fn, seen))
432
645
  index = 0
433
646
  while index < len(bodies):
434
647
  cur_rel, own, _ = bodies[index]
@@ -443,6 +656,7 @@ class _Walker:
443
656
  crel, cname = callee
444
657
  cfn = self.funcs[crel][cname]
445
658
  bodies.append((crel, list(_own_nodes(cfn.body)), cfn))
659
+ bodies.extend(self._decorator_bodies(crel, cfn, seen))
446
660
  return bodies
447
661
 
448
662
  def _starts_server(self, bodies):
@@ -479,9 +693,12 @@ class _Walker:
479
693
  found.sort(key=lambda e: (e[0], e[1].lineno, e[1].col_offset))
480
694
  return found
481
695
 
482
- def signals(self, categories):
696
+ def signals(self, categories, others, root):
483
697
  out = []
484
698
  for category in sorted(set(categories)):
699
+ if category == "unreferenced":
700
+ out.extend(_References(self, others, root).signals())
701
+ continue
485
702
  emitted = set()
486
703
  for rel, node, bodies in self._entries(category):
487
704
  tables = set()
@@ -493,3 +710,164 @@ class _Walker:
493
710
  emitted.add(table)
494
711
  out.append(_table_signal(table, category, loc(rel, node)))
495
712
  return out
713
+
714
+
715
+ class _References:
716
+ """Finds the tables no serving module names (the ``unreferenced`` category).
717
+
718
+ A statement that creates a row names its table where it is built: by class
719
+ symbol, by ``Table`` variable or by table-name text. A table that no
720
+ serving module names is therefore written by no request.
721
+
722
+ A reference to a target is a ``Name`` or attribute equal to its symbol, an
723
+ import of the symbol under another name, or a string that holds the symbol
724
+ or the table name as a word (any letter case). A non-Python input counts
725
+ for the table name as a word. Not references: the nodes of the target's
726
+ own class, the ``Table(...)`` call's own name, docstrings and other bare
727
+ strings, and the ``__all__`` value.
728
+
729
+ Operator-only modules are skipped, for references and for the guard:
730
+ alembic-shaped revision modules (``_is_alembic_revision``) that no other
731
+ scanned module imports or names in a string. Every other module is
732
+ serving code, scripts included: nothing in the scan shows what launches one.
733
+
734
+ The guard: one construct that can reach a table without naming it (see
735
+ ``_visit``) voids every signal of the run.
736
+ """
737
+
738
+ def __init__(self, walker, others, root):
739
+ self.walker = walker
740
+ self.void = False
741
+ self.classes = {} # a target's ClassDef -> its symbol
742
+ self.own = set() # ids of a Table() target's own binding name and name argument
743
+ self.targets = self._targets()
744
+ # token -> where it is named: a target's ClassDef, or None for anywhere else.
745
+ self.idents = {symbol: set() for _, symbol, _ in self.targets}
746
+ self.words = {word.lower(): set() for table, symbol, _ in self.targets for word in (symbol, table[2])}
747
+ self.modules = {name for rel in walker.trees for name in _dotted_suffixes(rel)}
748
+ operator_only = self._operator_only()
749
+ for rel, tree in walker.trees.items():
750
+ if rel not in operator_only:
751
+ self._read(rel, tree)
752
+ names = {table[2].lower() for table, _, _ in self.targets}
753
+ # Without a target there is no signal to withhold: the other inputs stay unread.
754
+ for rel in others if names else ():
755
+ # latin-1 maps every byte to one character, so ASCII words survive any encoding.
756
+ text = (root / rel).read_bytes().decode("latin-1").lower()
757
+ for name in names.intersection(WORD.findall(text)):
758
+ self.words[name].add(None)
759
+
760
+ def _targets(self):
761
+ """``(table, symbol, definition)`` for each table a signal can name, in table order.
762
+
763
+ A declarative class goes by its simple name. A ``Table()`` call goes by
764
+ the one module-level name bound to it, and only when no other table
765
+ shares its table name: its signal carries the bare name. A symbol or
766
+ table name that is not a plain ASCII word is left out.
767
+ """
768
+ walker = self.walker
769
+ named = Counter(table[2] for table in walker.tables)
770
+ found = []
771
+ for table in sorted(set(walker.tables), key=_table_key):
772
+ rel, qname, name = table
773
+ if qname is not None:
774
+ node = next(rec.node for rec in walker.indexes[rel].classes if rec.qname == qname)
775
+ symbol, own = qname.rsplit(".", 1)[-1], ()
776
+ elif named[name] == 1:
777
+ node = next(call["node"] for call in walker.indexes[rel].table_calls if call["table_name"] == name)
778
+ bound = [
779
+ stmt.targets[0]
780
+ for stmt in walker.trees[rel].body
781
+ if isinstance(stmt, ast.Assign)
782
+ and stmt.value is node
783
+ and len(stmt.targets) == 1
784
+ and isinstance(stmt.targets[0], ast.Name)
785
+ ]
786
+ if not bound or walker.module_bound[rel][bound[0].id] != 1:
787
+ continue
788
+ symbol, own = bound[0].id, (id(bound[0]), id(node.args[0]))
789
+ else:
790
+ continue
791
+ if WORD.fullmatch(symbol) is None or WORD.fullmatch(name) is None:
792
+ continue
793
+ if qname is not None:
794
+ self.classes[node] = symbol
795
+ self.own.update(own)
796
+ found.append((table, symbol, node))
797
+ return found
798
+
799
+ def _operator_only(self):
800
+ """Alembic-shaped revision modules that no other module imports or names in a string."""
801
+ walker = self.walker
802
+ candidates = {rel: _dotted_suffixes(rel) for rel, tree in walker.trees.items() if _is_alembic_revision(tree)}
803
+ namers = {name: set() for names in candidates.values() for name in names}
804
+ for rel, tree in walker.trees.items():
805
+ for node in ast.walk(tree):
806
+ if isinstance(node, (ast.Import, ast.ImportFrom, ast.Constant)):
807
+ for name in _importable(node):
808
+ _note(namers, name, rel)
809
+ return {rel for rel, names in candidates.items() if not any(namers[name] - {rel} for name in names)}
810
+
811
+ def _read(self, rel, tree):
812
+ """Notes one serving module's names and string words, each with the target class it sits in."""
813
+ stack = [(stmt, None) for stmt in tree.body if not _binds_all(stmt)]
814
+ while stack:
815
+ node, region = stack.pop()
816
+ if id(node) in self.own or (isinstance(node, ast.Expr) and _str_const(node.value) is not None):
817
+ continue
818
+ decorators = getattr(node, "decorator_list", [])
819
+ if region is None and node in self.classes:
820
+ # A decorator hands the class to other code, which then holds it unnamed.
821
+ if decorators:
822
+ self.idents[self.classes[node]].add(None)
823
+ stack.extend((child, None if child in decorators else node) for child in ast.iter_child_nodes(node))
824
+ continue
825
+ if region is not None and not all(_inert_decorator(dec) for dec in decorators):
826
+ # The same for a method: its body may build the class's rows without a name.
827
+ self.idents[self.classes[region]].add(None)
828
+ self._visit(rel, node, region)
829
+ stack.extend((child, region) for child in ast.iter_child_nodes(node))
830
+
831
+ def _visit(self, rel, node, region):
832
+ """Notes the reference one node makes; sets ``void`` when it can reach a table unnamed."""
833
+ text = _str_const(node)
834
+ if isinstance(node, ast.Name):
835
+ _note(self.idents, node.id, region)
836
+ elif isinstance(node, ast.Attribute):
837
+ _note(self.idents, node.attr, region)
838
+ if node.attr in REGISTRY_ATTRS or (node.attr == "tables" and _final_name(node.value) == "metadata"):
839
+ self.void = True
840
+ elif isinstance(node, ast.alias) and node.asname is not None:
841
+ # ``from models import Row as R``: the uses then say ``R``, never ``Row``.
842
+ _note(self.idents, node.name, region)
843
+ elif isinstance(node, ast.Call) and self._computed_lookup(rel, node):
844
+ self.void = True
845
+ elif text is not None:
846
+ for word in WORD.findall(text.lower()):
847
+ _note(self.words, word, region)
848
+ if isinstance(node, (ast.Constant, ast.JoinedStr, ast.BinOp)) and COMPUTED_WRITE.match(_template(node)):
849
+ self.void = True
850
+
851
+ def _computed_lookup(self, rel, call):
852
+ """True for ``table(<non-literal>)``, ``Table(<non-literal>, ...)`` and ``getattr(<scanned module>, <non-literal>)``."""
853
+ func, args = call.func, call.args
854
+ if _final_name(func) in ("table", "Table"):
855
+ return bool(args) and _str_const(args[0]) is None
856
+ if not (isinstance(func, ast.Name) and func.id == "getattr" and len(args) >= 2 and isinstance(args[0], ast.Name)):
857
+ return False
858
+ ref = self.walker.indexes[rel].imports.get(args[0].id)
859
+ if ref is None or _str_const(args[1]) is not None:
860
+ return False
861
+ module = ref.module if ref.name is None else f"{ref.module}.{ref.name}".lstrip(".")
862
+ return module in self.modules
863
+
864
+ def signals(self):
865
+ """One signal per target nothing names, at its definition; none when the run is void."""
866
+ if self.void:
867
+ return []
868
+ out = []
869
+ for table, symbol, node in self.targets:
870
+ named = self.idents[symbol] | self.words[symbol.lower()] | self.words[table[2].lower()]
871
+ if not named - {node}:
872
+ out.append(_table_signal(table, "unreferenced", loc(table[0], node)))
873
+ 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