aboutsummaryrefslogtreecommitdiff
path: root/python/docs/epytext.py
blob: 61d731bff570d5e8124a25fae67810a343ce2649 (plain) (blame)
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
import re

RULES = (
    (r"<[\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):
    """
    >>> _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, what, name, obj, options, lines):
    for i in range(len(lines)):
        lines[i] = _convert_epytext(lines[i])

def setup(app):
    app.connect("autodoc-process-docstring", _process_docstring)