From: Vladimír Vondruš Date: Sun, 7 Jul 2019 20:28:19 +0000 (+0200) Subject: m.plots: adapt for matplotlib 3.0. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=644658c758fd124a98410954429b8226671532b4;p=blog.git m.plots: adapt for matplotlib 3.0. 3.0 uses a HTTPS URL in the SVG preamble, so the regex needed updating. That's it. And I was putting this off for over a year, heh. Well, actually now I have THREE DIFFERENT OUTPUTS to test for -- Python 3.5 and older has slightly different number rounding, while matplotlib 3.1 adds a CSS property that 3.0 didn't have. Yay this is annoying as hell. --- diff --git a/documentation/test_python/page_plugins/index.html b/documentation/test_python/page_plugins/index.html index 03673af7..b39085e2 100644 --- a/documentation/test_python/page_plugins/index.html +++ b/documentation/test_python/page_plugins/index.html @@ -52,142 +52,6 @@ Yup!
Image in a subdir

~~~ Custom plugins! ~~~

-

And now something totally different:

-
- - - - - - - - - - 15.0 meters, i guess? - - - 30.0 meters, i guess? - - - - - - - - - - - - - - 0 - - - - - - - - - - 5 - - - - - - - - - - 10 - - - - - - - - - - 15 - - - - - - - - - - 20 - - - - - - - - - - 25 - - - - - - - - - - 30 - - - - meters, i guess? - - - - - - - - - - - - - - First - - - - - - - - - - Second - - - - - A plot with a single color - - - - - - - - - -
diff --git a/documentation/test_python/page_plugins/index.rst b/documentation/test_python/page_plugins/index.rst index c9a6d7f1..c8098534 100644 --- a/documentation/test_python/page_plugins/index.rst +++ b/documentation/test_python/page_plugins/index.rst @@ -41,20 +41,3 @@ Images! Image in a subdir .. fancy-line:: Custom plugins! - -And now something totally different: - -.. raw:: html - - - -.. plot:: A plot with a single color - :type: barh - :labels: - First - Second - :units: meters, i guess? - :values: 15 30 - :colors: success diff --git a/documentation/test_python/page_plugins/plots.html b/documentation/test_python/page_plugins/plots.html new file mode 100644 index 00000000..f60ed497 --- /dev/null +++ b/documentation/test_python/page_plugins/plots.html @@ -0,0 +1,165 @@ + + + + + And now something totally different | My Python Project + + + + + +
+
+
+
+
+

+ And now something totally different +

+
+ + + + + + + + + + 15.0 meters, i guess? + + + 30.0 meters, i guess? + + + + + + + + + + + + + + 0 + + + + + + + + + + 5 + + + + + + + + + + 10 + + + + + + + + + + 15 + + + + + + + + + + 20 + + + + + + + + + + 25 + + + + + + + + + + 30 + + + + meters, i guess? + + + + + + + + + + + + + + First + + + + + + + + + + Second + + + + + A plot with a single color + + + + + + + + + +
+
+
+
+
+ + diff --git a/documentation/test_python/page_plugins/plots.rst b/documentation/test_python/page_plugins/plots.rst new file mode 100644 index 00000000..15dba9c2 --- /dev/null +++ b/documentation/test_python/page_plugins/plots.rst @@ -0,0 +1,17 @@ +And now something totally different +################################### + +.. raw:: html + + + +.. plot:: A plot with a single color + :type: barh + :labels: + First + Second + :units: meters, i guess? + :values: 15 30 + :colors: success diff --git a/documentation/test_python/test_page.py b/documentation/test_python/test_page.py index 6c6f3475..0dd6a6ec 100644 --- a/documentation/test_python/test_page.py +++ b/documentation/test_python/test_page.py @@ -22,6 +22,7 @@ # DEALINGS IN THE SOFTWARE. # +import matplotlib import os import re import subprocess @@ -79,7 +80,7 @@ class Plugins(BaseTestCase): 'fancyline' ], 'PLUGIN_PATHS': ['plugins'], - 'INPUT_PAGES': ['index.rst', 'dot.rst'], + 'INPUT_PAGES': ['index.rst', 'dot.rst', 'plots.rst'], 'M_HTMLSANITY_SMART_QUOTES': True, 'M_DOT_FONT': 'DejaVu Sans', 'M_PLOTS_FONT': 'DejaVu Sans', @@ -90,8 +91,11 @@ class Plugins(BaseTestCase): self.assertEqual(*self.actual_expected_contents('index.html')) # The output is different for older Graphviz self.assertEqual(*self.actual_expected_contents('dot.html', 'dot.html' if LooseVersion(dot_version()) >= LooseVersion("2.40.1") else 'dot-238.html')) + # I assume this will be a MASSIVE ANNOYANCE at some point as well so + # keeping it separate + self.assertEqual(*self.actual_expected_contents('plots.html')) self.assertTrue(os.path.exists(os.path.join(self.path, 'output/tiny.png'))) import fancyline - self.assertEqual(fancyline.pre_page_call_count, 3) + self.assertEqual(fancyline.pre_page_call_count, 4) self.assertEqual(fancyline.post_run_call_count, 1) diff --git a/plugins/m/plots.py b/plugins/m/plots.py index 94e0b35d..41505b90 100644 --- a/plugins/m/plots.py +++ b/plugins/m/plots.py @@ -73,11 +73,12 @@ style_mapping = { 'dim': '#cafe09' } -# Patch to remove preamble and hardcoded sizes +# Patch to remove preamble and hardcoded sizes. Matplotlib 2.2 has a http URL +# while matplotlib 3 has a https URL, check for both. _patch_src = re.compile(r"""<\?xml version="1\.0" encoding="utf-8" standalone="no"\?> - + viewBox="0 0 \d+ \d+(\.\d+)?") width="\d+(\.\d+)?pt" xmlns="http://www\.w3\.org/2000/svg" xmlns:xlink="http://www\.w3\.org/1999/xlink"> """) _patch_dst = r"""> diff --git a/plugins/m/test/plots/page-22.html b/plugins/m/test/plots/page-22.html new file mode 100644 index 00000000..e6598208 --- /dev/null +++ b/plugins/m/test/plots/page-22.html @@ -0,0 +1,687 @@ + + + + + m.plots | A Pelican Blog + + + + + + +
+
+
+
+
+
+

m.plots

+ +

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

+
+ + + + + + + + + + 15.0 meters, i guess? + + + 30.0 meters, i guess? + + + + + + + + + + + + + + 0 + + + + + + + + + + 5 + + + + + + + + + + 10 + + + + + + + + + + 15 + + + + + + + + + + 20 + + + + + + + + + + 25 + + + + + + + + + + 30 + + + + meters, i guess? + + + + + + + + + + + + + + First + + + + + + + + + + Second + + + + + A plot with a single color + + + + + + + + + +
+
+ + + + + + + + + + 3.0 ± 0.1 Mondays + + + 4.0 ± 2.1 Mondays + + + 5.0 ± 1.0 Mondays + + + + + + + + + + + + + + 0 + + + + + + + + + + 1 + + + + + + + + + + 2 + + + + + + + + + + 3 + + + + + + + + + + 4 + + + + + + + + + + 5 + + + + + + + + + + 6 + + + + Mondays + + + + + + + + + + + + + + January + + + + + + + + + + + February + + + + + + + + + + March + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a paradise + + + + hell! + + + A plot with separate colors, extra labels, error bars and custom height + + + + + + + + + +
+
+ + + + + + + + + + 111.9 kB + + + 74.4 kB + + + 52.1 kB + + + 731.2 kB + + + 226.3 kB + + + 226.0 kB + + + + + + + + + + + + + + 0 + + + + + + + + + + 100 + + + + + + + + + + 200 + + + + + + + + + + 300 + + + + + + + + + + 400 + + + + + + + + + + 500 + + + + + + + + + + 600 + + + + + + + + + + 700 + + + + + + + + + + 800 + + + + kB + + + + + + + + + + + + + + A + + + + + + + + + + B + + + + + + + + + + C + + + + + Stacked plot + + + + + + + + + +
+
+ + + + + + + + + + 111.9 ± 25.0 kB + + + 74.4 ± 15.3 kB + + + 731.2 ± 200.0 kB + + + 226.3 ± 5.0 kB + + + + + + + + + + + + + + 0 + + + + + + + + + + 200 + + + + + + + + + + 400 + + + + + + + + + + 600 + + + + + + + + + + 800 + + + + + + + + + + 1000 + + + + kB + + + + + + + + + + + + + + A + + + + + + + + + + B + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stacked plot with errors and full colors + + + + + + + + + +
+ +
+
+
+
+
+ + diff --git a/plugins/m/test/plots/page-py35.html b/plugins/m/test/plots/page-py35.html new file mode 100644 index 00000000..3e538545 --- /dev/null +++ b/plugins/m/test/plots/page-py35.html @@ -0,0 +1,687 @@ + + + + + m.plots | A Pelican Blog + + + + + + +
+
+
+
+
+
+

m.plots

+ +

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

+
+ + + + + + + + + + 15.0 meters, i guess? + + + 30.0 meters, i guess? + + + + + + + + + + + + + + 0 + + + + + + + + + + 5 + + + + + + + + + + 10 + + + + + + + + + + 15 + + + + + + + + + + 20 + + + + + + + + + + 25 + + + + + + + + + + 30 + + + + meters, i guess? + + + + + + + + + + + + + + First + + + + + + + + + + Second + + + + + A plot with a single color + + + + + + + + + +
+
+ + + + + + + + + + 3.0 ± 0.1 Mondays + + + 4.0 ± 2.1 Mondays + + + 5.0 ± 1.0 Mondays + + + + + + + + + + + + + + 0 + + + + + + + + + + 1 + + + + + + + + + + 2 + + + + + + + + + + 3 + + + + + + + + + + 4 + + + + + + + + + + 5 + + + + + + + + + + 6 + + + + Mondays + + + + + + + + + + + + + + January + + + + + + + + + + + February + + + + + + + + + + March + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a paradise + + + + hell! + + + A plot with separate colors, extra labels, error bars and custom height + + + + + + + + + +
+
+ + + + + + + + + + 111.9 kB + + + 74.4 kB + + + 52.1 kB + + + 731.2 kB + + + 226.3 kB + + + 226.0 kB + + + + + + + + + + + + + + 0 + + + + + + + + + + 100 + + + + + + + + + + 200 + + + + + + + + + + 300 + + + + + + + + + + 400 + + + + + + + + + + 500 + + + + + + + + + + 600 + + + + + + + + + + 700 + + + + + + + + + + 800 + + + + kB + + + + + + + + + + + + + + A + + + + + + + + + + B + + + + + + + + + + C + + + + + Stacked plot + + + + + + + + + +
+
+ + + + + + + + + + 111.9 ± 25.0 kB + + + 74.4 ± 15.3 kB + + + 731.2 ± 200.0 kB + + + 226.3 ± 5.0 kB + + + + + + + + + + + + + + 0 + + + + + + + + + + 200 + + + + + + + + + + 400 + + + + + + + + + + 600 + + + + + + + + + + 800 + + + + + + + + + + 1000 + + + + kB + + + + + + + + + + + + + + A + + + + + + + + + + B + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stacked plot with errors and full colors + + + + + + + + + +
+ +
+
+
+
+
+ + diff --git a/plugins/m/test/plots/page.html b/plugins/m/test/plots/page.html index e6598208..6939e60d 100644 --- a/plugins/m/test/plots/page.html +++ b/plugins/m/test/plots/page.html @@ -37,13 +37,13 @@ div.m-plot svg { font-family: DejaVu Sans; } - + 15.0 meters, i guess? - + 30.0 meters, i guess? - + @@ -62,65 +62,65 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - 5 + 5 - + - 10 + 10 - + - 15 + 15 - + - 20 + 20 - + - 25 + 25 - + - 30 + 30 - meters, i guess? + meters, i guess? @@ -149,13 +149,13 @@ div.m-plot svg { font-family: DejaVu Sans; } - A plot with a single color + A plot with a single color - - + + @@ -170,16 +170,16 @@ div.m-plot svg { font-family: DejaVu Sans; } - + 3.0 ± 0.1 Mondays - + 4.0 ± 2.1 Mondays - + 5.0 ± 1.0 Mondays - + @@ -188,75 +188,75 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - 0 + 0 - + - 1 + 1 - + - 2 + 2 - + - 3 + 3 - + - 4 + 4 - + - 5 + 5 - + - 6 + 6 - Mondays + Mondays @@ -266,74 +266,74 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - January - + January + - + - February + February - + - March - + March + - - - + + + - - - - + + + + - - - - + + + + - - a paradise + + a paradise - - hell! + + hell! - A plot with separate colors, extra labels, error bars and custom height + A plot with separate colors, extra labels, error bars and custom height - - + + @@ -348,25 +348,25 @@ div.m-plot svg { font-family: DejaVu Sans; } - + 111.9 kB - + 74.4 kB - + 52.1 kB - + 731.2 kB - + 226.3 kB - + 226.0 kB - + @@ -385,85 +385,85 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - 100 + 100 - + - 200 + 200 - + - 300 + 300 - + - 400 + 400 - + - 500 + 500 - + - 600 + 600 - + - 700 + 700 - + - 800 + 800 - kB + kB @@ -502,13 +502,13 @@ div.m-plot svg { font-family: DejaVu Sans; } - Stacked plot + Stacked plot - - + + @@ -523,19 +523,19 @@ div.m-plot svg { font-family: DejaVu Sans; } - + 111.9 ± 25.0 kB - + 74.4 ± 15.3 kB - + 731.2 ± 200.0 kB - + 226.3 ± 5.0 kB - + @@ -554,55 +554,55 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - 200 + 200 - + - 400 + 400 - + - 600 + 600 - + - 800 + 800 - + - 1000 + 1000 - kB + kB @@ -631,48 +631,48 @@ div.m-plot svg { font-family: DejaVu Sans; } - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - Stacked plot with errors and full colors + Stacked plot with errors and full colors - - + + diff --git a/plugins/m/test/test_plots.py b/plugins/m/test/test_plots.py index 3660abaa..a7338080 100644 --- a/plugins/m/test/test_plots.py +++ b/plugins/m/test/test_plots.py @@ -22,9 +22,13 @@ # DEALINGS IN THE SOFTWARE. # +import matplotlib import os +import sys import unittest +from distutils.version import LooseVersion + from . import PelicanPluginTestCase class Plots(PelicanPluginTestCase): @@ -37,4 +41,11 @@ class Plots(PelicanPluginTestCase): 'M_PLOTS_FONT': 'DejaVu Sans' }) - self.assertEqual(*self.actual_expected_contents('page.html')) + # FUCK this is annoying + if LooseVersion(matplotlib.__version__) >= LooseVersion("3.0"): + if LooseVersion(sys.version) >= LooseVersion("3.6"): + self.assertEqual(*self.actual_expected_contents('page.html')) + else: + self.assertEqual(*self.actual_expected_contents('page.html', 'page-py35.html')) + else: + self.assertEqual(*self.actual_expected_contents('page.html', 'page-22.html'))