From: Vladimír Vondruš Date: Mon, 3 Jan 2022 11:39:59 +0000 (+0100) Subject: m.plots: adapt to changes in matplotlib 3.4. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=3a38f75e4334674bc04745b326af1f5228aa1fdd;p=blog.git m.plots: adapt to changes in matplotlib 3.4. Version 3.5 is a whole other beast (different order of XML attributes altogether), will need to be handled in a separate step. --- diff --git a/documentation/test_python/page_plugins/plots-32.html b/documentation/test_python/page_plugins/plots-32.html new file mode 100644 index 00000000..c1f9746c --- /dev/null +++ b/documentation/test_python/page_plugins/plots-32.html @@ -0,0 +1,163 @@ + + + + + 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.html b/documentation/test_python/page_plugins/plots.html index c1f9746c..a0b54cf8 100644 --- a/documentation/test_python/page_plugins/plots.html +++ b/documentation/test_python/page_plugins/plots.html @@ -35,19 +35,19 @@ div.m-plot svg { font-family: DejaVu Sans; } 15.0 meters, i guess? - + 30.0 meters, i guess? - + - + - + @@ -57,7 +57,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -67,7 +67,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -77,7 +77,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -87,7 +87,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -97,7 +97,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -107,7 +107,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -122,10 +122,10 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - + @@ -135,7 +135,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -149,7 +149,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + diff --git a/documentation/test_python/test_page.py b/documentation/test_python/test_page.py index 42e432de..276dc199 100644 --- a/documentation/test_python/test_page.py +++ b/documentation/test_python/test_page.py @@ -92,8 +92,11 @@ class Plugins(BaseTestCase): self.assertEqual(*self.actual_expected_contents('dot.html', file)) # 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')) + # keeping it separate. (Yes, thank you past mosra. Very helpful.) + if LooseVersion(matplotlib.__version__) >= LooseVersion('3.4'): + self.assertEqual(*self.actual_expected_contents('plots.html')) + else: + self.assertEqual(*self.actual_expected_contents('plots.html', 'plots-32.html')) self.assertTrue(os.path.exists(os.path.join(self.path, 'output/tiny.png'))) import fancyline diff --git a/package/ci/circleci.yml b/package/ci/circleci.yml index 50a6b016..06727fcc 100644 --- a/package/ci/circleci.yml +++ b/package/ci/circleci.yml @@ -51,9 +51,8 @@ commands: steps: - run: name: Install Python dependencies - # Matplotlib 3.4.1 has different output AGAIN, staying on something - # older until I can investigate; on Py3.5 there's only 3.0 so this is - # being set explicitly in py36 and py37 build + # Matplotlib 3.5.1 has different order of attributes than 3.4, so can't + # just use the latest (and 3.4 is not on the Python 3.6 image) # Attrs 20.3 add some new properties that I need to ignore first, using # 19.3 instead # Pygments 2.11 (and apparently 2.10 as well) treats certain whitespace @@ -197,7 +196,7 @@ jobs: - install-base: extra: graphviz cmake ninja-build wget - install-python-deps: - matplotlib-version: ==3.3.4 + matplotlib-version: ==3.4.3 - checkout - test-theme - test-plugins @@ -212,7 +211,7 @@ jobs: - install-base: extra: graphviz cmake ninja-build wget - install-python-deps: - matplotlib-version: ==3.3.4 + matplotlib-version: ==3.4.3 - checkout - test-theme - test-plugins @@ -229,7 +228,7 @@ jobs: - install-base: extra: graphviz cmake ninja-build wget - install-python-deps: - matplotlib-version: ==3.3.4 + matplotlib-version: ==3.4.3 - checkout - test-theme - test-plugins @@ -246,7 +245,7 @@ jobs: - install-base: extra: graphviz cmake ninja-build wget - install-python-deps: - matplotlib-version: ==3.3.4 + matplotlib-version: ==3.4.3 - checkout - test-theme - test-plugins diff --git a/plugins/m/plots.py b/plugins/m/plots.py index 18a86426..179b73f4 100644 --- a/plugins/m/plots.py +++ b/plugins/m/plots.py @@ -78,10 +78,12 @@ style_mapping = { # while matplotlib 3 has a https URL, check for both. Matplotlib 3.3 has a new # field (which we're not interested in) and slightly different # formatting of the global style after (which we unify to the compact version). +# Matplotlib 3.4 drops the "Created with" comment, as that's in the +# already anyway. _patch_src = re.compile(r"""<\?xml version="1\.0" encoding="utf-8" standalone="no"\?> - + "http://www\.w3\.org/Graphics/SVG/1\.1/DTD/svg11\.dtd">( +)? 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">( .+)? diff --git a/plugins/m/test/plots/page-32.html b/plugins/m/test/plots/page-32.html new file mode 100644 index 00000000..836e2966 --- /dev/null +++ b/plugins/m/test/plots/page-32.html @@ -0,0 +1,682 @@ + + + + + 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 + + + + + + + + + +
+
+

A plot with separate colors, extra labels, error bars and custom width + height

+
+ + + + + + + + + + 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! + + + Yes. + + + + + + + + + +
+
+
+ + + + + + + + + + 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 836e2966..87863bad 100644 --- a/plugins/m/test/plots/page.html +++ b/plugins/m/test/plots/page.html @@ -38,19 +38,19 @@ div.m-plot svg { font-family: DejaVu Sans; }
15.0 meters, i guess? - + 30.0 meters, i guess? - + - + - + @@ -60,7 +60,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -70,7 +70,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -80,7 +80,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -90,7 +90,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -100,7 +100,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -110,7 +110,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -125,10 +125,10 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - + @@ -138,7 +138,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -152,7 +152,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -171,22 +171,22 @@ div.m-plot svg { font-family: DejaVu Sans; } 3.0 ± 0.1 Mondays - + 4.0 ± 2.1 Mondays - + 5.0 ± 1.0 Mondays - + - + - + @@ -196,7 +196,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -206,7 +206,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -216,7 +216,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -226,7 +226,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -236,7 +236,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -246,7 +246,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -261,10 +261,10 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - + @@ -275,7 +275,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -285,7 +285,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -295,25 +295,25 @@ div.m-plot svg { font-family: DejaVu Sans; } - - - + + + - + - - - - + + + + - - - - + + + + @@ -330,7 +330,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -348,31 +348,31 @@ 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 - + - + - + @@ -382,7 +382,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -392,7 +392,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -402,7 +402,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -412,7 +412,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -422,7 +422,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -432,7 +432,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -442,7 +442,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -452,7 +452,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -467,10 +467,10 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - + @@ -480,7 +480,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -490,7 +490,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -504,7 +504,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -521,25 +521,25 @@ 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 - + - + - + @@ -549,7 +549,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -559,7 +559,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -569,7 +569,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -579,7 +579,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -589,7 +589,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -604,10 +604,10 @@ div.m-plot svg { font-family: DejaVu Sans; } - + - + @@ -617,7 +617,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + @@ -626,38 +626,38 @@ div.m-plot svg { font-family: DejaVu Sans; } - - + + - - + + - + - - - + + + - - - + + + - - - + + + - - - + + + @@ -666,7 +666,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - + diff --git a/plugins/m/test/test_plots.py b/plugins/m/test/test_plots.py index f93e9585..5211ad73 100644 --- a/plugins/m/test/test_plots.py +++ b/plugins/m/test/test_plots.py @@ -42,9 +42,11 @@ class Plots(PelicanPluginTestCase): }) # FUCK this is annoying - if LooseVersion(matplotlib.__version__) >= LooseVersion('3.2'): + if LooseVersion(matplotlib.__version__) >= LooseVersion('3.4'): self.assertEqual(*self.actual_expected_contents('page.html')) + elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.2'): + self.assertEqual(*self.actual_expected_contents('page.html', 'page-32.html')) elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.0'): - self.assertEqual(*self.actual_expected_contents('page-30.html')) + self.assertEqual(*self.actual_expected_contents('page.html', 'page-30.html')) else: self.assertEqual(*self.actual_expected_contents('page.html', 'page-22.html'))