python: define our own SVG DisplayObject

This is to workaround differences in minidom's pretty-printing that
occurred between Python 3.7 and 3.8.

* python/spot/jupyter.py (SVG): New class.
* python/spot/__init__.py: Use it.
* tests/python/_altscc.ipynb, tests/python/alternation.ipynb,
tests/python/automata.ipynb, tests/python/formulas.ipynb,
tests/python/gen.ipynb, tests/python/highlighting.ipynb,
tests/python/ltsmin-dve.ipynb, tests/python/ltsmin-pml.ipynb,
tests/python/product.ipynb, tests/python/randaut.ipynb,
tests/python/testingaut.ipynb, tests/python/twagraph-internals.ipynb,
tests/python/word.ipynb: Adjust.
This commit is contained in:
Alexandre Duret-Lutz 2019-12-04 23:05:51 +01:00
parent 44df3c0837
commit e778965730
15 changed files with 14765 additions and 14141 deletions

View file

@ -150,7 +150,7 @@ class twa:
# Load the SVG function only if we need it. This way the
# bindings can still be used outside of IPython if IPython is
# not installed.
from IPython.display import SVG
from spot.jupyter import SVG
return SVG(self._repr_svg_(opt))
def highlight_states(self, states, color):
@ -212,7 +212,7 @@ class twa_graph:
def show_storage(self, opt=None):
ostr = ostringstream()
self.dump_storage_as_dot(ostr, opt)
from IPython.display import SVG
from spot.jupyter import SVG
return SVG(_ostream_to_svg(ostr))
@ -237,7 +237,7 @@ class formula:
# Load the SVG function only if we need it. This way the bindings
# can still be used outside of IPython if IPython is not
# installed.
from IPython.display import SVG
from spot.jupyter import SVG
return SVG(_str_to_svg(self.to_str('d')))
def _repr_latex_(self):
@ -1169,7 +1169,7 @@ def show_mp_hierarchy(cl):
Return a picture of the Manna & Pnueli hierarchy as an SVG object
in the IPython/Jupyter.
"""
from IPython.display import SVG
from spot.jupyter import SVG
return SVG(mp_hierarchy_svg(cl))
@ -1278,7 +1278,7 @@ class twa_word:
"""
Display the word as an SVG picture of signals.
"""
from IPython.display import SVG
from spot.jupyter import SVG
return SVG(self.as_svg())

View file

@ -21,8 +21,23 @@
Auxiliary functions for Spot's Python bindings.
"""
from IPython.display import display, HTML
from IPython.display import display, HTML, DisplayObject
class SVG(DisplayObject):
"""
Replacement for IPython.display.SVG that does not use
minidom to extract the <svg> element.
We need that because prior to Python 3.8, minidom used
sort all attributes, and in Python 3.8 this was changed
to keep the same order, causing test failures in our
diff-based test suite.
We do not need the <svg> extraction when processing
GraphViz output.
"""
def _repr_svg_(self):
return self.data
def display_inline(*args, per_row=None, show=None):
"""