From: Vladimír Vondruš Date: Sun, 1 Jul 2018 12:40:45 +0000 (+0200) Subject: m.dot: compatibility with Graphviz < 2.40. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2d7d3b5e1ae7f62e35203d2848e96a7836676d6f;p=blog.git m.dot: compatibility with Graphviz < 2.40. Ugh. This does not scale at all. --- diff --git a/doc/plugins/plots-and-graphs.rst b/doc/plugins/plots-and-graphs.rst index 81385d1c..ce4816bd 100644 --- a/doc/plugins/plots-and-graphs.rst +++ b/doc/plugins/plots-and-graphs.rst @@ -245,6 +245,11 @@ extensive `attribute documentation Note that currently all styling is discarded and only the ``class`` and ``fontsize`` attributes are taken into account. +.. note-warning:: + + The ``class`` attribute is new in Graphviz 2.40.1. If you have an older + version on your system, this attribute will get ignored. + `Undirected graphs`_ -------------------- diff --git a/pelican-plugins/m/dot.py b/pelican-plugins/m/dot.py index 5e2e69e9..164ff29b 100644 --- a/pelican-plugins/m/dot.py +++ b/pelican-plugins/m/dot.py @@ -43,8 +43,9 @@ _patch_dst = r"""\n""") -_class_src = re.compile(r""" -(?P[^<]*) +# Graphviz < 2.40 (Ubuntu 16.04 and older) doesn't have a linebreak between +# and +_class_src = re.compile(r"""<g id="(edge|node)\d+" class="(?P<type>edge|node)(?P<classes>[^"]*)">[\n]?<title>(?P<title>[^<]*) <(?Pellipse|polygon|path) fill="(?P[^"]+)" stroke="[^"]+" """) _class_dst = r""" @@ -55,8 +56,9 @@ _attributes_src = re.compile(r"""<(?Pellipse|polygon|polyline) fill="[^ _attributes_dst = r"""<\g """ -# re.compile() is called after replacing {font} in configure() -_text_src_src = ' font-family="{font}" font-size="(?P[^"]+)" fill="[^"]+"' +# re.compile() is called after replacing {font} in configure(). Graphviz < 2.40 +# doesn't put the fill="" attribute there +_text_src_src = ' font-family="{font}" font-size="(?P[^"]+)"( fill="[^"]+")?' _text_dst = ' style="font-size: {size}px;"' diff --git a/pelican-plugins/m/test/dot/page-236.html b/pelican-plugins/m/test/dot/page-236.html new file mode 100644 index 00000000..e740ce42 --- /dev/null +++ b/pelican-plugins/m/test/dot/page-236.html @@ -0,0 +1,211 @@ + + + + + m.dot | A Pelican Blog + + + + + + +
+
+
+
+
+
+

m.dot

+ +

Note: the test uses DejaVu Sans instead of Source Sans Pro in order to have +predictable rendering on the CIs.

+

Different shapes, fills etc. All default colors, filled only the first node +and the arrowheads, nothing else. Non-default font size should be preserved.

+
+ + +Basics + +a + +a + + +b + + +b + + +a->b + + + + +c + +c + + +b->c + + +0 + + +c->c + + +1 + + + +
+

Colors:

+
+ + +Colors + +a + +a + + +b + +b + + +a->b + + +yes + + +b->b + + +no + + + +
+

Unoriented graph:

+
+ + +A to B + +a + +a + + +b + +b + + +a--b + + + +a--b + + + + +
+

Strict graphs:

+
+ + +A to B + +a + +a + + +b + +b + + +a->b + + + + + +
+
+ + +A to B + +a + +a + + +b + +b + + +a--b + + + + +
+

Structs:

+
+ + +Structs + +struct + +a + +b + +c + +d + +e + + +another + +a + +b + +c + +d + +e + + + +
+ +
+
+
+
+
+ + diff --git a/pelican-plugins/m/test/dot/page-238.html b/pelican-plugins/m/test/dot/page-238.html new file mode 100644 index 00000000..5fa3e779 --- /dev/null +++ b/pelican-plugins/m/test/dot/page-238.html @@ -0,0 +1,211 @@ + + + + + m.dot | A Pelican Blog + + + + + + +
+
+
+
+
+
+

m.dot

+ +

Note: the test uses DejaVu Sans instead of Source Sans Pro in order to have +predictable rendering on the CIs.

+

Different shapes, fills etc. All default colors, filled only the first node +and the arrowheads, nothing else. Non-default font size should be preserved.

+
+ + +Basics + +a + +a + + +b + + +b + + +a->b + + + + +c + +c + + +b->c + + +0 + + +c->c + + +1 + + + +
+

Colors:

+
+ + +Colors + +a + +a + + +b + +b + + +a->b + + +yes + + +b->b + + +no + + + +
+

Unoriented graph:

+
+ + +A to B + +a + +a + + +b + +b + + +a--b + + + +a--b + + + + +
+

Strict graphs:

+
+ + +A to B + +a + +a + + +b + +b + + +a->b + + + + + +
+
+ + +A to B + +a + +a + + +b + +b + + +a--b + + + + +
+

Structs:

+
+ + +Structs + +struct + +a + +b + +c + +d + +e + + +another + +a + +b + +c + +d + +e + + + +
+ +
+
+
+
+
+ + diff --git a/pelican-plugins/m/test/test_dot.py b/pelican-plugins/m/test/test_dot.py index 5938a1af..3a3dc7b5 100644 --- a/pelican-plugins/m/test/test_dot.py +++ b/pelican-plugins/m/test/test_dot.py @@ -22,6 +22,8 @@ # DEALINGS IN THE SOFTWARE. # +import re +import subprocess import sys import unittest @@ -29,12 +31,16 @@ from distutils.version import LooseVersion from m.test import PluginTestCase +def dot_version(): + return re.match(".*version (?P\d+\.\d+\.\d+).*", subprocess.check_output(['dot', '-V'], stderr=subprocess.STDOUT).decode('utf-8').strip()).group('version') + class Dot(PluginTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, '', *args, **kwargs) - @unittest.skipUnless(LooseVersion(sys.version) >= LooseVersion("3.5"), - "The math plugin requires at least Python 3.5 installed") + @unittest.skipUnless(LooseVersion(sys.version) >= LooseVersion("3.5") and + LooseVersion(dot_version()) >= LooseVersion("2.40.1"), + "The math plugin requires at least Python 3.5 installed. Dot < 2.40.1 has a completely different output.") def test(self): self.run_pelican({ 'PLUGINS': ['m.htmlsanity', 'm.dot'], @@ -42,3 +48,26 @@ class Dot(PluginTestCase): }) self.assertEqual(*self.actual_expected_contents('page.html')) + + @unittest.skipUnless(LooseVersion(sys.version) >= LooseVersion("3.5") and + LooseVersion(dot_version()) < LooseVersion("2.40.1") and + LooseVersion(dot_version()) >= LooseVersion("2.38.0"), + "The math plugin requires at least Python 3.5 installed. Dot < 2.38 and dot > 2.38 has a completely different output.") + def test_238(self): + self.run_pelican({ + 'PLUGINS': ['m.htmlsanity', 'm.dot'], + 'M_DOT_FONT': 'DejaVu Sans' + }) + + self.assertEqual(*self.actual_expected_contents('page.html', 'page-238.html')) + + @unittest.skipUnless(LooseVersion(sys.version) >= LooseVersion("3.5") and + LooseVersion(dot_version()) < LooseVersion("2.38.0"), + "The math plugin requires at least Python 3.5 installed. Dot > 2.36 has a completely different output.") + def test_236(self): + self.run_pelican({ + 'PLUGINS': ['m.htmlsanity', 'm.dot'], + 'M_DOT_FONT': 'DejaVu Sans' + }) + + self.assertEqual(*self.actual_expected_contents('page.html', 'page-236.html'))