Skip to content

Commit 56e9a5a

Browse files
docs: Improve docstring handling and API documentation structure
1 parent 713ffde commit 56e9a5a

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

docs/source/_ext/raw_docstring.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
11
from sphinx.ext.autodoc import ClassDocumenter, MethodDocumenter, FunctionDocumenter
2-
3-
def setup(app):
4-
app.add_autodocumenter(RawFunctionDocumenter)
5-
app.add_autodocumenter(RawMethodDocumenter)
6-
app.add_autodocumenter(RawClassDocumenter)
7-
return {'version': '1.0', 'parallel_read_safe': True}
2+
import inspect
83

94
class RawDocumenterMixin:
10-
def add_directive_header(self, sig):
11-
super().add_directive_header(sig)
5+
def get_doc(self, encoding=None, ignore=1):
6+
"""Directly return the docstring as-is."""
127
if self.object.__doc__:
13-
# Add raw docstring as a code block
8+
# Return as a list of lines
9+
return [self.object.__doc__.splitlines()]
10+
return []
11+
12+
def add_content(self, more_content):
13+
"""Add content from docstrings, attribute documentation and user."""
14+
docstring = self.get_doc()
15+
if docstring:
16+
self.add_line('', '<autodoc>')
17+
self.add_line('**Raw Docstring:**', '<autodoc>')
1418
self.add_line('', '<autodoc>')
1519
self.add_line('.. code-block:: python', '<autodoc>')
1620
self.add_line('', '<autodoc>')
17-
for line in self.object.__doc__.splitlines():
21+
for line in docstring[0]:
1822
self.add_line(f' {line}', '<autodoc>')
1923
self.add_line('', '<autodoc>')
24+
25+
# Add any additional content from parent class
26+
super().add_content(more_content)
2027

2128
class RawFunctionDocumenter(RawDocumenterMixin, FunctionDocumenter):
2229
objtype = 'function'
30+
priority = 10 + FunctionDocumenter.priority
2331

2432
class RawMethodDocumenter(RawDocumenterMixin, MethodDocumenter):
2533
objtype = 'method'
34+
priority = 10 + MethodDocumenter.priority
2635

2736
class RawClassDocumenter(RawDocumenterMixin, ClassDocumenter):
2837
objtype = 'class'
38+
priority = 10 + ClassDocumenter.priority
39+
40+
def setup(app):
41+
app.add_autodocumenter(RawFunctionDocumenter)
42+
app.add_autodocumenter(RawMethodDocumenter)
43+
app.add_autodocumenter(RawClassDocumenter)
44+
return {'version': '1.0', 'parallel_read_safe': True}

docs/source/api.rst

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
API Documentation
22
================
33

4-
.. automodule:: wdoc
5-
:members:
6-
:undoc-members:
7-
:show-inheritance:
8-
:private-members:
9-
:noindex:
4+
Core Module
5+
----------
106

117
.. automodule:: wdoc.wdoc
128
:members:
139
:undoc-members:
1410
:show-inheritance:
1511
:private-members:
16-
:noindex:
12+
:special-members:
13+
14+
Utility Modules
15+
-------------
16+
17+
Miscellaneous Utilities
18+
~~~~~~~~~~~~~~~~~~~~~~
1719

1820
.. automodule:: wdoc.utils.misc
1921
:members:
2022
:undoc-members:
2123
:show-inheritance:
2224
:private-members:
23-
:noindex:
25+
:special-members:
26+
27+
Logger
28+
~~~~~~
2429

2530
.. automodule:: wdoc.utils.logger
2631
:members:
2732
:undoc-members:
2833
:show-inheritance:
2934
:private-members:
30-
:noindex:
35+
:special-members:
36+
37+
LLM Utilities
38+
~~~~~~~~~~~~
3139

3240
.. automodule:: wdoc.utils.llm
3341
:members:
3442
:undoc-members:
3543
:show-inheritance:
3644
:private-members:
37-
:noindex:
45+
:special-members:

0 commit comments

Comments
 (0)