-
Notifications
You must be signed in to change notification settings - Fork 742
Expand file tree
/
Copy pathdebug_docstrings.py
More file actions
30 lines (20 loc) · 895 Bytes
/
debug_docstrings.py
File metadata and controls
30 lines (20 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Extension for debugging docstrings."""
# Just do the following to see the rst of a function:
# rm ./_build/doctrees/api/generated/scanpy.<what you want>.doctree; DEBUG=1 make html
from __future__ import annotations
import os
from typing import TYPE_CHECKING
import sphinx.ext.napoleon
from sphinx.util.typing import ExtensionMetadata
if TYPE_CHECKING:
from sphinx.application import Sphinx
_pd_orig = sphinx.ext.napoleon._process_docstring
def pd_new(app, what, name, obj, options, lines) -> None: # noqa: PLR0917
"""Wrap ``sphinx.ext.napoleon._process_docstring``."""
_pd_orig(app, what, name, obj, options, lines)
print(*lines, sep="\n")
def setup(app: Sphinx) -> ExtensionMetadata:
"""App setup hook."""
if os.environ.get("DEBUG") is not None:
sphinx.ext.napoleon._process_docstring = pd_new
return ExtensionMetadata(parallel_read_safe=True)