From edabce15082bd3d560dc976e27a9c7c1b86d5604 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 05:09:40 +0000 Subject: [PATCH 1/4] fix(deps): update dependency erdantic to v1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 00459cb..0f2ad52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ coverage = { version ="^7", optional = true } ruff = { version = "^0.3", optional = true } # extras erdantic -erdantic = { version ="^0.7.0", optional = true } +erdantic = { version ="^1.0.0", optional = true } [tool.poetry.extras] docs = ["sphinx-rtd-theme", From a5fbc71bbeb779102b0734d078e81a4c3239ee11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20W=C3=B6llert?= Date: Thu, 11 Apr 2024 14:27:43 +0200 Subject: [PATCH 2/4] Improve erdantic example in docs --- docs/source/users/examples.rst | 6 ++-- .../test-base/target/example_erdantic.py | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/roots/test-base/target/example_erdantic.py diff --git a/docs/source/users/examples.rst b/docs/source/users/examples.rst index 8b85f86..22fa638 100644 --- a/docs/source/users/examples.rst +++ b/docs/source/users/examples.rst @@ -54,7 +54,7 @@ This example shows the rendered output of a pydantic model including an Entity-R .. tab:: *rendered output* - .. autopydantic_model:: target.example_generics.Response + .. autopydantic_model:: target.example_erdantic.Order :noindex: :model-erdantic-figure: True :model-erdantic-figure-collapsed: False @@ -63,13 +63,13 @@ This example shows the rendered output of a pydantic model including an Entity-R .. code-block:: - .. autopydantic_model:: target.example_generics.Response + .. autopydantic_model:: target.example_erdantic.Order :model-erdantic-figure: True :model-erdantic-figure-collapsed: False .. tab:: python - .. autocodeblock:: target.example_generics + .. autocodeblock:: target.example_erdantic ----------- diff --git a/tests/roots/test-base/target/example_erdantic.py b/tests/roots/test-base/target/example_erdantic.py new file mode 100644 index 0000000..40df107 --- /dev/null +++ b/tests/roots/test-base/target/example_erdantic.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from pydantic import BaseModel + + +class ProductCategory(BaseModel): + """Product category representation.""" + + id: int + name: str + + +class Product(BaseModel): + """Product representation.""" + + id: int + name: str + category: ProductCategory + + +class Customer(BaseModel): + """Customer representation.""" + + id: int + name: str + + +class Order(BaseModel): + """Order representation.""" + + id: int + customer: Customer + products: list[Product] + total: float From 0c164c63e88e2c875bf08092fbb4591b796b7985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20W=C3=B6llert?= Date: Thu, 11 Apr 2024 14:28:20 +0200 Subject: [PATCH 3/4] Remove label from erdantic graphs. Simplify tests with new erdantic version. --- .../directives/autodocumenters.py | 6 ++- tests/compatibility.py | 9 ---- tests/test_configuration_model.py | 54 ++++++++++--------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py b/sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py index 53dc446..7da8f8d 100644 --- a/sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py +++ b/sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py @@ -345,7 +345,11 @@ def add_erdantic_figure(self) -> None: raise RuntimeError(error_msg) # Graphviz [DOT language](https://graphviz.org/doc/info/lang.html) - figure_dot = erd.to_dot(self.object).replace('\t', ' ').split('\n') + figure_dot = ( + erd.to_dot(self.object, graph_attr={'label': ''}) + .replace('\t', ' ') + .split('\n') + ) lines_dot = [' ' + line for line in figure_dot] lines = ['.. graphviz::', '', *lines_dot, ''] diff --git a/tests/compatibility.py b/tests/compatibility.py index fd47a1e..fc16998 100644 --- a/tests/compatibility.py +++ b/tests/compatibility.py @@ -12,15 +12,6 @@ from sphinx.addnodes import desc_sig_punctuation, desc_annotation, pending_xref -def package_is_missing(package_name): - """Check if a Python package is not available""" - try: - importlib.import_module(package_name) - return False - except ImportError: - return True - - def desc_annotation_default_value(value: str): """Provides compatibility abstraction for `desc_annotation` for default values for sphinx version smaller and greater equal sphinx 4.3. diff --git a/tests/test_configuration_model.py b/tests/test_configuration_model.py index 6e1c110..4543900 100644 --- a/tests/test_configuration_model.py +++ b/tests/test_configuration_model.py @@ -5,7 +5,7 @@ from sphinx.testing.util import assert_node from sphinxcontrib.autodoc_pydantic import PydanticModelDocumenter -from .compatibility import desc_annotation_directive_prefix, package_is_missing +from .compatibility import desc_annotation_directive_prefix KWARGS = dict(documenter=PydanticModelDocumenter.objtype, deactivate_all=True) @@ -97,8 +97,9 @@ def test_autodoc_pydantic_model_show_json_false(autodocument): assert actual == result -@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing') def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): + pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') + kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) result = [ @@ -116,24 +117,27 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): '', ' .. graphviz::', '', - ' digraph "Entity Relationship Diagram" {', + ' digraph "Entity Relationship Diagram created by erdantic" {', ' graph [fontcolor=gray66,', + ' fontname="Times New Roman,Times,Liberation Serif,serif",', ' fontsize=9,', - ' label="Created by erdantic v0.5.0 ",', ' nodesep=0.5,', ' rankdir=LR,', ' ranksep=1.5', ' ];', - ' node [fontsize=14,', + ' node [fontname="Times New Roman,Times,Liberation Serif,serif",', + ' fontsize=14,', ' label="\\N",', ' shape=plain', ' ];', + ' edge [dir=both];', ' "target.configuration.ModelErdanticFigure" [label=<
ModelErdanticFigure
field1int
field2str
relatedModelErdanticFigureRelated
>,', ' tooltip="target.configuration.ModelErdanticFigure ModelErdanticFigure. "];', ' "target.configuration.ModelErdanticFigureRelated" [label=<
ModelErdanticFigureRelated
field1int
field2str
>,', ' tooltip="target.configuration.ModelErdanticFigureRelated ModelErdanticFigureRelated. "];', - ' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee];', - ' }' '', + ' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee,', + ' arrowtail=nonenone];', + ' }', '', '', '', @@ -143,18 +147,15 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): '', '', ] - # explicit global actual = autodocument( options_app={'autodoc_pydantic_model_erdantic_figure': True}, **kwargs ) - assert actual[:17] == result[:17] - assert actual[18:] == result[18:] + assert actual == result # explicit local actual = autodocument(options_doc={'model-erdantic-figure': True}, **kwargs) - assert actual[:17] == result[:17] - assert actual[18:] == result[18:] + assert actual == result # explicit local overwrite global actual = autodocument( @@ -162,12 +163,12 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): options_doc={'model-erdantic-figure': True}, **kwargs, ) - assert actual[:17] == result[:17] - assert actual[18:] == result[18:] + assert actual == result -@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing') def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): + pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') + kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) result = [ @@ -179,23 +180,26 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): '', ' .. graphviz::', '', - ' digraph "Entity Relationship Diagram" {', + ' digraph "Entity Relationship Diagram created by erdantic" {', ' graph [fontcolor=gray66,', + ' fontname="Times New Roman,Times,Liberation Serif,serif",', ' fontsize=9,', - ' label="Created by erdantic v0.5.0 ",', ' nodesep=0.5,', ' rankdir=LR,', ' ranksep=1.5', ' ];', - ' node [fontsize=14,', + ' node [fontname="Times New Roman,Times,Liberation Serif,serif",', + ' fontsize=14,', ' label="\\N",', ' shape=plain', ' ];', + ' edge [dir=both];', ' "target.configuration.ModelErdanticFigure" [label=<
ModelErdanticFigure
field1int
field2str
relatedModelErdanticFigureRelated
>,', ' tooltip="target.configuration.ModelErdanticFigure ModelErdanticFigure. "];', ' "target.configuration.ModelErdanticFigureRelated" [label=<
ModelErdanticFigureRelated
field1int
field2str
>,', ' tooltip="target.configuration.ModelErdanticFigureRelated ModelErdanticFigureRelated. "];', - ' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee];', + ' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee,', + ' arrowtail=nonenone];', ' }', '', '', @@ -209,8 +213,7 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): }, **kwargs, ) - assert actual[:11] == result[:11] - assert actual[12:] == result[12:] + assert actual == result # explicit local actual = autodocument( @@ -220,8 +223,7 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): }, **kwargs, ) - assert actual[:11] == result[:11] - assert actual[12:] == result[12:] + assert actual == result # explicit local overwrite global actual = autodocument( @@ -232,12 +234,12 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): }, **kwargs, ) - assert actual[:11] == result[:11] - assert actual[12:] == result[12:] + assert actual == result -@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing') def test_autodoc_pydantic_model_erdantic_figure_false(autodocument): + pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') + kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) result = [ From 046c14cbc1d649c3723552a5ae1b648fbef3253e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20W=C3=B6llert?= Date: Thu, 11 Apr 2024 14:32:56 +0200 Subject: [PATCH 4/4] Linting and version constraints --- pyproject.toml | 2 +- tests/test_configuration_model.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0f2ad52..1fafb03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ coverage = { version ="^7", optional = true } ruff = { version = "^0.3", optional = true } # extras erdantic -erdantic = { version ="^1.0.0", optional = true } +erdantic = { version ="<2.0", optional = true } [tool.poetry.extras] docs = ["sphinx-rtd-theme", diff --git a/tests/test_configuration_model.py b/tests/test_configuration_model.py index 4543900..6740408 100644 --- a/tests/test_configuration_model.py +++ b/tests/test_configuration_model.py @@ -98,7 +98,7 @@ def test_autodoc_pydantic_model_show_json_false(autodocument): def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): - pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') + pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing') kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) @@ -167,7 +167,7 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument): def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): - pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') + pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing') kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) @@ -238,8 +238,8 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument): def test_autodoc_pydantic_model_erdantic_figure_false(autodocument): - pytest.importorskip("erdantic", minversion="1.0", reason='erdantic missing') - + pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing') + kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS) result = [