3
3
import quartodoc .ast as qast
4
4
5
5
from contextlib import contextmanager
6
+ from functools import wraps
6
7
from griffe .docstrings import dataclasses as ds
7
8
from griffe import dataclasses as dc
8
9
from tabulate import tabulate
@@ -86,7 +87,7 @@ def _increment_header(self, n=1):
86
87
87
88
def _fetch_object_dispname (self , el : "dc.Alias | dc.Object" ):
88
89
# TODO: copied from Builder, should move into util function
89
- if self .display_name == "name" :
90
+ if self .display_name in { "name" , "short" } :
90
91
return el .name
91
92
elif self .display_name == "relative" :
92
93
return "." .join (el .path .split ("." )[1 :])
@@ -128,6 +129,22 @@ def render_annotation(self, el: "str | expr.Name | expr.Expression | None"):
128
129
129
130
# signature method --------------------------------------------------------
130
131
132
+ @dispatch
133
+ def signature (self , el : layout .Doc ):
134
+ orig = self .display_name
135
+
136
+ # set signature path, generate signature, then set back
137
+ # TODO: this is for backwards compatibility with the old approach
138
+ # of only defining signature over griffe objects, which projects
139
+ # like shiny currently extend
140
+ self .display_name = el .signature_name
141
+ res = self .signature (el .obj )
142
+ self .display_name = orig
143
+
144
+ return res
145
+
146
+
147
+
131
148
@dispatch
132
149
def signature (self , el : dc .Alias , source : Optional [dc .Alias ] = None ):
133
150
"""Return a string representation of an object's signature."""
@@ -310,28 +327,30 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
310
327
[self .render (x ) for x in raw_meths if isinstance (x , layout .Doc )]
311
328
)
312
329
330
+
331
+ str_sig = self .signature (el )
332
+ sig_part = [str_sig ] if self .show_signature else []
333
+
313
334
body = self .render (el .obj )
314
- return "\n \n " .join ([title , body , * attr_docs , * class_docs , * meth_docs ])
315
335
316
- @dispatch
317
- def render (self , el : layout .DocFunction ):
318
- title = self .render_header (el )
319
336
320
- return "\n \n " .join ([title , self . render ( el . obj ) ])
337
+ return "\n \n " .join ([title , * sig_part , body , * attr_docs , * class_docs , * meth_docs ])
321
338
322
339
@dispatch
323
- def render (self , el : layout .DocAttribute ):
340
+ def render (self , el : Union [ layout .DocFunction , layout . DocAttribute ] ):
324
341
title = self .render_header (el )
325
- return "\n \n " .join ([title , self .render (el .obj )])
342
+
343
+ str_sig = self .signature (el )
344
+ sig_part = [str_sig ] if self .show_signature else []
345
+
346
+ return "\n \n " .join ([title , * sig_part , self .render (el .obj )])
326
347
327
348
# render griffe objects ===================================================
328
349
329
350
@dispatch
330
351
def render (self , el : Union [dc .Object , dc .Alias ]):
331
352
"""Render high level objects representing functions, classes, etc.."""
332
353
333
- str_sig = self .signature (el )
334
-
335
354
str_body = []
336
355
if el .docstring is None :
337
356
pass
@@ -347,10 +366,7 @@ def render(self, el: Union[dc.Object, dc.Alias]):
347
366
else :
348
367
str_body .append (body )
349
368
350
- if self .show_signature :
351
- parts = [str_sig , * str_body ]
352
- else :
353
- parts = [* str_body ]
369
+ parts = [* str_body ]
354
370
355
371
return "\n \n " .join (parts )
356
372
0 commit comments