|
10 | 10 | # add these directories to sys.path here. If the directory is relative to the |
11 | 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
12 | 12 | # |
13 | | -import docutils.nodes, os, logging, re, sys |
| 13 | +import base64 |
| 14 | +import docutils.nodes, os, logging, re, sys, shutil, posixpath |
14 | 15 | from docutils import nodes |
15 | 16 | from packaging.version import Version |
16 | 17 | from sphinx.application import Sphinx |
| 18 | +from sphinx.ext import graphviz as sphinx_graphviz |
| 19 | +from sphinx.util.osutil import ensuredir |
| 20 | +from pathlib import Path |
17 | 21 |
|
18 | 22 |
|
19 | 23 | sys.path.insert(0, os.path.abspath("../..")) |
|
70 | 74 | # 'nbsphinx.localfile', # Suppresses local file warnings in notebooks |
71 | 75 | #] |
72 | 76 |
|
| 77 | +# Use PNG for graphviz outputs across builders and guard PR builds (RTD PRs |
| 78 | +# skip apt packages, so dot may be missing) with a tiny placeholder to keep |
| 79 | +# builds green. |
| 80 | +graphviz_output_format = "png" |
| 81 | +_graphviz_placeholder_png = base64.b64decode( |
| 82 | + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" |
| 83 | +) |
| 84 | +_orig_render_dot = sphinx_graphviz.render_dot |
| 85 | + |
| 86 | + |
| 87 | +def _render_dot_with_placeholder(self, code, options, format, prefix="graphviz", filename=None): |
| 88 | + relfn, outfn = _orig_render_dot(self, code, options, format, prefix, filename) |
| 89 | + if relfn is None: |
| 90 | + fname = f"{prefix}-placeholder.{format}" |
| 91 | + relfn = posixpath.join(self.builder.imgpath, fname) |
| 92 | + outfn = os.path.join(self.builder.outdir, self.builder.imagedir, fname) |
| 93 | + ensuredir(os.path.dirname(outfn)) |
| 94 | + if not os.path.isfile(outfn): |
| 95 | + Path(outfn).write_bytes(_graphviz_placeholder_png) |
| 96 | + return relfn, outfn |
| 97 | + |
| 98 | + |
| 99 | +sphinx_graphviz.render_dot = _render_dot_with_placeholder |
| 100 | + |
73 | 101 | #FIXME Why is sphinx/autodoc failing here? |
74 | 102 | nitpick_ignore = [ |
75 | 103 | ('py:class', '1'), # Ex: api : Optional[Literal[1, 3]] |
|
0 commit comments