-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuilders.py
39 lines (28 loc) · 1.03 KB
/
builders.py
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
39
"""Sphinx builders for pytest."""
from __future__ import annotations
from docutils import nodes
from sphinx.application import Sphinx
from sphinx.builders.dummy import DummyBuilder
class DoctreeBuilder(DummyBuilder):
"""A builder that only builds the the initial doctrees,
without subsequent events or post-transforms.
The doctrees are stored in the `doctrees` attribute, rather than saved to disk.
"""
name = "doctree"
def init(self) -> None:
self.doctrees: dict[str, nodes.document] = {}
def write_doctree(
self, docname: str, doctree: nodes.document, *, _cache: bool = True
) -> None:
# save the doctree instead of pickling to disk
self.doctrees[docname] = doctree
def build(self, *args, **kwargs) -> None:
# don't run anything after the initial doctree reads
self.read()
def setup(app: Sphinx) -> dict:
app.add_builder(DoctreeBuilder)
return {
"version": "1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}