-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathepytext.py
More file actions
28 lines (24 loc) · 800 Bytes
/
epytext.py
File metadata and controls
28 lines (24 loc) · 800 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
import re
from sphinx.application import Sphinx
RULES = (
(r"<(!BLANKLINE)[\w.]+>", r""),
(r"L{([\w.()]+)}", r":class:`\1`"),
(r"[LC]{(\w+\.\w+)\(\)}", r":func:`\1`"),
(r"C{([\w.()]+)}", r":class:`\1`"),
(r"[IBCM]{([^}]+)}", r"`\1`"),
('pyspark.rdd.RDD', 'RDD'),
)
def _convert_epytext(line: str) -> str:
"""
>>> _convert_epytext("L{A}")
:class:`A`
"""
line = line.replace('@', ':')
for p, sub in RULES:
line = re.sub(p, sub, line)
return line
def _process_docstring(app: "Sphinx", what: str, name: str, obj: object, options: dict, lines: list[str]) -> None:
for i in range(len(lines)):
lines[i] = _convert_epytext(lines[i])
def setup(app: "Sphinx") -> None:
app.connect("autodoc-process-docstring", _process_docstring)