File: fix_pybind11_autodoc.py

package info (click to toggle)
pikepdf 1.17.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,548 kB
  • sloc: python: 5,210; cpp: 3,556; makefile: 248; sh: 28
file content (38 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download
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
37
38
# pybind11 generates some docstrings and function signatures that are functionally
# correct but encourage users to rely on implementation details. Fix these here.

import re

replacements = [
    (re.compile(r'pikepdf._qpdf.Object\b'), 'pikepdf.Object'),
    (re.compile(r'pikepdf._qpdf.Pdf\b'), 'pikepdf.Pdf'),
    (re.compile(r'pikepdf._qpdf.Page\b'), 'pikepdf.Page'),
    (re.compile(r'QPDFTokenizer::Token\b'), 'pikepdf.Token'),
    (re.compile(r'pikepdf._qpdf.Token\b'), 'pikepdf.Token'),
    (re.compile(r'pikepdf._qpdf.TokenFilter\b'), 'pikepdf.TokenFilter'),
    (re.compile(r'pikepdf._qpdf.TokenType\b'), 'pikepdf.TokenType'),
    (re.compile(r'QPDFObjectHandle'), 'pikepdf.Object'),
    (re.compile(r'QPDFExc'), 'pikepdf.PdfError'),
]


def fix_sigs(app, what, name, obj, options, signature, return_annotation):
    for from_, to in replacements:
        if signature:
            signature = from_.sub(to, signature)
        if return_annotation:
            return_annotation = from_.sub(to, return_annotation)
    return signature, return_annotation


def fix_doc(app, what, name, obj, options, lines):
    for n, line in enumerate(lines[:]):
        for from_, to in replacements:
            lines[n] = from_.sub(to, lines[n])


def setup(app):
    app.connect('autodoc-process-signature', fix_sigs)
    app.connect('autodoc-process-docstring', fix_doc)

    return {'version': '0.1', 'parallel_read_safe': True, 'parallel_write_safe': True}