From 6e8b2442f7d9884d66a8425bdf95fe81ae85e5df Mon Sep 17 00:00:00 2001
From: Greg Hogan <code@greghogan.com>
Date: Wed, 31 Mar 2021 17:06:20 +0000
Subject: [PATCH 3/4] gnu: python-matplotlib: Update to 3.4.2.

* gnu/packages/python-xyz.scm (python-matplotlib): Update to 3.4.2.
[source]: Update patches.
[propagated-inputs]: Add python-certifi, qhull.
[arguments]: Fix tests and config file newline formatting.
* gnu/packages/patches/python-matplotlib-fix-tests.patch: New file.
* gnu/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch:
Remove file.
* gnu/local.mk: Update list of patches.
---
 gnu/local.mk                                  |  2 +-
 .../patches/python-matplotlib-fix-tests.patch | 40 +++++++++++++++++++
 ...on-matplotlib-run-under-wayland-gtk3.patch | 31 --------------
 gnu/packages/python-xyz.scm                   | 21 ++++++----
 4 files changed, 54 insertions(+), 40 deletions(-)
 create mode 100644 gnu/packages/patches/python-matplotlib-fix-tests.patch
 delete mode 100644 gnu/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 8355a208ea..f7d2b1146b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1598,7 +1598,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/python-pyfakefs-remove-bad-test.patch	\
   %D%/packages/patches/python-flint-includes.patch		\
   %D%/packages/patches/python-libxml2-utf8.patch		\
-  %D%/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch	\
+  %D%/packages/patches/python-matplotlib-fix-tests.patch	\
   %D%/packages/patches/python-mediafile-wavpack.patch		\
   %D%/packages/patches/python-memcached-syntax-warnings.patch	\
   %D%/packages/patches/python-mox3-python3.6-compat.patch	\
diff --git a/gnu/packages/patches/python-matplotlib-fix-tests.patch b/gnu/packages/patches/python-matplotlib-fix-tests.patch
new file mode 100644
index 0000000000..d9622bab71
--- /dev/null
+++ b/gnu/packages/patches/python-matplotlib-fix-tests.patch
@@ -0,0 +1,40 @@
+Patch the tests to prevent the error "pytest ids must be list of strings, found: 0".
+
+The PyTest documentation states that "Numbers, strings, booleans and None will
+have their usual string representation used in the test ID. For other objects,
+pytest will make a string based on the argument name".
+
+https://docs.pytest.org/en/6.2.x/example/parametrize.html#different-options-for-test-ids
+
+--- a/lib/matplotlib/tests/test_mathtext.py
++++ b/lib/matplotlib/tests/test_mathtext.py
+@@ -184,8 +184,7 @@ def baseline_images(request, fontset, index, text):
+     return ['%s_%s_%02d' % (request.param, fontset, index)]
+ 
+ 
+-@pytest.mark.parametrize(
+-    'index, text', enumerate(math_tests), ids=range(len(math_tests)))
++@pytest.mark.parametrize('index, text', enumerate(math_tests))
+ @pytest.mark.parametrize(
+     'fontset', ['cm', 'stix', 'stixsans', 'dejavusans', 'dejavuserif'])
+ @pytest.mark.parametrize('baseline_images', ['mathtext'], indirect=True)
+@@ -197,8 +196,7 @@ def test_mathtext_rendering(baseline_images, fontset, index, text):
+              horizontalalignment='center', verticalalignment='center')
+ 
+ 
+-@pytest.mark.parametrize('index, text', enumerate(lightweight_math_tests),
+-                         ids=range(len(lightweight_math_tests)))
++@pytest.mark.parametrize('index, text', enumerate(lightweight_math_tests))
+ @pytest.mark.parametrize('fontset', ['dejavusans'])
+ @pytest.mark.parametrize('baseline_images', ['mathtext1'], indirect=True)
+ @image_comparison(baseline_images=None, extensions=['png'])
+@@ -208,8 +206,7 @@ def test_mathtext_rendering_lightweight(baseline_images, fontset, index, text):
+              horizontalalignment='center', verticalalignment='center')
+ 
+ 
+-@pytest.mark.parametrize(
+-    'index, text', enumerate(font_tests), ids=range(len(font_tests)))
++@pytest.mark.parametrize('index, text', enumerate(font_tests))
+ @pytest.mark.parametrize(
+     'fontset', ['cm', 'stix', 'stixsans', 'dejavusans', 'dejavuserif'])
+ @pytest.mark.parametrize('baseline_images', ['mathfont'], indirect=True)
diff --git a/gnu/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch b/gnu/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch
deleted file mode 100644
index 6f067763b5..0000000000
--- a/gnu/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch
+++ /dev/null
@@ -1,31 +0,0 @@
-From: Tobias Geerinckx-Rice <me@tobias.gr>
-Date: Tue, 02 Mar 2021 18:04:33 +0100
-Subject: [PATCH] gnu: python-matplotlib: Run under Wayland with GTK3.
-
-Adopted from upstream's fix[0] for
-<https://github.com/matplotlib/matplotlib/issues/19405>.
-
-[0]: https://github.com/liuyun88/matplotlib/commit/3d5000463bd23cb046681220f5511f07743f7d82
-
----
-diff -Naur a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py
---- a/lib/matplotlib/backends/backend_gtk3.py	2019-11-21 23:47:05.000000000 +0100
-+++ b/lib/matplotlib/backends/backend_gtk3.py	2021-03-02 18:00:57.479929766 +0100
-@@ -42,11 +42,12 @@
- 
- try:
-+    _display = Gdk.Display.get_default()
-     cursord = {
--        cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
--        cursors.HAND          : Gdk.Cursor.new(Gdk.CursorType.HAND2),
--        cursors.POINTER       : Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR),
--        cursors.SELECT_REGION : Gdk.Cursor.new(Gdk.CursorType.TCROSS),
--        cursors.WAIT          : Gdk.Cursor.new(Gdk.CursorType.WATCH),
-+        cursors.MOVE          : Gdk.Cursor.new_from_name(_display, "move"),
-+        cursors.HAND          : Gdk.Cursor.new_from_name(_display, "pointer"),
-+        cursors.POINTER       : Gdk.Cursor.new_from_name(_display, "default"),
-+        cursors.SELECT_REGION : Gdk.Cursor.new_from_name(_display, "crosshair"),
-+        cursors.WAIT          : Gdk.Cursor.new_from_name(_display, "wait"),
-     }
- except TypeError as exc:
-     # Happens when running headless.  Convert to ImportError to cooperate with
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 2d3be5e4fb..224a4bc8a1 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -5477,18 +5477,19 @@ convert between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.
 (define-public python-matplotlib
   (package
     (name "python-matplotlib")
-    (version "3.1.2")
+    (version "3.4.2")
     (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "matplotlib" version))
        (sha256
-        (base32 "1nmshfqh7wyg15i16hx1yiylcvzkws29ivn66n3i0wyqwcpjr3lf"))
+        (base32 "0682x8k8zs9pf7wwp1dcri5dn6i1ypj3vsv6a6jap6pzzp799nfq"))
        (patches
-        (search-patches "python-matplotlib-run-under-wayland-gtk3.patch"))))
+        (search-patches "python-matplotlib-fix-tests.patch"))))
     (build-system python-build-system)
     (propagated-inputs ; the following packages are all needed at run time
-     `(("python-cycler" ,python-cycler)
+     `(("python-certifi" ,python-certifi)
+       ("python-cycler" ,python-cycler)
        ("python-kiwisolver" ,python-kiwisolver)
        ("python-pyparsing" ,python-pyparsing)
        ("python-pygobject" ,python-pygobject)
@@ -5510,6 +5511,7 @@ convert between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.
        ("freetype" ,freetype)
        ("cairo" ,cairo)
        ("glib" ,glib)
+       ("qhull", qhull)
        ;; FIXME: Add backends when available.
        ;("python-wxpython" ,python-wxpython)
        ("tcl" ,tcl)
@@ -5540,7 +5542,7 @@ convert between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.
                                               "test_.*\\.py$"))
                (("^from matplotlib" match)
                 (string-append "import pytest\n" match))
-               (("( *)@image_comparison" match indent)
+               (("( *)(@(mpl3d_)?image_comparison|def test_get_tightbbox_polar)" match indent)
                 (string-append indent
                                "@pytest.mark.skip(reason=\"unknown minor image differences\")\n"
                                match)))
@@ -5589,10 +5591,13 @@ convert between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.
                  (setenv "CFLAGS" "-ffloat-store"))
                (call-with-output-file "setup.cfg"
                  (lambda (port)
-                   (format port "[directories]~%
+                   (format port "[directories]
 basedirlist = ~a,~a~%
-[packages]~%
-tests = True~%"
+[packages]
+tests = True~%
+[libs]
+system_freetype = true
+system_qhull = true~%"
                         (assoc-ref inputs "tcl")
                         (assoc-ref inputs "tk")))))
              #t)))))
-- 
2.31.1

