erdify 1.5.2__tar.gz → 1.5.3__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.
Files changed (29) hide show
  1. {erdify-1.5.2 → erdify-1.5.3}/PKG-INFO +1 -1
  2. {erdify-1.5.2 → erdify-1.5.3}/pyproject.toml +1 -1
  3. {erdify-1.5.2 → erdify-1.5.3}/pyproject.toml.orig +1 -1
  4. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/django.py +11 -9
  5. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/django_apps.py +2 -2
  6. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/inheritance.py +3 -2
  7. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/sql_parser.py +44 -2
  8. {erdify-1.5.2 → erdify-1.5.3}/LICENSE +0 -0
  9. {erdify-1.5.2 → erdify-1.5.3}/README.md +0 -0
  10. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/__init__.py +0 -0
  11. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/__main__.py +0 -0
  12. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/cli.py +0 -0
  13. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/config.py +0 -0
  14. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/generator.py +0 -0
  15. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/inject.py +0 -0
  16. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/__init__.py +0 -0
  17. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/aliases.py +0 -0
  18. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/annotations.py +0 -0
  19. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/common.py +0 -0
  20. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/core.py +0 -0
  21. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/__init__.py +0 -0
  22. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/annotated.py +0 -0
  23. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/base.py +0 -0
  24. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/django_contrib.py +0 -0
  25. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/keyless.py +0 -0
  26. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/dialects/sqlalchemy.py +0 -0
  27. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/parser/discovery.py +0 -0
  28. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/py.typed +0 -0
  29. {erdify-1.5.2 → erdify-1.5.3}/src/erdify/pyproject.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: erdify
3
- Version: 1.5.2
3
+ Version: 1.5.3
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "erdify"
3
- version = "1.5.2"
3
+ version = "1.5.3"
4
4
  description = "A zero-dependency ERD generator for your Python models — pure AST, no database required."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "erdify"
3
- version = "1.5.2"
3
+ version = "1.5.3"
4
4
  description = "A zero-dependency ERD generator for your Python models — pure AST, no database required."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -616,9 +616,10 @@ class DjangoDialect(Dialect):
616
616
  """The model a Django ``"self"`` relation declared in class ``name`` points at.
617
617
 
618
618
  A concrete model's own fields point at that model (a multi-table child
619
- does not copy them, #233). An abstract base's or a plain
620
- mixin's fields are copied into the first concrete model that inherits
621
- it, so ``"self"`` points there (#226).
619
+ does not copy them, #233). An abstract base's fields (or those of a
620
+ base not known to be plain, see :meth:`_own_declarations`) are copied
621
+ into the first concrete model that inherits it, so ``"self"`` points
622
+ there (#226).
622
623
  """
623
624
  if self._is_concrete_django_model(name):
624
625
  return name
@@ -634,8 +635,8 @@ class DjangoDialect(Dialect):
634
635
  def _is_concrete_django_model(self, name: str) -> bool:
635
636
  """A Django model with its own table: a ``models.Model`` subclass, not abstract.
636
637
 
637
- A plain mixin or an abstract base has no table, so a ``"self"``
638
- relation declared there belongs to the concrete model that copies it.
638
+ An abstract base has no table, so a ``"self"`` relation declared there
639
+ belongs to the concrete model that copies it.
639
640
  """
640
641
  node = self.classes.all[name]
641
642
  return self._inherits_django_model(node) and not self._meta_flag(node, "abstract")
@@ -792,10 +793,11 @@ class DjangoDialect(Dialect):
792
793
 
793
794
  Django's ``ModelBase`` (#272, #280): the class body's fields, then,
794
795
  along the MRO, each *direct* base that is an abstract model adds the
795
- fields it has itself (its own and those it copied) unless the name is
796
- already taken. Every other class in the MRO only takes names: a
797
- concrete parent its fields (they stay in its table, #233), a plain
798
- mixin or an indirect ancestor every name its body binds. So a field on
796
+ fields it has itself (its own and those it copied) unless the body or
797
+ a class earlier in the MRO already took the name. Every other class in
798
+ the MRO only takes names: a concrete parent its fields (they stay in
799
+ its table, #233), a plain mixin or an indirect ancestor every name its
800
+ body binds. So a field on
799
801
  a plain mixin is no column, and a diamond keeps the first copy. A base
800
802
  that is not known to be plain (it extends a class outside the scanned
801
803
  files) is read like an abstract model.
@@ -19,8 +19,8 @@ with an ``__init__.py``) from the model file: the nearest directory with an
19
19
  file. The walk never leaves the package chain, so an unrelated ``models``
20
20
  directory above the project can't be picked up.
21
21
 
22
- ``Meta.app_label`` inherited from an abstract base's ``Meta`` is not read yet
23
- (the same gap as an inherited ``db_table``, #279).
22
+ A ``Meta.app_label``, also one inherited from an abstract base's ``Meta``
23
+ (#279), takes precedence; the dialect reads it before asking this module.
24
24
 
25
25
  An ``AppConfig`` chosen explicitly in ``INSTALLED_APPS`` (``"shop.apps.Custom"``)
26
26
  is not known to erdify; the app's default config is used instead.
@@ -1,8 +1,9 @@
1
1
  """Class hierarchy of the parsed files: MRO, merge order and member merging.
2
2
 
3
3
  Shared by every dialect. A model's fields come from its own body and its
4
- bases; which declaration wins follows Python's MRO (#228), and the order they
5
- are listed in follows the pre-MRO recursive merge.
4
+ bases; which declaration wins follows Python's MRO (#228) unless a dialect
5
+ resolves it its own way (Django follows ``ModelBase``, #272), and the order
6
+ they are listed in follows the pre-MRO recursive merge.
6
7
  """
7
8
 
8
9
  import ast
@@ -157,6 +157,11 @@ class SqlSchemaParser:
157
157
  #: for tables and, per table, for columns.
158
158
  self._table_keys: dict[str, str] = {}
159
159
  self._column_keys: dict[str, dict[str, str]] = {}
160
+ #: Enum type name keys -> declared names.
161
+ self._enum_keys: dict[str, str] = {}
162
+ #: Columns of a user-defined type: (field, schema prefix, type name key),
163
+ #: matched to the enums in _finalize().
164
+ self._typed_fields: list[tuple[FieldInfo, str, str]] = []
160
165
  self._dialect: Any = None
161
166
 
162
167
  def parse(self) -> tuple[dict[str, EntityInfo], dict[str, EnumInfo]]:
@@ -335,6 +340,7 @@ class SqlSchemaParser:
335
340
  values.append(lit.this)
336
341
  if name and values:
337
342
  self._enums[name] = EnumInfo(name=name, values=values)
343
+ self._enum_keys[self._key(name_node)] = name
338
344
 
339
345
  def _column(
340
346
  self,
@@ -348,6 +354,11 @@ class SqlSchemaParser:
348
354
  name = coldef.name # type: ignore[attr-defined]
349
355
  kind = coldef.args.get("kind") # type: ignore[attr-defined]
350
356
  type_str = kind.sql().lower() if kind is not None else ""
357
+ type_ref = self._user_defined_type(kind, exp)
358
+ if type_ref is not None:
359
+ prefix, ident = type_ref
360
+ # Unquoted like the CREATE TYPE name: a quoted name keeps its case (#328).
361
+ type_str = prefix + (ident.name if ident.quoted else ident.name.lower())
351
362
  constraints = coldef.constraints # type: ignore[attr-defined] # list[exp.ColumnConstraint]
352
363
  is_pk = name in pk_cols or self._has_constraint(
353
364
  constraints,
@@ -366,7 +377,7 @@ class SqlSchemaParser:
366
377
  constraints,
367
378
  exp.UniqueColumnConstraint, # type: ignore[attr-defined]
368
379
  )
369
- return FieldInfo(
380
+ field = FieldInfo(
370
381
  name=name,
371
382
  type_str=type_str,
372
383
  is_primary_key=is_pk,
@@ -375,6 +386,31 @@ class SqlSchemaParser:
375
386
  default_value=default,
376
387
  is_unique=is_unique,
377
388
  )
389
+ if type_ref is not None:
390
+ self._typed_fields.append((field, type_ref[0], self._key(type_ref[1])))
391
+ return field
392
+
393
+ @staticmethod
394
+ def _user_defined_type(kind: Any, exp: Any) -> tuple[str, Any] | None:
395
+ """A user-defined column type (e.g. an enum) as (schema prefix, name
396
+ identifier), or ``None`` for a built-in type.
397
+
398
+ Only a dialect that reads quoted type names (PostgreSQL) has the
399
+ identifier; the generic dialect keeps the name as plain text.
400
+ """
401
+ if not isinstance(kind, exp.DataType) or kind.this != exp.DataType.Type.USERDEFINED:
402
+ return None
403
+ ref = kind.args.get("kind")
404
+ if isinstance(ref, exp.Identifier):
405
+ return "", ref
406
+ if isinstance(ref, exp.Dot) and isinstance(ref.expression, exp.Identifier):
407
+ # Each schema part follows the type name's rule: quoted keeps its case.
408
+ schema = ".".join(
409
+ part.name if part.quoted else part.name.lower()
410
+ for part in ref.this.find_all(exp.Identifier, bfs=False)
411
+ )
412
+ return schema + ".", ref.expression
413
+ return None
378
414
 
379
415
  @staticmethod
380
416
  def _has_constraint(constraints: list[object], kind: "type") -> bool:
@@ -559,7 +595,13 @@ class SqlSchemaParser:
559
595
  return part
560
596
 
561
597
  def _finalize(self) -> None:
562
- """Detect link tables, then apply ``exclude_patterns``."""
598
+ """Name enum-typed columns' types as their enum, detect link tables,
599
+ then apply ``exclude_patterns``."""
600
+ # Type names fold like table names: `mood` is the enum `Mood` (#328).
601
+ for field, prefix, key in self._typed_fields:
602
+ enum_name = self._enum_keys.get(key)
603
+ if enum_name is not None:
604
+ field.type_str = prefix + enum_name
563
605
  for entity in self._entities.values():
564
606
  normalize_key_uniqueness(entity.fields)
565
607
  entity.is_link_table = is_structural_link_table(entity.fields)
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