forked from scverse/scanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_images.py
More file actions
36 lines (27 loc) · 979 Bytes
/
function_images.py
File metadata and controls
36 lines (27 loc) · 979 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
31
32
33
34
35
36
"""Images for plot functions."""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
from sphinx.util.typing import ExtensionMetadata
if TYPE_CHECKING:
from typing import Any
from sphinx.application import Sphinx
from sphinx.ext.autodoc import Options
def insert_function_images( # noqa: PLR0917
app: Sphinx, what: str, name: str, obj: Any, options: Options, lines: list[str]
) -> None:
"""Insert images for plot functions."""
path = app.config.api_dir / f"{name}.png"
if what != "function" or not path.is_file():
return
lines[0:0] = [
f".. image:: {path.name}",
" :width: 200",
" :align: right",
"",
]
def setup(app: Sphinx) -> ExtensionMetadata:
"""App setup hook."""
app.add_config_value("api_dir", Path(), "env")
app.connect("autodoc-process-docstring", insert_function_images)
return ExtensionMetadata(parallel_read_safe=True)