Subject: Re: bug#25834: [PATCH] Update scipy stack.

From: Thomas Danckaert <[email-masked]>
Date: Thu, 02 Mar 2017 15:13:43 +0100 (CET)

From: Ben Woodcroft <[email-masked]>
Subject: Re: bug#25834: [PATCH] Update scipy stack.
Date: Mon, 27 Feb 2017 20:33:07 +1000

> I managed to get it downloading something with
>
>        (uri (pypi-uri "backports.shutil_get_terminal_size" version))
>
> which I ascertained by looking at the "name" in setup.py at
> https://github.com/chrippa/backports.shutil_get_terminal_size/blob/master/setup.py

Thanks (again), Ben.  I've attached an updated patch series (rebased 
on current python-tests branch).

Thomas
From b1da3400ddea2f6921e65953102bde5c4541287e Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 13:33:20 +0100
Subject: [PATCH 1/8] gnu: Add python2-backports-shutil-get-terminal-size.

* gnu/packages/python.scm (python2-backports-shutil-get-terminal-size): New
  variable.
---
 gnu/packages/python.scm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index a8ba1b8c7..03a9de576 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -33,7 +33,7 @@
 ;;; Copyright © 2016 Arun Isaac <[email-masked]>
 ;;; Copyright © 2016, 2017 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2016, 2017 Tobias Geerinckx-Rice <[email-masked]>
-;;; Copyright © 2016 Thomas Danckaert <[email-masked]>
+;;; Copyright © 2016, 2017 Thomas Danckaert <[email-masked]>
 ;;; Copyright © 2017 Carlo Zancanaro <[email-masked]>
 ;;; Copyright © 2017 Frederick M. Muriithi <[email-masked]>
 ;;;
@@ -6024,6 +6024,30 @@ connection to each user.")
 (define-public python2-backports-abc
   (package-with-python2 python-backports-abc))
 
+(define-public python2-backports-shutil-get-terminal-size
+  (package
+    (name "python2-backports-shutil-get-terminal-size")
+    (version "1.0.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "backports.shutil_get_terminal_size" version))
+       (sha256
+        (base32
+         "107cmn7g3jnbkp826zlj8rrj19fam301qvaqf0f3905f5217lgki"))))
+    (build-system python-build-system)
+    (arguments
+     `(#:python ,python-2))
+    (home-page
+     "https://github.com/chrippa/backports.shutil_get_terminal_size")
+    (synopsis
+      "Backport of Python 3.3's shutil.get_terminal_size")
+    (description
+     "A backport of the @code{get_terminal_size function} from Python 3.3's @code{shutil}.
+Unlike the original version it is written in pure Python rather than C, so it
+might be a tiny bit slower.")
+    (license license:expat)))
+
 (define-public python-waf
   (package
     (name "python-waf")
-- 
2.11.1

From 5de56bad756d816e286797b399f3442b9eb68f21 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 21:33:02 +0100
Subject: [PATCH 2/8] gnu: Add python-colorspacious.

* gnu/packages/python.scm (python-colorspacious, python2-colorspacious): New
  variables.
---
 gnu/packages/python.scm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 03a9de576..c449ccb6e 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -3763,6 +3763,31 @@ To address this and enable easy cycling over arbitrary @code{kwargs}, the
 (define-public python2-cycler
   (package-with-python2 python-cycler))
 
+(define-public python-colorspacious
+  (package
+  (name "python-colorspacious")
+  (version "1.1.0")
+  (source
+    (origin
+      (method url-fetch)
+      (uri (string-append
+            "https://github.com/njsmith/colorspacious/archive/v"
+            version ".tar.gz"))
+      (file-name (string-append name "-" version))
+      (sha256
+       (base32 "1vflh5jm32qb0skza2i8pjacv09w6gq84fqpp2nj77s0rbmzgr4k"))))
+  (build-system python-build-system)
+  (propagated-inputs
+   `(("python-numpy" ,python-numpy)))
+  (home-page "https://github.com/njsmith/colorspacious")
+  (synopsis "Python library for colorspace conversions")
+  (description "Colorspacious is a Python library that lets you easily convert
+between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.")
+  (license license:expat)))
+
+(define-public python2-colorspacious
+  (package-with-python2 python-colorspacious))
+
 (define-public python-matplotlib
   (package
     (name "python-matplotlib")
-- 
2.11.1

From b73e26ce12dc2fd0b38937bc615f5071556dfd5a Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 20:28:27 +0100
Subject: [PATCH 3/8] gnu: python-numpy: Update to 1.12.0.

* gnu/packages/python.scm (python-numpy): Update to 1.12.0.
  [source]: Use github instead of sourceforge.
  [native-inputs]: Add python-cython.

  To simplify the handling of dependency cycles (numpy documentation depends
  on matplotlib, which depends on numpy), we split out the documentation into
  a separate package:
  (python-numpy-bootstrap, python2-numpy-bootstrap): Remove variables.
  (python-numpy-documentation, python2-numpy-documentation): New variables.
---
 gnu/packages/python.scm | 148 +++++++++++++++++++++++++++---------------------
 1 file changed, 82 insertions(+), 66 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index c449ccb6e..d296ee1d9 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -3402,24 +3402,26 @@ between language specification and implementation aspects.")
 
 ;; This version of numpy is missing the documentation and is only used to
 ;; build matplotlib which is required to build numpy's documentation.
-(define python-numpy-bootstrap
+(define-public python-numpy
   (package
-    (name "python-numpy-bootstrap")
-    (version "1.10.4")
+    (name "python-numpy")
+    (version "1.12.0")
     (source
      (origin
        (method url-fetch)
-       (uri (string-append "mirror://sourceforge/numpy/NumPy/" version
-                           "/numpy-" version ".tar.gz"))
+       (uri (string-append
+             "https://github.com/numpy/numpy/archive/v" version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32
-         "1bjjhvncraka5s6i4lg644jrxij6bvycxy7an20gcz3a0m11iygp"))))
+         "025d4j4aakcp8w5i5diqh812cbbjgac7jszx1j56ivrbi1i8vv7d"))))
     (build-system python-build-system)
     (inputs
      `(("openblas" ,openblas)
        ("lapack" ,lapack)))
     (native-inputs
-     `(("python-nose" ,python-nose)
+     `(("python-cython" ,python-cython)
+       ("python-nose" ,python-nose)
        ("gfortran" ,gfortran)))
     (arguments
      `(#:phases
@@ -3468,8 +3470,8 @@ and Fortran code, useful linear algebra, Fourier transform, and random number
 capabilities.")
     (license license:bsd-3)))
 
-(define python2-numpy-bootstrap
-  (package-with-python2 python-numpy-bootstrap))
+(define-public python2-numpy
+  (package-with-python2 python-numpy))
 
 (define-public python-munch
   (package
@@ -3526,69 +3528,83 @@ Models, is a program for performing both single-SNP and SNP-set genome-wide
 association studies (GWAS) on extremely large data sets.")
     (license license:asl2.0)))
 
-(define-public python-numpy
-  (package (inherit python-numpy-bootstrap)
-    (name "python-numpy")
-    (outputs '("out" "doc"))
-    (inputs
-     `(("which" ,which)
-       ,@(package-inputs python-numpy-bootstrap)))
-    (propagated-inputs
-     `(("python-matplotlib" ,python-matplotlib)
-       ("python-pyparsing" ,python-pyparsing)
-       ,@(package-propagated-inputs python-numpy-bootstrap)))
+(define-public python-numpy-documentation
+  (package
+    (name "python-numpy-documentation")
+    (version (package-version python-numpy))
+    (source (package-source python-numpy))
+    (build-system python-build-system)
     (native-inputs
-     `(("pkg-config" ,pkg-config)
+     `(("python-matplotlib" ,python-matplotlib)
+       ("python-numpy" ,python-numpy)
+       ("pkg-config" ,pkg-config)
        ("python-sphinx" ,python-sphinx)
        ("python-numpydoc" ,python-numpydoc)
        ("texlive" ,texlive)
        ("texinfo" ,texinfo)
        ("perl" ,perl)
-       ,@(package-native-inputs python-numpy-bootstrap)))
-    (arguments
-     `(,@(substitute-keyword-arguments
-             (package-arguments python-numpy-bootstrap)
-           ((#:phases phases)
-            `(alist-cons-after
-              'install 'install-doc
-              (lambda* (#:key inputs outputs #:allow-other-keys)
-                ;; Make installed package available for building the
-                ;; documentation
-                (add-installed-pythonpath inputs outputs)
-                (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
-                       (doc (string-append
-                             data "/doc/" ,name "-"
-                             ,(package-version python-numpy-bootstrap)))
-                       (info (string-append data "/info"))
-                       (html (string-append doc "/html"))
-                       (pyver ,(string-append "PYVER=")))
-                  (with-directory-excursion "doc"
-                    (mkdir-p html)
-                    (system* "make" "html" pyver)
-                    (system* "make" "latex" "PAPER=a4" pyver)
-                    (system* "make" "-C" "build/latex"
-                             "all-pdf" "PAPER=a4" pyver)
-                    ;; FIXME: Generation of the info file fails.
-                    ;; (system* "make" "info" pyver)
-                    ;; (mkdir-p info)
-                    ;; (copy-file "build/texinfo/numpy.info"
-                    ;;            (string-append info "/numpy.info"))
-                    (for-each (lambda (file)
-                                (copy-file (string-append "build/latex" file)
-                                           (string-append doc file)))
-                              '("/numpy-ref.pdf" "/numpy-user.pdf"))
-                    (with-directory-excursion "build/html"
-                      (for-each (lambda (file)
-                                  (let* ((dir (dirname file))
-                                         (tgt-dir (string-append html "/" dir)))
-                                    (unless (equal? "." dir)
-                                      (mkdir-p tgt-dir))
-                                    (install-file file html)))
-                                (find-files "." ".*"))))))
-              ,phases)))))))
+       ("scipy-sphinx-theme"
+        ,(origin ; The build script expects scipy-sphinx-theme as a git submodule
+           (method git-fetch)
+           (uri (git-reference
+                 (url "https://github.com/scipy/scipy-sphinx-theme.git")
+                 (commit "c466764e22")))
+           (sha256
+            (base32
+                "0q2y87clwlsgc7wvlsn9pzyssybcq10plwhq2w1ydykfsyyqbmkl"))))
+       ,@(package-native-inputs python-numpy)))
+    (arguments
+     `(#:tests? #f ; we're only generating the documentation
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'build)
+         (replace 'install
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((data (string-append (assoc-ref outputs "out") "/share"))
+                    (doc (string-append
+                          data "/doc/" ,name "-"
+                          ,(package-version python-numpy)))
+                    (info-reader (string-append data "/info"))
+                    (html (string-append doc "/html"))
+                    (scipy-sphinx-theme "scipy-sphinx-theme")
+                    (sphinx-theme-checkout (assoc-ref inputs scipy-sphinx-theme))
+                    (pyver ,(string-append "PYVER=")))
+               (with-directory-excursion "doc"
+                 (copy-recursively sphinx-theme-checkout scipy-sphinx-theme)
+                 (mkdir-p html)
+                 (system* "make" "html" pyver)
+                 (system* "make" "latex" "PAPER=a4" pyver)
+                 (system* "make" "-C" "build/latex"
+                          "all-pdf" "PAPER=a4" pyver)
+                 ;; FIXME: Generation of the info file fails.
+                 ;; (system* "make" "info" pyver)
+                 ;; (mkdir-p info)
+                 ;; (copy-file "build/texinfo/numpy.info"
+                 ;;            (string-append info "/numpy.info"))
+                 (for-each (lambda (file)
+                             (copy-file (string-append "build/latex" file)
+                                        (string-append doc file)))
+                           '("/numpy-ref.pdf" "/numpy-user.pdf"))
+                 (with-directory-excursion "build/html"
+                   (for-each (lambda (file)
+                               (let* ((dir (dirname file))
+                                      (tgt-dir (string-append html "/" dir)))
+                                 (unless (equal? "." dir)
+                                   (mkdir-p tgt-dir))
+                                 (install-file file html)))
+                             (find-files "." ".*")))))
+             #t)))))
+    (home-page (package-home-page python-numpy))
+    (synopsis "Documentation for the python-numpy package")
+    (description (package-description python-numpy))
+    (license (package-license python-numpy))))
 
-(define-public python2-numpy
-  (package-with-python2 python-numpy))
+(define-public python2-numpy-documentation
+  (let ((numpy-documentation (package-with-python2 python-numpy-documentation)))
+    (package
+      (inherit numpy-documentation)
+      (native-inputs `(("python2-functools32" ,python2-functools32)
+                       ,@(package-native-inputs numpy-documentation))))))
 
 (define-public python-pygit2
   (package
@@ -3810,7 +3826,7 @@ between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.")
        ("gobject-introspection" ,gobject-introspection)
        ("python-tkinter" ,python "tk")
        ("python-dateutil" ,python-dateutil)
-       ("python-numpy" ,python-numpy-bootstrap)
+       ("python-numpy" ,python-numpy)
        ("python-pillow" ,python-pillow)
        ("python-pytz" ,python-pytz)
        ("python-six" ,python-six)
-- 
2.11.1

From 99bd1a9ae4c7fd4ad52437c25ae40726235eb6b0 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 22:18:45 +0100
Subject: [PATCH 4/8] 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                           | 118 ++++++++++++----------
 3 files changed, 67 insertions(+), 86 deletions(-)
 delete mode 100644 gnu/packages/patches/matplotlib-setupext-tk.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 9d2cd0ad2..29b980829 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -746,7 +746,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 d296ee1d9..0b223f1fc 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -89,6 +89,7 @@
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages protobuf)
+  #:use-module (gnu packages qt)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages sdl)
   #:use-module (gnu packages shells)
@@ -3807,21 +3808,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")
@@ -3853,17 +3853,13 @@ 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-1.2.3)
-       ("python-numpydoc" ,python-numpydoc)
        ("python-nose" ,python-nose)
-       ("python-mock" ,python-mock)
-       ("texlive" ,texlive)
-       ("texinfo" ,texinfo)))
+       ("python-mock" ,python-mock)))
     (arguments
      `(#:phases
        (modify-phases %standard-phases
@@ -3882,26 +3878,66 @@ between colorspaces like sRGB, XYZ, CIEL*a*b*, CIECAM02, CAM02-UCS, etc.")
 basedirlist = ~a,~a~%
  [rc_options]~%
 backend = TkAgg~%"
-                           (assoc-ref inputs "tcl")
-                           (assoc-ref inputs "tk"))))
-               #t)))
-         (add-after 'install 'install-doc
+                        (assoc-ref inputs "tcl")
+                        (assoc-ref inputs "tk")))))
+             #t)))))
+    (home-page "http://matplotlib.org")
+    (synopsis "2D plotting library for Python")
+    (description
+     "Matplotlib is a Python 2D plotting library which produces publication
+quality figures in a variety of hardcopy formats and interactive environments
+across platforms.  Matplotlib can be used in Python scripts, the python and
+ipython shell, web application servers, and six graphical user interface
+toolkits.")
+    (license license:psfl)
+    (properties `((python2-variant . ,(delay python2-matplotlib))))))
+
+(define-public python2-matplotlib
+  (let ((matplotlib (package-with-python2
+                     (strip-python2-variant python-matplotlib))))
+    (package (inherit matplotlib)
+      ;; Make sure to use special packages for Python 2 instead
+      ;; of those automatically rewritten by package-with-python2.
+      (propagated-inputs
+       `(("python2-pycairo" ,python2-pycairo)
+         ("python2-pygobject-2" ,python2-pygobject-2)
+         ("python2-tkinter" ,python-2 "tk")
+         ,@(fold alist-delete (package-propagated-inputs matplotlib)
+                 '("python-pycairo" "python-pygobject" "python-tkinter")))))))
+
+(define-public python-matplotlib-documentation
+  (package
+    (name "python-matplotlib-documentation")
+    (version (package-version python-matplotlib))
+    (source (package-source python-matplotlib))
+    (build-system python-build-system)
+    (native-inputs
+     `(("python-matplotlib" ,python-matplotlib)
+       ("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)
-             (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
+             (let* ((data (string-append (assoc-ref outputs "out") "/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'"))
-                 (substitute* "users/intro.rst"
-                   ;; Fix reST markup error (see <https://github.com/sphinx-doc/sphinx/issues/3044>)
-                   (("[[][*][]]") "[#]"))
                  (mkdir-p html)
                  (mkdir-p info)
                  ;; The doc recommends to run the 'html' target twice.
@@ -3923,35 +3959,15 @@ backend = TkAgg~%"
                  (copy-file "build/texinfo/matplotlib.info"
                             (string-append info "/matplotlib.info"))
                  (copy-file "build/latex/Matplotlib.pdf"
-                            (string-append doc "/Matplotlib.pdf")))
-                 #t))))))
-    (home-page "http://matplotlib.org")
-    (synopsis "2D plotting library for Python")
-    (description
-     "Matplotlib is a Python 2D plotting library which produces publication
-quality figures in a variety of hardcopy formats and interactive environments
-across platforms.  Matplotlib can be used in Python scripts, the python and
-ipython shell, web application servers, and six graphical user interface
-toolkits.")
-    (license license:psfl)
-    (properties `((python2-variant . ,(delay python2-matplotlib))))))
+                            (string-append doc "/Matplotlib.pdf"))))
+             #t)))))
+    (home-page (package-home-page python-matplotlib))
+    (synopsis "Documentation for the python-matplotlib package")
+    (description (package-description python-matplotlib))
+    (license (package-license python-matplotlib))))
 
-(define-public python2-matplotlib
-  (let ((matplotlib (package-with-python2
-                     (strip-python2-variant python-matplotlib))))
-    (package (inherit matplotlib)
-      ;; Make sure to use special packages for Python 2 instead
-      ;; of those automatically rewritten by package-with-python2.
-      (native-inputs
-       `(("python2-sphinx" ,python2-sphinx-1.2.3)
-         ,@(fold alist-delete (package-native-inputs matplotlib)
-                 '("python-sphinx"))))
-      (propagated-inputs
-       `(("python2-pycairo" ,python2-pycairo)
-         ("python2-pygobject-2" ,python2-pygobject-2)
-         ("python2-tkinter" ,python-2 "tk")
-         ,@(fold alist-delete (package-propagated-inputs matplotlib)
-                 '("python-pycairo" "python-pygobject" "python-tkinter")))))))
+(define-public python2-matplotlib-documentation
+  (package-with-python2 python-matplotlib-documentation))
 
 (define-public python2-pysnptools
   (package
-- 
2.11.1

From 66c61b4683f8bb2ef15f3b659af3ddd1ac8c7927 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Fri, 24 Feb 2017 17:07:27 +0100
Subject: [PATCH 5/8] gnu: python-testpath: Fix library location for python2
 version.

* gnu/packages/python.scm (python-testpath)[arguments]: Install module in the proper
"lib/pythonx.y" location for all Python versions.
---
 gnu/packages/python.scm | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 0b223f1fc..daa001fe0 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -5153,20 +5153,26 @@ installing @code{kernelspec}s for use with Jupyter frontends.")
     (build-system python-build-system)
     (arguments
      `(#:tests? #f ; this package does not even have a setup.py
+       #:modules ((guix build python-build-system)
+                  (guix build utils)
+                  (srfi srfi-1))
+       #:imported-modules (,@%python-build-system-modules
+                           (srfi srfi-1))
        #:phases
        (modify-phases %standard-phases
          (delete 'install)
          (replace 'build
-                  (lambda* (#:key inputs outputs #:allow-other-keys)
-                    (let ((dir (string-append
-                                (assoc-ref outputs "out")
-                                "/lib/python"
-                                (string-take (string-take-right
-                                              (assoc-ref inputs "python") 5) 3)
-                                "/site-packages/testpath")))
-                      (mkdir-p dir)
-                      (copy-recursively "testpath" dir))
-                    #t)))))
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((version (last
+                              (string-split (assoc-ref inputs "python") #\-)))
+                    (x.y (string-join (take (string-split version #\.) 2)
+                                        "."))
+                    (dir (string-append
+                          (assoc-ref outputs "out")
+                          "/lib/python" x.y "/site-packages/testpath")))
+               (mkdir-p dir)
+               (copy-recursively "testpath" dir))
+             #t)))))
     (home-page "https://github.com/takluyver/testpath")
     (synopsis "Test utilities for code working with files and commands")
     (description
-- 
2.11.1

From c7ff74dedc83b4614ab5aaeddc19e7acd6305693 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 12:41:09 +0100
Subject: [PATCH 6/8] gnu: python-ipython: Update to 5.2.2.

* gnu/packages/python.scm (python-ipython): Update to 5.2.2.
[propagated-inputs]: Add pyhon-prompt-toolkit and python-nbformat.
(python2-ipython) [arguments]: Enable tests.
[propagated-inputs]: Add python2-backports-shutil-get-terminal-size.
---
 gnu/packages/python.scm | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index daa001fe0..583c53149 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -5187,17 +5187,18 @@ tools for mocking system commands and recording calls to those.")
 (define-public python-ipython
   (package
     (name "python-ipython")
-    (version "4.0.3")
+    (version "5.2.2")
     (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "ipython" version ".tar.gz"))
        (sha256
-        (base32 "1h2gp1p06sww9rzfkfzqy489bh47gj3910y2b1wdk3dcx1cqz4is"))))
+        (base32 "1qhjwa9cyz1np7rhv3p4ip13lkgbqsad62l24xkwiq1ic2gwiqbf"))))
     (build-system python-build-system)
     (outputs '("out" "doc"))
     (propagated-inputs
      `(("python-pyzmq" ,python-pyzmq)
+       ("python-prompt-toolkit" ,python-prompt-toolkit)
        ("python-terminado" ,python-terminado)
        ("python-matplotlib" ,python-matplotlib)
        ("python-numpy" ,python-numpy)
@@ -5210,6 +5211,7 @@ tools for mocking system commands and recording calls to those.")
        ("python-jsonschema" ,python-jsonschema)
        ("python-traitlets" ,python-traitlets)
        ("python-ipykernel" ,python-ipykernel)
+       ("python-nbformat" ,python-nbformat)
        ("python-pygments" ,python-pygments)))
     (inputs
      `(("readline" ,readline)
@@ -5220,6 +5222,7 @@ tools for mocking system commands and recording calls to those.")
        ("python-testpath" ,python-testpath)
        ("python-nose" ,python-nose)
        ("python-sphinx" ,python-sphinx)
+       ("python-shpinx-rtd-theme" ,python-sphinx-rtd-theme)
        ("texlive" ,texlive)
        ("texinfo" ,texinfo)))
     (arguments
@@ -5233,15 +5236,16 @@ tools for mocking system commands and recording calls to those.")
                    (html (string-append doc "/html"))
                    (man1 (string-append data "/man/man1"))
                    (info (string-append data "/info"))
-                   (examples (string-append doc "/examples")))
+                   (examples (string-append doc "/examples"))
+                   (python-arg (string-append "PYTHON=" (which "python"))))
               (setenv "LANG" "en_US.utf8")
               ;; Make installed package available for running the tests
               (add-installed-pythonpath inputs outputs)
               (with-directory-excursion "docs"
                 ;; FIXME: pdf fails to build
                 ;;(system* "make" "pdf" "PAPER=a4")
-                (system* "make" "html")
-                (system* "make" "info"))
+                (system* "make" python-arg "html")
+                (system* "make" python-arg "info"))
               (copy-recursively "docs/man" man1)
               (copy-recursively "examples" examples)
               (copy-recursively "docs/build/html" html)
@@ -5291,10 +5295,12 @@ computing.")
   (let ((ipython (package-with-python2 (strip-python2-variant python-ipython))))
     (package
       (inherit ipython)
-      ;; FIXME: some tests are failing
-      (arguments
-       `(#:tests? #f ,@(package-arguments ipython)))
       ;; FIXME: add pyreadline once available.
+      (propagated-inputs
+       `(("python2-backports-shutil-get-terminal-size"
+          ,python2-backports-shutil-get-terminal-size)
+         ("python2-pathlib2" ,python2-pathlib2)
+         ,@(package-propagated-inputs ipython)))
       (native-inputs
        `(("python2-mock" ,python2-mock)
          ,@(package-native-inputs ipython))))))
-- 
2.11.1

From 2fbe5993e969566f07191be3578b351994839e93 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Tue, 21 Feb 2017 11:45:06 +0100
Subject: [PATCH 7/8] gnu: python-scipy: Update to 0.18.1.

* gnu/packages/python.scm (python-scipy): Update to 0.18.1.
[source]: Use github instead of sourceforge.
[native-inputs]: Add python-cython.
---
 gnu/packages/python.scm | 104 ++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 56 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 583c53149..404ac38e3 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -4049,16 +4049,16 @@ functions.")
 (define-public python-scipy
   (package
     (name "python-scipy")
-    (version "0.16.0")
+    (version "0.18.1")
     (source
      (origin
        (method url-fetch)
-; http://downloads.sourceforge.net/project/scipy/scipy/0.16.1/scipy-0.16.1.tar.gz
-       (uri (string-append "mirror://sourceforge/scipy/scipy/" version
-                           "/scipy-" version ".tar.xz"))
+       (uri (string-append "https://github.com/scipy/scipy/archive/v"
+                           version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32
-         "0wa0a4skpda3gx7lb12yn19nhbairlyxrvda2lz2bcawk3x5qzz2"))))
+         "17slsrfawjp7if6qrlx03zhgp05350ginxx8ddpw9zqx43x905sn"))))
     (build-system python-build-system)
     (propagated-inputs
      `(("python-numpy" ,python-numpy)
@@ -4068,21 +4068,16 @@ functions.")
      `(("lapack" ,lapack)
        ("openblas" ,openblas)))
     (native-inputs
-     `(("python-nose" ,python-nose)
-       ("python-sphinx" ,python-sphinx-1.2.3)
+     `(("python-cython" ,python-cython)
+       ("python-nose" ,python-nose)
+       ("python-sphinx" ,python-sphinx)
        ("python-numpydoc" ,python-numpydoc)
        ("gfortran" ,gfortran)
-       ("texlive" ,texlive)
        ("perl" ,perl)))
     (outputs '("out" "doc"))
     (arguments
      `(#:phases
        (modify-phases %standard-phases
-         (add-after 'unpack 'fix-tests
-           (lambda _
-             (substitute* "scipy/integrate/tests/test_quadpack.py"
-               (("libm.so") "libm.so.6"))
-             #t))
          (add-before 'build 'configure-openblas
            (lambda* (#:key inputs #:allow-other-keys)
              (call-with-output-file "site.cfg"
@@ -4102,40 +4097,44 @@ atlas_libs = openblas
                          (assoc-ref inputs "openblas")
                          (assoc-ref inputs "openblas"))))
              #t))
-           (delete 'check)
-           (add-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))
-                      (html (string-append doc "/html"))
-                      (pyver ,(string-append "PYVER=")))
-                 ;; Make installed package available for building the
-                 ;; documentation
-                 (add-installed-pythonpath inputs outputs)
-                 (with-directory-excursion "doc"
-                   ;; Fix generation of images for mathematical expressions.
-                   (substitute* (find-files "source" "conf\\.py")
-                     (("pngmath_use_preview = True")
-                      "pngmath_use_preview = False"))
-                   (mkdir-p html)
-                   (system* "make" "html" pyver)
-                   (system* "make" "latex" "PAPER=a4" pyver)
-                   (system* "make" "-C" "build/latex" "all-pdf" "PAPER=a4" pyver)
-                   (copy-file "build/latex/scipy-ref.pdf"
-                              (string-append doc "/scipy-ref.pdf"))
-                   (with-directory-excursion "build/html"
-                     (for-each (lambda (file)
-                                 (let* ((dir (dirname file))
-                                        (tgt-dir (string-append html "/" dir)))
-                                   (install-file file html)))
-                               (find-files "." ".*"))))
-                 #t)))
-           (add-after 'install-doc 'check
-             (lambda _
-               ;; Tests can only be run after the library has been installed and not
-               ;; within the source directory.
-               (with-directory-excursion "/tmp"
-                 (zero? (system* "python" "-c" "import scipy; scipy.test()"))))))))
+         (add-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))
+                    (html (string-append doc "/html"))
+                    (pyver ,(string-append "PYVER=")))
+               ;; Make installed package available for building the
+               ;; documentation
+               (add-installed-pythonpath inputs outputs)
+               (with-directory-excursion "doc"
+                 ;; Fix generation of images for mathematical expressions.
+                 (substitute* (find-files "source" "conf\\.py")
+                   (("pngmath_use_preview = True")
+                    "pngmath_use_preview = False"))
+                 (mkdir-p html)
+                 (system* "make" "html" pyver)
+                 (with-directory-excursion "build/html"
+                   (for-each (lambda (file)
+                               (let* ((dir (dirname file))
+                                      (tgt-dir (string-append html "/" dir)))
+                                 (install-file file html)))
+                             (find-files "." ".*")))))
+             #t))
+         (add-after 'unpack 'fix-tests
+           (lambda _
+             (substitute* "scipy/integrate/tests/test_quadpack.py"
+               (("libm.so") "libm.so.6"))
+             #t))
+           ;; Tests can only be run after the library has been installed and not
+           ;; within the source directory.
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (add-installed-pythonpath inputs outputs)
+             (with-directory-excursion "/tmp"
+               (zero? (system* "python" "-c"
+                               "import scipy; scipy.test('full')")))
+             #t)))))
     (home-page "http://www.scipy.org/")
     (synopsis "The Scipy library provides efficient numerical routines")
     (description "The SciPy library is one of the core packages that make up
@@ -4145,15 +4144,8 @@ routines such as routines for numerical integration and optimization.")
     (license license:bsd-3)))
 
 (define-public python2-scipy
-  (let ((scipy (package-with-python2
-                (strip-python2-variant python-scipy))))
-    (package (inherit scipy)
-             ;; Make sure to use special packages for Python 2 instead
-             ;; of those automatically rewritten by package-with-python2.
-             (native-inputs
-              `(("python2-sphinx" ,python2-sphinx-1.2.3)
-                ,@(fold alist-delete (package-native-inputs scipy)
-                        '("python-sphinx")))))))
+  (package-with-python2
+   (strip-python2-variant python-scipy)))
 
 (define-public python-socksipy-branch
   (package
-- 
2.11.1

From 49827031bbee8c06c89824ce5c6a72fab3635b31 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <[email-masked]>
Date: Sat, 25 Feb 2017 23:35:22 +0100
Subject: [PATCH 8/8] gnu: Remove python-sphinx-1.2.3.

* gnu/packages/python.scm (python-sphinx-1.2.3, python2-sphinx-1.2.3): Remove variables.
---
 gnu/packages/python.scm | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 404ac38e3..e3fff483b 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -3029,24 +3029,6 @@ sources.")
       (propagated-inputs `(("python2-pytz" ,python2-pytz)
                        ,@(package-propagated-inputs base))))))
 
-;; This is needed for [email-masked] and [email-masked], at least.
-;; Try removing this when they are updated.
-(define-public python-sphinx-1.2.3
-  (package (inherit python-sphinx)
-           (version "1.2.3")
-           (source (origin
-                     (method url-fetch)
-                     (uri (pypi-uri "Sphinx" version))
-                     (sha256
-                      (base32
-                       "011xizm3jnmf4cvs5i6kgf6c5nn046h79i8j0vd0f27yw9j3p4wl"))))
-           ;; XXX: "'NoneType' object has no attribute 'split'".
-           (arguments '(#:tests? #f))))
-
-(define-public python2-sphinx-1.2.3
-  (package (inherit (package-with-python2
-                     (strip-python2-variant python-sphinx-1.2.3)))))
-
 (define-public python-sphinx-rtd-theme
   (package
     (name "python-sphinx-rtd-theme")
-- 
2.11.1