Skip to content

Commit c78ebb5

Browse files
committed
chore(docs): guard graphviz build when dot missing
1 parent d85c6b0 commit c78ebb5

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/source/conf.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
import docutils.nodes, os, logging, re, sys
13+
import base64
14+
import docutils.nodes, os, logging, re, sys, shutil, posixpath
1415
from docutils import nodes
1516
from packaging.version import Version
1617
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
1721

1822

1923
sys.path.insert(0, os.path.abspath("../.."))
@@ -70,6 +74,30 @@
7074
# 'nbsphinx.localfile', # Suppresses local file warnings in notebooks
7175
#]
7276

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+
73101
#FIXME Why is sphinx/autodoc failing here?
74102
nitpick_ignore = [
75103
('py:class', '1'), # Ex: api : Optional[Literal[1, 3]]

0 commit comments

Comments
 (0)