Skip to content

Commit 4d6e16f

Browse files
docs: Improve docstring formatting and add Sphinx processing extensions
1 parent 56e9a5a commit 4d6e16f

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

docs/source/_ext/better_docstring.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from sphinx.ext.autodoc import between
2+
3+
def setup(app):
4+
# Register a priority handler for docstrings
5+
app.connect('autodoc-process-docstring', process_docstring)
6+
return {'version': '1.0', 'parallel_read_safe': True}
7+
8+
def process_docstring(app, what, name, obj, options, lines):
9+
"""Process docstrings to ensure they are properly formatted."""
10+
# Remove empty lines at start
11+
while lines and not lines[0].strip():
12+
lines.pop(0)
13+
# Remove empty lines at end
14+
while lines and not lines[-1].strip():
15+
lines.pop()
16+
17+
# Ensure there's spacing between sections
18+
new_lines = []
19+
in_section = False
20+
for line in lines:
21+
if line.strip() and line[0].isalpha() and ':' in line:
22+
if in_section:
23+
new_lines.append('')
24+
in_section = True
25+
new_lines.append(line)
26+
27+
lines[:] = new_lines

docs/source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'sphinx.ext.viewcode',
2626
'myst_parser', # for markdown support
2727
'raw_docstring',
28+
'better_docstring',
2829
'sphinx.ext.autosectionlabel'
2930
]
3031

@@ -49,6 +50,8 @@
4950
napoleon_use_ivar = True
5051
napoleon_use_param = True
5152
napoleon_use_rtype = True
53+
napoleon_attr_annotations = True
54+
napoleon_preprocess_types = True
5255

5356
templates_path = ['_templates']
5457
exclude_patterns = []

wdoc/utils/interact.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919

2020
@optional_typecheck
2121
def get_toolbar_text(settings: dict) -> Any:
22-
"parsed settings to be well displayed in the prompt toolbar"
22+
"""Parse settings for display in the prompt toolbar.
23+
24+
Args:
25+
settings (dict): Dictionary containing the current settings
26+
27+
Returns:
28+
Any: Formatted text suitable for display in the toolbar
29+
"""
2330
out = []
2431
keys = sorted(list(settings.keys()))
2532
for k in keys:
@@ -85,7 +92,14 @@ def get_completions(self, document, complete_event):
8592

8693
@optional_typecheck
8794
def show_help() -> None:
88-
"display CLI help"
95+
"""Display CLI help information.
96+
97+
This function displays the CLI help information by formatting and showing
98+
the docstring from the ask_user function.
99+
100+
Returns:
101+
None
102+
"""
89103
md_printer(dedent(ask_user.__doc__).strip())
90104

91105

0 commit comments

Comments
 (0)