Closed rappdw closed 3 years ago
The sphinx Graphviz extension adds a graphviz
node to the document tree (rather than image
).
Adding the following to the sphinx conf.py
will workaround the above issue. I suspect it requires some refinement to cover all cases.
Uncertain why the sphinx extension doesn't conform to the DocUtils dtd, and I'm not sure that this workaround would be the best way to handle things in general.
import rinoh as rt
from sphinx.ext.graphviz import render_dot
from rinoh.frontend.rst.nodes import Image
class Graphviz(Image):
def __init__(self, doctree_node, **context):
super().__init__(doctree_node, **context)
self.code = doctree_node.attributes['code']
def build_flowable(self):
sphinx_app = self.context['sphinx_builder'].app
options = self.options
fname, outfn = render_dot(sphinx_app, self.code, options, sphinx_app.config.graphviz_output_format)
return rt.Image(outfn, **options)
Your code looks like a good way to implement support for the graphviz extension into rinohtype. If you can provide a PR (add the code to src/rinoh/frontend/sphinx/nodes.py
, preferably including a regression test), I'm happy to merge it!
The sphinx Graphviz extension adds a
graphviz
node to the document tree (rather thanimage
).
I see this approach used in many extensions, presumably because this is how things are documented in the Sphinx manual. It took me a while to realize that in most cases it's possible to make use of existing docutils/Sphinx nodes instead of creating new ones. And that's probably only because I'm developing a third-party Sphinx builder.
You could file an issue on the Sphinx issue tracker to bring this to the attention of the Sphinx developers, but I'm not sure how important refactoring this is to them.
The sphinxcontrib-drawio extension's implementation is a good reference for how this type of extension (image generation) can be implemented independent of the builders. For general remarks on Sphinx extensions, see:
I'm trying to run the regression tests (following outline in DEVELOPING.rst) and most of the regressions tests are failing with the following error. I'm guessing I'm overlooking something simple, but it's not obvious to me. (Running on OSX, and I've brew install poppler.)
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/Users/drapp/dev/rinohtype/tests_regression/helpers/diffpdf.py", line 127, in diff_page
if compare_page(a_filename, b_filename, a_page, b_page):
File "/Users/drapp/dev/rinohtype/tests_regression/helpers/diffpdf.py", line 152, in compare_page
compare = Popen(MAGICK + ['compare', '-', '-metric', 'AE', 'null:'],
File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'compare'```
You also need ImageMagick (compare, convert, ...), which can also be installed by Homebrew.
I should check for ImageMagick in the diffpdf script and exit with a clear error message.
I should check for ImageMagick in the diffpdf script and exit with a clear error message.
Added in 06e7490e316ba74470ccb3af548c101ea834126f.
Graphviz support was implemented in #300.
repo to reproduce problem is here: github.com/rappdw/rinoh_error@graphviz
(log file is also in repo, but included here as well)