Subject: bug#25834: [PATCH 5/7] gnu: python-matplotlib: Update to 2.0.0.

From: Thomas Danckaert <[email-masked]>
Date: Thu, 23 Feb 2017 09:48:46 +0100 (CET)

From: Thomas Danckaert <[email-masked]>
Subject: bug#25834: [PATCH 5/7] gnu: python-matplotlib: Update to 2.0.0.
Date: Wed, 22 Feb 2017 12:22:51 +0100

> From: Thomas Danckaert <[email-masked]>
> 
> * gnu/packages/python.scm (python-matplotlib): Update to 2.0.0.
> [source]: Remove Tk backend patch, use Github instead of Sourceforge.
> [outputs]: Remove "doc" output.
> [propagated-inputs]: Add python-cycler.
> [native-inputs]: Remove python-sphinx, python-numpydoc, texlive and texinfo.
> (python-matplotlib-documentation, python2-matplotlib-documentation): New
> variable.
> * gnu/packages/patches/matplotlib-setupext-tk.patch: Delete file.
> * gnu/local.mk (dist_patch_DATA): Remove patch.

I send an updated patch because I've realized that we now have python-qt as well.  Adding python-qt enables the Qt5Agg backend (interactive plotting widget using Qt).

I'm not sure if it should be a propagated input, though.  With
python-qt as a regular input, the users have to install python-qt into
their profile if they want to use the Qt5Agg backend.  When you ask matplotlib to use Qt5Agg but don't have python-qt in your profile, you get the following error:

> ImportError: Matplotlib qt-based backends require an external PyQt4,
> PyQt5, or PySide package to be installed, but it was not found.

This is unlike the TkAgg backend (similar plotting widget using Tk), which is available immediately (I think because of the propagated python-tkinter).  Is this OK, or do we want to propagate python-qt as well so everything works immediately?

The GtkAgg backend seems work automatically when in Gnome shell, but not in xfce4 (and the error message is not helpful).  My guess is that something is missing from $GI_TYPELIB_PATH in xfce4.  In a Gnome session, $GI_TYPELIB_PATH contains a big list of entries, while in an xfce4, it only contains ${HOME}/.guix-profile/lib/girepository-1.0.

Thomas
>From 548df3e2ee7288be93146d7164e8e0c37ce21ce8 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 22:18:45 +0100
Subject: [PATCH] gnu: python-matplotlib: Update to 2.0.0.

* gnu/packages/python.scm (python-matplotlib): Update to 2.0.0.
[source]: Remove Tk backend patch, use Github instead of Sourceforge.
[outputs]: Remove "doc" output.
[inputs]: Add python-pyqt.
[propagated-inputs]: Add python-cycler.
[native-inputs]: Remove python-sphinx, python-numpydoc, texlive and texinfo.
(python-matplotlib-documentation, python2-matplotlib-documentation): New
variables.
* gnu/packages/patches/matplotlib-setupext-tk.patch: Delete file.
* gnu/local.mk (dist_patch_DATA): Remove patch.
---
 gnu/local.mk                                      |   1 -
 gnu/packages/patches/matplotlib-setupext-tk.patch |  34 -----
 gnu/packages/python.scm                           | 144 ++++++++++++----------
 3 files changed, 80 insertions(+), 99 deletions(-)
 delete mode 100644 gnu/packages/patches/matplotlib-setupext-tk.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index ca415ec48..13faeeba8 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -748,7 +748,6 @@ dist_patch_DATA =						\
   %D%/packages/patches/make-impure-dirs.patch			\
   %D%/packages/patches/mars-install.patch			\
   %D%/packages/patches/mars-sfml-2.3.patch			\
-  %D%/packages/patches/matplotlib-setupext-tk.patch		\
   %D%/packages/patches/maxima-defsystem-mkdir.patch		\
   %D%/packages/patches/mcron-install.patch			\
   %D%/packages/patches/mcrypt-CVE-2012-4409.patch			\
diff --git a/gnu/packages/patches/matplotlib-setupext-tk.patch b/gnu/packages/patches/matplotlib-setupext-tk.patch
deleted file mode 100644
index 37c3d686e..000000000
--- a/gnu/packages/patches/matplotlib-setupext-tk.patch
+++ /dev/null
@@ -1,34 +0,0 @@
-Use 'pkg-config' instead of heuristics to find 'tk' flags.
-
---- matplotlib-1.4.3/setupext.py.orig	2015-12-01 14:21:19.554417453 +0100
-+++ matplotlib-1.4.3/setupext.py	2015-12-02 10:39:47.282363530 +0100
-@@ -1457,7 +1457,7 @@
-             p = subprocess.Popen(
-                 '. %s ; eval echo ${%s}' % (file, varname),
-                 shell=True,
--                executable="/bin/sh",
-+                executable="sh",
-                 stdout=subprocess.PIPE)
-             result = p.communicate()[0]
-             return result.decode('ascii')
-@@ -1601,8 +1601,19 @@
-             #      of distros.
- 
-             # Query Tcl/Tk system for library paths and version string
-+            def getoutput(s):
-+                ret = os.popen(s).read().strip()
-+                return ret
-             try:
--                tcl_lib_dir, tk_lib_dir, tk_ver = self.query_tcltk()
-+                pkg_config_libs = getoutput('pkg-config --libs-only-L tk').split()
-+                # drop '-L' part of strings
-+                pkg_config_libs = [s[2:] for s in pkg_config_libs]
-+                pkg_config_ver = getoutput('pkg-config --modversion tk')
-+                tk_ver = re.match(r"(\d+.\d+)[\d.]*", pkg_config_ver).group(1)
-+                tcl_lib_dir = next(s for s in pkg_config_libs
-+                                   if re.match(r".*-tcl-.*", s)) + '/tcl' + tk_ver
-+                tk_lib_dir = next(s for s in pkg_config_libs
-+                                  if re.match(r".*-tk-.*", s)) + '/tk' + tk_ver
-             except:
-                 tk_ver = ''
-                 result = self.hardcoded_tcl_config()
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index c45cc9db4..cae01b841 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -3675,21 +3675,20 @@ between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.")
 (define-public python-matplotlib
   (package
     (name "python-matplotlib")
-    (version "1.4.3")
+    (version "2.0.0")
     (source
      (origin
        (method url-fetch)
-       (uri (string-append "mirror://sourceforge/matplotlib/matplotlib"
-                           "/matplotlib-" version
-                           "/matplotlib-" version ".tar.gz"))
+       (uri (string-append
+             "https://github.com/matplotlib/matplotlib/archive/v" version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32
-         "1dn05cvd0g984lzhh72wa0z93psgwshbbg93fkab6slx5m3l95av"))
-       (patches (search-patches "matplotlib-setupext-tk.patch"))))
+         "0w3k5m5qb3wsd7yhvmg042xddvligklvcq2visk2c5wnph3hhsln"))))
     (build-system python-build-system)
-    (outputs '("out" "doc"))
     (propagated-inputs ; the following packages are all needed at run time
-     `(("python-pyparsing" ,python-pyparsing)
+     `(("python-cycler" ,python-cycler)
+       ("python-pyparsing" ,python-pyparsing)
        ("python-pygobject" ,python-pygobject)
        ("gobject-introspection" ,gobject-introspection)
        ("python-tkinter" ,python "tk")
@@ -3721,75 +3720,33 @@ between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.")
        ("glib" ,glib)
        ;; FIXME: Add backends when available.
        ;("python-wxpython" ,python-wxpython)
-       ;("python-pyqt" ,python-pyqt)
+       ("python-pyqt" ,python-pyqt)
        ("tcl" ,tcl)
        ("tk" ,tk)))
     (native-inputs
      `(("pkg-config" ,pkg-config)
-       ("python-sphinx" ,python-sphinx)
-       ("python-numpydoc" ,python-numpydoc)
        ("python-nose" ,python-nose)
-       ("python-mock" ,python-mock)
-       ("texlive" ,texlive)
-       ("texinfo" ,texinfo)))
+       ("python-mock" ,python-mock)))
     (arguments
      `(#:phases
-       (alist-cons-before
-        'build 'configure-environment
-        (lambda* (#:key outputs inputs #:allow-other-keys)
-          (let ((cairo (assoc-ref inputs "cairo"))
-                (gtk+ (assoc-ref inputs "gtk+")))
-            ;; Setting these directories in the 'basedirlist' of 'setup.cfg'
-            ;; has not effect.
-            (setenv "LD_LIBRARY_PATH"
-                    (string-append cairo "/lib:" gtk+ "/lib"))
-            (setenv "HOME" (getcwd))
-            (call-with-output-file "setup.cfg"
+       (modify-phases %standard-phases
+         (add-before 'build 'configure-environment
+           (lambda* (#:key outputs inputs #:allow-other-keys)
+             (let ((cairo (assoc-ref inputs "cairo"))
+                   (gtk+ (assoc-ref inputs "gtk+")))
+               ;; Setting these directories in the 'basedirlist' of 'setup.cfg'
+               ;; has not effect.
+               (setenv "LD_LIBRARY_PATH"
+                       (string-append cairo "/lib:" gtk+ "/lib"))
+               (setenv "HOME" (getcwd))
+               (call-with-output-file "setup.cfg"
               (lambda (port)
                 (format port "[directories]~%
 basedirlist = ~a,~a~%
  [rc_options]~%
 backend = TkAgg~%"
                         (assoc-ref inputs "tcl")
-                        (assoc-ref inputs "tk"))))))
-        (alist-cons-after
-         'install 'install-doc
-         (lambda* (#:key inputs outputs #:allow-other-keys)
-           (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
-                  (doc (string-append data "/doc/" ,name "-" ,version))
-                  (info (string-append data "/info"))
-                  (html (string-append doc "/html")))
-             ;; Make installed package available for building the
-             ;; documentation
-             (add-installed-pythonpath inputs outputs)
-             (with-directory-excursion "doc"
-               ;; Produce pdf in 'A4' format.
-               (substitute* (find-files "." "conf\\.py")
-                 (("latex_paper_size = 'letter'")
-                  "latex_paper_size = 'a4'"))
-               (mkdir-p html)
-               (mkdir-p info)
-               ;; The doc recommends to run the 'html' target twice.
-               (system* "python" "make.py" "html")
-               (system* "python" "make.py" "html")
-               (copy-recursively "build/html" html)
-               (system* "python" "make.py" "latex")
-               (system* "python" "make.py" "texinfo")
-               (symlink (string-append html "/_images")
-                        (string-append info "/matplotlib-figures"))
-               (with-directory-excursion "build/texinfo"
-                 (substitute* "matplotlib.texi"
-                   (("@image\\{([^,]*)" all file)
-                    (string-append "@image{matplotlib-figures/" file)))
-                 (symlink (string-append html "/_images")
-                          "./matplotlib-figures")
-                 (system* "makeinfo" "--no-split"
-                          "-o" "matplotlib.info" "matplotlib.texi"))
-               (copy-file "build/texinfo/matplotlib.info"
-                          (string-append info "/matplotlib.info"))
-               (copy-file "build/latex/Matplotlib.pdf"
-                          (string-append doc "/Matplotlib.pdf")))))
-        %standard-phases))))
+                        (assoc-ref inputs "tk"))))))))))
     (home-page "http://matplotlib.org")
     (synopsis "2D plotting library for Python")
     (description
@@ -3814,6 +3771,65 @@ toolkits.")
          ,@(fold alist-delete (package-propagated-inputs matplotlib)
                  '("python-pycairo" "python-pygobject" "python-tkinter")))))))
 
+(define-public python-matplotlib-documentation
+  (package
+    (inherit python-matplotlib)
+    (name "python-matplotlib-documentation")
+    (native-inputs
+     `(("python-colorspacious" ,python-colorspacious)
+       ("python-sphinx" ,python-sphinx)
+       ("python-numpydoc" ,python-numpydoc)
+       ("python-ipython" ,python-ipython)
+       ("texlive" ,texlive)
+       ("texinfo" ,texinfo)
+       ,@(package-native-inputs python-matplotlib)))
+    (arguments
+     `(#:tests? #f ; we're only generating documentation
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'build)
+         (replace 'install
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (add-installed-pythonpath inputs outputs)
+             (let* ((data (string-append (assoc-ref outputs "out") "/share"))
+                    (doc (string-append data "/doc/" ,name "-"
+                                        ,(package-version python-matplotlib)))
+                    (info (string-append data "/info"))
+                    (html (string-append doc "/html")))
+               ;; Make installed package available for building the
+               ;; documentation
+               (with-directory-excursion "doc"
+                 ;; Produce pdf in 'A4' format.
+                 (substitute* (find-files "." "conf\\.py")
+                   (("latex_paper_size = 'letter'")
+                    "latex_paper_size = 'a4'"))
+                 (mkdir-p html)
+                 (mkdir-p info)
+                 ;; The doc recommends to run the 'html' target twice.
+                 (system* "python" "make.py" "html")
+                 (system* "python" "make.py" "html")
+                 (copy-recursively "build/html" html)
+                 (system* "python" "make.py" "latex")
+                 (system* "python" "make.py" "texinfo")
+                 (symlink (string-append html "/_images")
+                          (string-append info "/matplotlib-figures"))
+                 (with-directory-excursion "build/texinfo"
+                   (substitute* "matplotlib.texi"
+                     (("@image\\{([^,]*)" all file)
+                      (string-append "@image{matplotlib-figures/" file)))
+                   (symlink (string-append html "/_images")
+                            "./matplotlib-figures")
+                   (system* "makeinfo" "--no-split"
+                            "-o" "matplotlib.info" "matplotlib.texi"))
+                 (copy-file "build/texinfo/matplotlib.info"
+                            (string-append info "/matplotlib.info"))
+                 (copy-file "build/latex/Matplotlib.pdf"
+                            (string-append doc "/Matplotlib.pdf")))))))))
+    (synopsis "Documentation for the python-matplotlib package")))
+
+(define-public python2-matplotlib-documentation
+  (package-with-python2 python-matplotlib-documentation))
+
 (define-public python2-pysnptools
   (package
     (name "python2-pysnptools")
-- 
2.11.1