Skip to content

Commit e99b86a

Browse files
authored
Merge pull request #326 from machow/fix-griffe-compat
fix: compatibility with griffe 0.39
2 parents 6781777 + ae9288f commit e99b86a

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ docs-build-readme:
4343
--output README.md \
4444
--output-dir ..
4545

46+
docs-build: export PLUM_SIMPLE_DOC=1
4647
docs-build: docs-build-examples
4748
cd docs && quarto add --no-prompt ..
4849
cd docs && quartodoc build

quartodoc/ast.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from griffe.docstrings import dataclasses as ds
88
from griffe import dataclasses as dc
99
from plum import dispatch
10-
from typing import Union
10+
from typing import Type, Union
1111

1212
from ._pydantic_compat import BaseModel # for previewing
1313

@@ -44,7 +44,7 @@ class DocstringSectionKindPatched(Enum):
4444

4545

4646
class _DocstringSectionPatched(ds.DocstringSection):
47-
_registry: "dict[Enum, _DocstringSectionPatched]" = {}
47+
_registry: "dict[str, Type[_DocstringSectionPatched]]" = {}
4848

4949
def __init__(self, value: str, title: "str | None" = None):
5050
super().__init__(title)
@@ -102,18 +102,31 @@ def transform(cls, el: ds.DocstringSection) -> list[ds.DocstringSection]:
102102
class represents a section like See Also, etc..
103103
"""
104104

105-
if not isinstance(el, ds.DocstringSectionText):
105+
if not isinstance(el, (ds.DocstringSectionText, ds.DocstringSectionAdmonition)):
106106
return [el]
107107

108-
splits = cls.split_sections(el.value)
109108
results = []
110-
for title, body in splits:
111-
sub_cls = cls._registry.get(title.lower(), ds.DocstringSectionText)
112109

113-
# note that griffe currently doesn't store the title anywhere,
114-
# but we add the exact title here, so we can be flexible about the
115-
# sections we parse (e.g. Note instead of Notes) in the future.
116-
results.append(sub_cls(body, title))
110+
# griffe < 0.39 w/ numpydoc uses DocstringSectionText for unhandled section
111+
# but later versions always use Admonitions. Note it may still use Text
112+
# for areas of docstrings not associated with particular sections (e.g. freeform
113+
# text betwen a parameters section and the next section).
114+
if isinstance(el, ds.DocstringSectionText):
115+
# handle griffe < 0.39 case
116+
splits = cls.split_sections(el.value)
117+
for title, body in splits:
118+
sub_cls = cls._registry.get(title.lower(), ds.DocstringSectionText)
119+
120+
# note that griffe currently doesn't store the title anywhere,
121+
# but we add the exact title here, so we can be flexible about the
122+
# sections we parse (e.g. Note instead of Notes) in the future.
123+
results.append(sub_cls(body, title))
124+
elif isinstance(el, ds.DocstringSectionAdmonition):
125+
sub_cls = cls._registry.get(el.title.lower(), None)
126+
if sub_cls:
127+
results.append(sub_cls(el.value.contents, el.title))
128+
else:
129+
results.append(el)
117130

118131
return results or [el]
119132

quartodoc/renderers/md_renderer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def render_annotation(self, el: expr.Expr) -> str:
140140

141141
@dispatch
142142
def signature(self, el: layout.Doc):
143+
"""Return a string representation of an object's signature."""
143144
orig = self.display_name
144145

145146
# set signature path, generate signature, then set back
@@ -156,7 +157,6 @@ def signature(self, el: layout.Doc):
156157

157158
@dispatch
158159
def signature(self, el: dc.Alias, source: Optional[dc.Alias] = None):
159-
"""Return a string representation of an object's signature."""
160160
return self.signature(el.final_target, el)
161161

162162
@dispatch
@@ -508,7 +508,7 @@ def render(self, el: ds.DocstringSectionAdmonition):
508508
# TODO: attempt to parse See Also sections
509509
return convert_rst_link_to_md(el.value.description)
510510

511-
raise NotImplementedError(f"Unsupported DocstringSectionAdmonition kind: {kind}")
511+
return el.value.description
512512

513513
# warnings ----
514514

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@
307307
|--------|--------|------------------|------------|
308308
| `a` | int | The a parameter. | _required_ |
309309
| `b` | str | The b parameter. | _required_ |
310+
311+
## Custom Admonition
312+
313+
Some text.
310314
'''
311315
# ---
312316
# name: test_render_docstring_styles[numpy]
@@ -323,6 +327,10 @@
323327
|--------|--------|------------------|------------|
324328
| `a` | | The a parameter. | _required_ |
325329
| `b` | str | The b parameter. | _required_ |
330+
331+
## Custom Admonition
332+
333+
Some text.
326334
'''
327335
# ---
328336
# name: test_render_docstring_styles[sphinx]

quartodoc/tests/example_docstring_styles.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ def f_google(a, b: str):
44
Args:
55
a (int): The a parameter.
66
b: The b parameter.
7+
8+
Custom Admonition:
9+
Some text.
710
"""
811

912

@@ -26,6 +29,9 @@ def f_numpy(a, b: str):
2629
b:
2730
The b parameter.
2831
32+
Custom Admonition
33+
-----------------
34+
Some text.
2935
"""
3036

3137

@@ -41,5 +47,4 @@ def f_numpy_with_linebreaks(a, b: str):
4147
4248
b:
4349
The b parameter.
44-
4550
"""

0 commit comments

Comments
 (0)