erdify 1.4.1__tar.gz → 1.4.2__tar.gz
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.
- {erdify-1.4.1 → erdify-1.4.2}/PKG-INFO +1 -1
- {erdify-1.4.1 → erdify-1.4.2}/pyproject.toml +1 -1
- {erdify-1.4.1 → erdify-1.4.2}/pyproject.toml.orig +1 -1
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/aliases.py +84 -25
- {erdify-1.4.1 → erdify-1.4.2}/LICENSE +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/README.md +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/__init__.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/__main__.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/cli.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/config.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/generator.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/inject.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/__init__.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/annotations.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/common.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/core.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/__init__.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/annotated.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/base.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/django.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/keyless.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/dialects/sqlalchemy.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/discovery.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/parser/inheritance.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/py.typed +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/pyproject.py +0 -0
- {erdify-1.4.1 → erdify-1.4.2}/src/erdify/sql_parser.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: erdify
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.2
|
|
4
4
|
Summary: A zero-dependency ERD generator for your Python models — pure AST, no database required.
|
|
5
5
|
Keywords: sqlmodel,sqlalchemy,django,pydantic,dataclass,erd,plantuml,diagram,database,erdify,sql,ddl
|
|
6
6
|
Author: devsuit GmbH, Fabian Clemenz
|
|
@@ -75,13 +75,18 @@ class AliasResolver:
|
|
|
75
75
|
#: Cycle cut-offs so far; a result computed across one is not cached.
|
|
76
76
|
self._cycles = 0
|
|
77
77
|
self._views: Dict[Tuple[Path, int | None], Mapping[str, ast.expr]] = {}
|
|
78
|
-
|
|
78
|
+
#: Name -> its by-name fallback alias (or None), once known (#254).
|
|
79
|
+
self._fallback: Dict[str, ast.expr | None] = {}
|
|
80
|
+
#: Name -> files whose last binding of it may be an alias (built once).
|
|
81
|
+
self._definers: Dict[str, List[Path]] | None = None
|
|
82
|
+
#: Candidate modules of each ambiguous absolute import.
|
|
83
|
+
self._ambiguous: Dict[Tuple[Path, str | None, int], List[Path]] = {}
|
|
79
84
|
self._suffixes: Dict[Tuple[str, ...], List[Path]] | None = None
|
|
80
85
|
|
|
81
86
|
def aliases_for(self, file: Path | None, line: int | None = None) -> Mapping[str, ast.expr]:
|
|
82
87
|
"""Alias name -> fully expanded ``Annotated[...]``, as seen at ``line`` of ``file``."""
|
|
83
88
|
if file is None or file not in self._trees:
|
|
84
|
-
return MappingProxyType(
|
|
89
|
+
return MappingProxyType(self._all_fallbacks())
|
|
85
90
|
key = (file, line)
|
|
86
91
|
view = self._views.get(key)
|
|
87
92
|
if view is not None:
|
|
@@ -91,10 +96,12 @@ class AliasResolver:
|
|
|
91
96
|
value = self._resolve(file, name, line, ())
|
|
92
97
|
if value is not None:
|
|
93
98
|
result[name] = value
|
|
94
|
-
for name
|
|
99
|
+
for name in self._fallback_candidates():
|
|
95
100
|
# A name bound before the class (also via `*`) never falls back.
|
|
96
101
|
if name not in result and self._binding_at(file, name, line) is None:
|
|
97
|
-
|
|
102
|
+
value = self._fallback_for(name)
|
|
103
|
+
if value is not None:
|
|
104
|
+
result[name] = value
|
|
98
105
|
view = MappingProxyType(result)
|
|
99
106
|
self._views[key] = view
|
|
100
107
|
return view
|
|
@@ -268,8 +275,8 @@ class AliasResolver:
|
|
|
268
275
|
) -> ast.expr | None:
|
|
269
276
|
if binding.kind == "import":
|
|
270
277
|
target = self._find_module(file, binding.module, binding.level)
|
|
271
|
-
if target is _AMBIGUOUS: # several scanned modules match
|
|
272
|
-
return self.
|
|
278
|
+
if target is _AMBIGUOUS: # several scanned modules match
|
|
279
|
+
return self._agreed_import(file, binding, stack)
|
|
273
280
|
if target is None: # not a scanned module (stdlib, third party)
|
|
274
281
|
return None
|
|
275
282
|
return self._resolve(target, binding.original, None, stack)
|
|
@@ -331,6 +338,8 @@ class AliasResolver:
|
|
|
331
338
|
m for m in matches if m.name == "__init__.py" or m.with_suffix("") not in packages
|
|
332
339
|
]
|
|
333
340
|
found = matches[0] if len(matches) == 1 else (_AMBIGUOUS if matches else None)
|
|
341
|
+
if found is _AMBIGUOUS:
|
|
342
|
+
self._ambiguous[key] = matches
|
|
334
343
|
self._modules[key] = found
|
|
335
344
|
return found
|
|
336
345
|
|
|
@@ -367,22 +376,72 @@ class AliasResolver:
|
|
|
367
376
|
root = dotted[: len(dotted) - depth]
|
|
368
377
|
return self._absolute(importer).parts[: len(root)] == root
|
|
369
378
|
|
|
370
|
-
def
|
|
371
|
-
"""
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
for
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
self.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
379
|
+
def _definer_index(self) -> Dict[str, List[Path]]:
|
|
380
|
+
"""Name -> files whose last module-level binding of it may be an alias.
|
|
381
|
+
|
|
382
|
+
Built in one pass over the modules; resolving the values stays lazy.
|
|
383
|
+
"""
|
|
384
|
+
if self._definers is None:
|
|
385
|
+
definers: Dict[str, List[Path]] = {}
|
|
386
|
+
for file in self._trees:
|
|
387
|
+
for name, bindings in self._history(file).items():
|
|
388
|
+
if bindings[-1].kind == "alias" and name not in self._classes:
|
|
389
|
+
definers.setdefault(name, []).append(file)
|
|
390
|
+
self._definers = dict(sorted(definers.items()))
|
|
391
|
+
return self._definers
|
|
392
|
+
|
|
393
|
+
def _fallback_candidates(self) -> List[str]:
|
|
394
|
+
"""Names some scanned module ends up defining as a possible alias."""
|
|
395
|
+
return list(self._definer_index())
|
|
396
|
+
|
|
397
|
+
def _agreed_import(
|
|
398
|
+
self, file: Path, binding: _Binding, stack: Tuple[_Lookup, ...]
|
|
399
|
+
) -> ast.expr | None:
|
|
400
|
+
"""An ambiguous absolute import: the alias every matching module defines alike.
|
|
401
|
+
|
|
402
|
+
Only the modules the import could name are consulted (#254), never
|
|
403
|
+
other modules that merely define the same name.
|
|
404
|
+
"""
|
|
405
|
+
candidates = self._ambiguous[(file, binding.module, binding.level)]
|
|
406
|
+
values = [self._resolve(m, binding.original, None, stack) for m in candidates]
|
|
407
|
+
if any(v is None for v in values):
|
|
408
|
+
return None # one candidate defines no such alias: unknown which applies
|
|
409
|
+
return self._agreed([v for v in values if v is not None])
|
|
410
|
+
|
|
411
|
+
def _fallback_for(self, name: str) -> ast.expr | None:
|
|
412
|
+
"""The alias ``name`` names wherever it is defined, if all definitions agree.
|
|
413
|
+
|
|
414
|
+
For a name a model module does not bind (e.g. imported under
|
|
415
|
+
``TYPE_CHECKING``). Resolved on demand, per name, so an alias built on
|
|
416
|
+
another one (``UserId = intpk``) is included (#254).
|
|
417
|
+
"""
|
|
418
|
+
if name in self._fallback:
|
|
419
|
+
return self._fallback[name]
|
|
420
|
+
result = None
|
|
421
|
+
if name not in self._classes:
|
|
422
|
+
values = [
|
|
423
|
+
value
|
|
424
|
+
for file in self._definitions_of(name)
|
|
425
|
+
if (value := self._resolve(file, name, None, ())) is not None
|
|
426
|
+
]
|
|
427
|
+
result = self._agreed(values)
|
|
428
|
+
self._fallback[name] = result
|
|
429
|
+
return result
|
|
430
|
+
|
|
431
|
+
def _definitions_of(self, name: str) -> List[Path]:
|
|
432
|
+
"""Files whose last module-level binding of ``name`` may be an alias."""
|
|
433
|
+
return self._definer_index().get(name, [])
|
|
434
|
+
|
|
435
|
+
@staticmethod
|
|
436
|
+
def _agreed(values: List[ast.expr]) -> ast.expr | None:
|
|
437
|
+
"""The common value, if every definition gives the same one."""
|
|
438
|
+
return values[0] if values and len({ast.dump(v) for v in values}) == 1 else None
|
|
439
|
+
|
|
440
|
+
def _all_fallbacks(self) -> Dict[str, ast.expr]:
|
|
441
|
+
"""Every by-name fallback alias (for a class whose file is unknown)."""
|
|
442
|
+
table: Dict[str, ast.expr] = {}
|
|
443
|
+
for name in self._fallback_candidates():
|
|
444
|
+
value = self._fallback_for(name)
|
|
445
|
+
if value is not None:
|
|
446
|
+
table[name] = value
|
|
447
|
+
return table
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|