Skip to content

Commit 3c8daa8

Browse files
fix(deps): update dependency erdantic to <v2 (#246)
docs: improve erdantic example tests: simplify erdantic tests tests: remove `package_is_missing` Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Franz Wöllert <[email protected]>
1 parent e6fe9e1 commit 3c8daa8

File tree

6 files changed

+71
-40
lines changed

6 files changed

+71
-40
lines changed

docs/source/users/examples.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This example shows the rendered output of a pydantic model including an Entity-R
5454

5555
.. tab:: *rendered output*
5656

57-
.. autopydantic_model:: target.example_generics.Response
57+
.. autopydantic_model:: target.example_erdantic.Order
5858
:noindex:
5959
:model-erdantic-figure: True
6060
:model-erdantic-figure-collapsed: False
@@ -63,13 +63,13 @@ This example shows the rendered output of a pydantic model including an Entity-R
6363

6464
.. code-block::
6565
66-
.. autopydantic_model:: target.example_generics.Response
66+
.. autopydantic_model:: target.example_erdantic.Order
6767
:model-erdantic-figure: True
6868
:model-erdantic-figure-collapsed: False
6969
7070
.. tab:: python
7171

72-
.. autocodeblock:: target.example_generics
72+
.. autocodeblock:: target.example_erdantic
7373

7474

7575
-----------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ coverage = { version ="^7", optional = true }
4545
ruff = { version = "^0.3", optional = true }
4646

4747
# extras erdantic
48-
erdantic = { version ="^0.7.0", optional = true }
48+
erdantic = { version ="<2.0", optional = true }
4949

5050
[tool.poetry.extras]
5151
docs = ["sphinx-rtd-theme",

sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ def add_erdantic_figure(self) -> None:
345345
raise RuntimeError(error_msg)
346346

347347
# Graphviz [DOT language](https://graphviz.org/doc/info/lang.html)
348-
figure_dot = erd.to_dot(self.object).replace('\t', ' ').split('\n')
348+
figure_dot = (
349+
erd.to_dot(self.object, graph_attr={'label': ''})
350+
.replace('\t', ' ')
351+
.split('\n')
352+
)
349353
lines_dot = [' ' + line for line in figure_dot]
350354
lines = ['.. graphviz::', '', *lines_dot, '']
351355

tests/compatibility.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
from sphinx.addnodes import desc_sig_punctuation, desc_annotation, pending_xref
1313

1414

15-
def package_is_missing(package_name):
16-
"""Check if a Python package is not available"""
17-
try:
18-
importlib.import_module(package_name)
19-
return False
20-
except ImportError:
21-
return True
22-
23-
2415
def desc_annotation_default_value(value: str):
2516
"""Provides compatibility abstraction for `desc_annotation` for default
2617
values for sphinx version smaller and greater equal sphinx 4.3.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from __future__ import annotations
2+
3+
from pydantic import BaseModel
4+
5+
6+
class ProductCategory(BaseModel):
7+
"""Product category representation."""
8+
9+
id: int
10+
name: str
11+
12+
13+
class Product(BaseModel):
14+
"""Product representation."""
15+
16+
id: int
17+
name: str
18+
category: ProductCategory
19+
20+
21+
class Customer(BaseModel):
22+
"""Customer representation."""
23+
24+
id: int
25+
name: str
26+
27+
28+
class Order(BaseModel):
29+
"""Order representation."""
30+
31+
id: int
32+
customer: Customer
33+
products: list[Product]
34+
total: float

tests/test_configuration_model.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sphinx.testing.util import assert_node
66

77
from sphinxcontrib.autodoc_pydantic import PydanticModelDocumenter
8-
from .compatibility import desc_annotation_directive_prefix, package_is_missing
8+
from .compatibility import desc_annotation_directive_prefix
99

1010
KWARGS = dict(documenter=PydanticModelDocumenter.objtype, deactivate_all=True)
1111

@@ -97,8 +97,9 @@ def test_autodoc_pydantic_model_show_json_false(autodocument):
9797
assert actual == result
9898

9999

100-
@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing')
101100
def test_autodoc_pydantic_model_erdantic_figure_true(autodocument):
101+
pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing')
102+
102103
kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS)
103104

104105
result = [
@@ -116,24 +117,27 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument):
116117
'',
117118
' .. graphviz::',
118119
'',
119-
' digraph "Entity Relationship Diagram" {',
120+
' digraph "Entity Relationship Diagram created by erdantic" {',
120121
' graph [fontcolor=gray66,',
122+
' fontname="Times New Roman,Times,Liberation Serif,serif",',
121123
' fontsize=9,',
122-
' label="Created by erdantic v0.5.0 <https://github.com/drivendataorg/erdantic>",',
123124
' nodesep=0.5,',
124125
' rankdir=LR,',
125126
' ranksep=1.5',
126127
' ];',
127-
' node [fontsize=14,',
128+
' node [fontname="Times New Roman,Times,Liberation Serif,serif",',
129+
' fontsize=14,',
128130
' label="\\N",',
129131
' shape=plain',
130132
' ];',
133+
' edge [dir=both];',
131134
' "target.configuration.ModelErdanticFigure" [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>ModelErdanticFigure</b></td></tr><tr><td>field1</td><td port="field1">int</td></tr><tr><td>field2</td><td port="field2">str</td></tr><tr><td>related</td><td port="related">ModelErdanticFigureRelated</td></tr></table>>,',
132135
' tooltip="target.configuration.ModelErdanticFigure&#xA;&#xA;ModelErdanticFigure.&#xA;"];',
133136
' "target.configuration.ModelErdanticFigureRelated" [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>ModelErdanticFigureRelated</b></td></tr><tr><td>field1</td><td port="field1">int</td></tr><tr><td>field2</td><td port="field2">str</td></tr></table>>,',
134137
' tooltip="target.configuration.ModelErdanticFigureRelated&#xA;&#xA;ModelErdanticFigureRelated.&#xA;"];',
135-
' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee];',
136-
' }' '',
138+
' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee,',
139+
' arrowtail=nonenone];',
140+
' }',
137141
'',
138142
'',
139143
'',
@@ -143,31 +147,28 @@ def test_autodoc_pydantic_model_erdantic_figure_true(autodocument):
143147
'',
144148
'',
145149
]
146-
147150
# explicit global
148151
actual = autodocument(
149152
options_app={'autodoc_pydantic_model_erdantic_figure': True}, **kwargs
150153
)
151-
assert actual[:17] == result[:17]
152-
assert actual[18:] == result[18:]
154+
assert actual == result
153155

154156
# explicit local
155157
actual = autodocument(options_doc={'model-erdantic-figure': True}, **kwargs)
156-
assert actual[:17] == result[:17]
157-
assert actual[18:] == result[18:]
158+
assert actual == result
158159

159160
# explicit local overwrite global
160161
actual = autodocument(
161162
options_app={'autodoc_pydantic_model_erdantic_figure': False},
162163
options_doc={'model-erdantic-figure': True},
163164
**kwargs,
164165
)
165-
assert actual[:17] == result[:17]
166-
assert actual[18:] == result[18:]
166+
assert actual == result
167167

168168

169-
@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing')
170169
def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument):
170+
pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing')
171+
171172
kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS)
172173

173174
result = [
@@ -179,23 +180,26 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument):
179180
'',
180181
' .. graphviz::',
181182
'',
182-
' digraph "Entity Relationship Diagram" {',
183+
' digraph "Entity Relationship Diagram created by erdantic" {',
183184
' graph [fontcolor=gray66,',
185+
' fontname="Times New Roman,Times,Liberation Serif,serif",',
184186
' fontsize=9,',
185-
' label="Created by erdantic v0.5.0 <https://github.com/drivendataorg/erdantic>",',
186187
' nodesep=0.5,',
187188
' rankdir=LR,',
188189
' ranksep=1.5',
189190
' ];',
190-
' node [fontsize=14,',
191+
' node [fontname="Times New Roman,Times,Liberation Serif,serif",',
192+
' fontsize=14,',
191193
' label="\\N",',
192194
' shape=plain',
193195
' ];',
196+
' edge [dir=both];',
194197
' "target.configuration.ModelErdanticFigure" [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>ModelErdanticFigure</b></td></tr><tr><td>field1</td><td port="field1">int</td></tr><tr><td>field2</td><td port="field2">str</td></tr><tr><td>related</td><td port="related">ModelErdanticFigureRelated</td></tr></table>>,',
195198
' tooltip="target.configuration.ModelErdanticFigure&#xA;&#xA;ModelErdanticFigure.&#xA;"];',
196199
' "target.configuration.ModelErdanticFigureRelated" [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>ModelErdanticFigureRelated</b></td></tr><tr><td>field1</td><td port="field1">int</td></tr><tr><td>field2</td><td port="field2">str</td></tr></table>>,',
197200
' tooltip="target.configuration.ModelErdanticFigureRelated&#xA;&#xA;ModelErdanticFigureRelated.&#xA;"];',
198-
' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee];',
201+
' "target.configuration.ModelErdanticFigure":related:e -> "target.configuration.ModelErdanticFigureRelated":_root:w [arrowhead=noneteetee,',
202+
' arrowtail=nonenone];',
199203
' }',
200204
'',
201205
'',
@@ -209,8 +213,7 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument):
209213
},
210214
**kwargs,
211215
)
212-
assert actual[:11] == result[:11]
213-
assert actual[12:] == result[12:]
216+
assert actual == result
214217

215218
# explicit local
216219
actual = autodocument(
@@ -220,8 +223,7 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument):
220223
},
221224
**kwargs,
222225
)
223-
assert actual[:11] == result[:11]
224-
assert actual[12:] == result[12:]
226+
assert actual == result
225227

226228
# explicit local overwrite global
227229
actual = autodocument(
@@ -232,12 +234,12 @@ def test_autodoc_pydantic_model_erdantic_figure_collapsed_false(autodocument):
232234
},
233235
**kwargs,
234236
)
235-
assert actual[:11] == result[:11]
236-
assert actual[12:] == result[12:]
237+
assert actual == result
237238

238239

239-
@pytest.mark.skipif(package_is_missing('erdantic'), reason='erdantic missing')
240240
def test_autodoc_pydantic_model_erdantic_figure_false(autodocument):
241+
pytest.importorskip('erdantic', minversion='1.0', reason='erdantic missing')
242+
241243
kwargs = dict(object_path='target.configuration.ModelErdanticFigure', **KWARGS)
242244

243245
result = [

0 commit comments

Comments
 (0)