gnu: r-fields: Update to 11.4.
[jackhill/guix/guix.git] / gnu / packages / python.scm
index 57ced49..993ca0b 100644 (file)
@@ -3,7 +3,7 @@
 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2013, 2014, 2015, 2016 Andreas Enge <andreas@enge.fr>
 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
-;;; Copyright © 2014, 2017 Eric Bavier <bavier@member.fsf.org>
+;;; Copyright © 2014, 2017, 2019 Eric Bavier <bavier@member.fsf.org>
 ;;; Copyright © 2014, 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2015 Omar Radwan <toxemicsquire4@gmail.com>
 ;;; Copyright © 2015 Pierre-Antoine Rault <par@rigelk.eu>
@@ -14,7 +14,7 @@
 ;;; Copyright © 2015, 2016, 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2015, 2017 Ben Woodcroft <donttrustben@gmail.com>
 ;;; Copyright © 2015, 2016 Erik Edrosa <erik.edrosa@gmail.com>
-;;; Copyright © 2015, 2016, 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2015, 2017 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2015, 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
 ;;; Copyright © 2016 Daniel Pimentel <d4n1@d4n1.org>
 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
 ;;; Copyright © 2016, 2017 Troy Sankey <sankeytms@gmail.com>
-;;; Copyright © 2016, 2017 ng0 <ng0@n0.is>
+;;; Copyright © 2016, 2017 Nikita <nikita@n0.is>
 ;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
 ;;; Copyright © 2016 David Craven <david@craven.ch>
-;;; Copyright © 2016, 2017, 2018 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2016, 2017, 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2016, 2017 Stefan Reichör <stefan@xsteve.at>
 ;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
 ;;; Copyright © 2016, 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2017 Frederick M. Muriithi <fredmanglis@gmail.com>
 ;;; Copyright © 2017, 2018 Adriano Peluso <catonano@gmail.com>
 ;;; Copyright © 2017 Ben Sturmfels <ben@sturm.com.au>
-;;; Copyright © 2017, 2018 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2017, 2018, 2019 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2017 José Miguel Sánchez García <jmi2k@openmailbox.org>
 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net>
 ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
 ;;; Copyright © 2017 Muriithi Frederick Muriuki <fredmanglis@gmail.com>
-;;; Copyright © 2017 Brendan Tildesley <brendan.tildesley@openmailbox.org>
+;;; Copyright © 2017 Brendan Tildesley <mail@brendan.scot>
 ;;; Copyright © 2018 Ethan R. Jones <ethanrjones97@gmail.com
 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
 ;;; Copyright © 2018 Vijayalakshmi Vedantham <vijimay12@gmail.com>
 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
 ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
 ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
+;;; Copyright © 2019 Tanguy Le Carrour <tanguy@bioneland.org>
+;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
 (define-module (gnu packages python)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (gnu packages)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
+  #:use-module (gnu packages certs)
+  #:use-module (gnu packages check)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages dbm)
+  #:use-module (gnu packages hurd)
   #:use-module (gnu packages libffi)
+  #:use-module (gnu packages ncurses)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages readline)
+  #:use-module (gnu packages shells)
   #:use-module (gnu packages sqlite)
   #:use-module (gnu packages tcl)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages xml)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix utils)
   #:use-module (guix build-system gnu)
-  #:use-module (guix build-system trivial))
+  #:use-module (guix build-system trivial)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26))
 
 (define-public python-2.7
   (package
     (name "python2")
-    (version "2.7.15")
-    (replacement python-2/fixed)
+    (version "2.7.17")
     (source
      (origin
       (method url-fetch)
                           version "/Python-" version ".tar.xz"))
       (sha256
        (base32
-        "0x2mvz9dp11wj7p5ccvmk9s0hzjk2fa1m462p395l4r6bfnb3n92"))
+        "0hds28cg226m8j8sr394nm9yc4gxhvlv109w0avsf2mxrlrz0hsd"))
       (patches (search-patches "python-2.7-search-paths.patch"
                                "python-2-deterministic-build-info.patch"
                                "python-2.7-site-prefixes.patch"
                                "python-2.7-source-date-epoch.patch"
-                               "python-2.7-adjust-tests.patch"))
+                               "python-2.7-adjust-tests.patch"
+                               "python-cross-compile.patch"))
       (modules '((guix build utils)))
-      ;; suboptimal to delete failing tests here, but if we delete them in the
-      ;; arguments then we need to make sure to strip out that phase when it
-      ;; gets inherited by python and python-minimal.
       (snippet
        '(begin
+          ;; Ensure the bundled copies of these libraries are not used.
+          (for-each delete-file-recursively
+                    '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
+
+          (substitute* "Modules/Setup.dist"
+            ;; Link Expat instead of embedding the bundled one.
+            (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
+
+          ;; Suboptimal to delete failing tests here, but if we delete them in
+          ;; the arguments then we need to make sure to strip out that phase
+          ;; when it gets inherited by python and python-minimal.
           (for-each delete-file
                     '("Lib/test/test_compileall.py"
                       "Lib/test/test_ctypes.py" ; fails on mips64el
      `(#:test-target "test"
        #:configure-flags
        (list "--enable-shared"                    ;allow embedding
+             "--with-system-expat"                ;for XML support
              "--with-system-ffi"                  ;build ctypes
              "--with-ensurepip=install"           ;install pip and setuptools
              "--enable-unicode=ucs4"
+
+             ;; Prevent the installed _sysconfigdata.py from retaining a reference
+             ;; to coreutils.
+             "INSTALL=install -c"
+             "MKDIR_P=mkdir -p"
+
+             ;; Disable runtime check failing if cross-compiling, see:
+             ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
+             ,@(if (%current-target-system)
+                   '("ac_cv_buggy_getaddrinfo=no"
+                     "ac_cv_file__dev_ptmx=no"
+                     "ac_cv_file__dev_ptc=no")
+                   '())
              (string-append "LDFLAGS=-Wl,-rpath="
                             (assoc-ref %outputs "out") "/lib"))
+       ;; With no -j argument tests use all available cpus, so provide one.
+       #:make-flags
+       (list (string-append
+              (format #f "TESTOPTS=-j~d" (parallel-job-count))
+              ;; Exclude the following tests as they fail
+              ;; non-deterministically with "error: [Errno 104] Connection
+              ;; reset by peer."  Python 3 seems unaffected.  A potential fix,
+              ;; yet to be backported to Python 2, is available at:
+              ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
+              " --exclude test_urllib2_localnet test_httplib"))
 
         #:modules ((ice-9 ftw) (ice-9 match)
                    (guix build utils) (guix build gnu-build-system))
           (add-before
            'configure 'patch-lib-shells
            (lambda _
+             ;; This variable is used in setup.py to enable cross compilation
+             ;; specific switches. As it is not set properly by configure
+             ;; script, set it manually.
+             ,@(if (%current-target-system)
+                   '((setenv "_PYTHON_HOST_PLATFORM" ""))
+                   '())
              ;; Filter for existing files, since some may not exist in all
              ;; versions of python that are built with this recipe.
              (substitute* (filter file-exists?
                                     "Lib/test/test_subprocess.py"))
                (("/bin/sh") (which "sh")))
              #t))
+          ,@(if (hurd-system?)
+                `((add-before 'build 'patch-regen-for-hurd
+                    (lambda* (#:key inputs #:allow-other-keys)
+                      (let ((libc (assoc-ref inputs "libc")))
+                        (substitute* "Lib/plat-generic/regen"
+                          (("/usr/include/") (string-append libc "/include/")))
+                        #t))))
+                '())
           (add-before 'configure 'do-not-record-configure-flags
             (lambda* (#:key configure-flags #:allow-other-keys)
               ;; Remove configure flags from the installed '_sysconfigdata.py'
                                  (scandir testdir
                                           (match-lambda
                                             ((or "." "..") #f)
+                                            ("support" #f)
                                             (file
                                              (not
-                                              ;; FIXME: Add the 'support' directory
-                                              ;; in the next rebuild cycle, since it
-                                              ;; moved in 2.7.14.  See also
-                                              ;; python2-futures below.
                                               (string-prefix? "test_support."
                                                               file))))))
                        (call-with-output-file "__init__.py" (const #t))
                        #t)))))))
+          (add-after 'remove-tests 'rebuild-bytecode
+            (lambda* (#:key outputs #:allow-other-keys)
+              (let ((out (assoc-ref outputs "out")))
+                ;; Disable hash randomization to ensure the generated .pycs
+                ;; are reproducible.
+                (setenv "PYTHONHASHSEED" "0")
+                (for-each
+                 (lambda (opt)
+                   (format #t "Compiling with optimization level: ~a\n"
+                           (if (null? opt) "none" (car opt)))
+                   (for-each (lambda (file)
+                               (apply invoke
+                                      `(,,(if (%current-target-system)
+                                              "python2"
+                                              '(string-append out "/bin/python"))
+                                        ,@opt
+                                        "-m" "compileall"
+                                        "-f" ; force rebuild
+                                        ;; Don't build lib2to3, because it contains Python 3 code.
+                                        "-x" "lib2to3/.*"
+                                        ,file)))
+                             (find-files out "\\.py$")))
+                 (list '() '("-O") '("-OO")))
+                #t)))
           (add-after 'install 'move-tk-inter
             (lambda* (#:key outputs #:allow-other-keys)
               ;; When Tkinter support is built move it to a separate output so
                 #t))))))
     (inputs
      `(("bzip2" ,bzip2)
+       ("expat" ,expat)
        ("gdbm" ,gdbm)
        ("libffi" ,libffi)                         ; for ctypes
        ("sqlite" ,sqlite)                         ; for sqlite extension
        ("tcl" ,tcl)
        ("tk" ,tk)))                               ; for tkinter
     (native-inputs
-     `(("pkg-config" ,pkg-config)))
+     `(("pkg-config" ,pkg-config)
+       ;; When cross-compiling, a native version of Python itself is needed.
+       ,@(if (%current-target-system)
+             `(("python2" ,this-package)
+               ("which" ,which))
+             '())))
     (native-search-paths
      (list (search-path-specification
             (variable "PYTHONPATH")
@@ -261,21 +346,12 @@ introspection capabilities; intuitive object orientation; natural
 expression of procedural code; full modularity, supporting hierarchical
 packages; exception-based error handling; and very high level dynamic
 data types.")
+    (properties '((cpe-name . "python")))
     (license license:psfl)))
 
 ;; Current 2.x version.
 (define-public python-2 python-2.7)
 
-(define python-2/fixed
-  (package
-    (inherit python-2)
-    (source (origin
-              (inherit (package-source python-2))
-              (patches (append
-                        (origin-patches (package-source python-2))
-                        (search-patches "python2-CVE-2018-14647.patch"
-                                        "python2-CVE-2018-1000802.patch")))))))
-
 (define-public python2-called-python
   ;; Both 2.x and 3.x used to be called "python".  In commit
   ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the
@@ -285,51 +361,72 @@ data types.")
     (name "python")
     (properties `((superseded . ,python-2)))))
 
-(define-public python-3.7
+(define-public python-3.8
   (package (inherit python-2)
     (name "python")
-    (version "3.7.0")
-    (replacement python-3/fixed)
+    (version "3.8.2")
     (source (origin
               (method url-fetch)
               (uri (string-append "https://www.python.org/ftp/python/"
                                   version "/Python-" version ".tar.xz"))
               (patches (search-patches
-                        "python-fix-tests.patch"
                         "python-3-fix-tests.patch"
+                        "python-3.8-fix-tests.patch"
                         "python-3-deterministic-build-info.patch"
                         "python-3-search-paths.patch"))
-              (patch-flags '("-p0"))
               (sha256
                (base32
-                "0j9mic5c9lbd2b20wka7hily7szz740wy9ilfrczxap63rnrk0h3"))
+                "1ps5v323cp5czfshqjmbsqw7nvrdpcbk06f62jbzaqik4gfffii6"))
+              (modules '((guix build utils)))
               (snippet
                '(begin
-                  (for-each delete-file
-                            '(;; This test may hang and eventually run out of
-                              ;; memory on some systems:
-                              ;; <https://bugs.python.org/issue34587>
-                              "Lib/test/test_socket.py"
-
-                              ;; These tests fail on AArch64.
-                              "Lib/ctypes/test/test_win32.py"
-                              "Lib/test/test_fcntl.py"
-                              "Lib/test/test_posix.py"))
+                  ;; Delete the bundled copy of libexpat.
+                  (delete-file-recursively "Modules/expat")
+                  (substitute* "Modules/Setup"
+                    ;; Link Expat instead of embedding the bundled one.
+                    (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
                   #t))))
     (arguments
      (substitute-keyword-arguments (package-arguments python-2)
+       ((#:make-flags _)
+        `(list (string-append
+                (format #f "TESTOPTS=-j~d" (parallel-job-count))
+                ;; test_mmap fails on low-memory systems.
+                " --exclude test_mmap"
+                ;; test_socket may hang and eventually run out of memory
+                ;; on some systems: <https://bugs.python.org/issue34587>.
+                " test_socket")))
        ((#:phases phases)
        `(modify-phases ,phases
+          ,@(if (hurd-system?)
+                `((delete 'patch-regen-for-hurd)) ;regen was removed after 3.5.9
+                '())
+          ,@(if (hurd-target?)
+                ;; The build system refuses to cross-compile for unknown targets
+                ;; even though it works fine.  Add GNU/Hurd target.
+                ;; TODO: Make it a patch in a future rebuild cycle.
+                '((add-before 'configure 'support-hurd-cross-compile
+                    (lambda _
+                      (substitute* "configure"
+                        (("\\*-\\*-vxworks.*" all)
+                         (string-append "*-*-gnu)\nac_sys_system=GNU\n;;\n" all)))
+                      #t)))
+                '())
+          (add-before 'check 'set-TZDIR
+            (lambda* (#:key inputs native-inputs #:allow-other-keys)
+              ;; test_email requires the Olson time zone database.
+              (setenv "TZDIR"
+                      (string-append (assoc-ref
+                                      (or native-inputs inputs) "tzdata")
+                                     "/share/zoneinfo"))
+              #t))
           ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it
           ;; again afterwards.  See <https://bugs.python.org/issue34022>.
           (add-before 'check 'unset-SOURCE_DATE_EPOCH
             (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
           (add-after 'check 'reset-SOURCE_DATE_EPOCH
             (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
-           ;; FIXME: Without this phase we have close to 400 files that
-           ;; differ across different builds of this package.  With this phase
-           ;; there are 44 files left that differ.
-           (add-after 'remove-tests 'rebuild-bytecode
+           (replace 'rebuild-bytecode
              (lambda* (#:key outputs #:allow-other-keys)
                (let ((out (assoc-ref outputs "out")))
                  ;; Disable hash randomization to ensure the generated .pycs
@@ -341,16 +438,49 @@ data types.")
                             (if (null? opt) "none" (car opt)))
                     (for-each (lambda (file)
                                 (apply invoke
-                                       `(,(string-append out "/bin/python3")
-                                         ,@opt
-                                         "-m" "compileall"
-                                         "-f" ; force rebuild
-                                         ;; Don't build lib2to3, because it's Python 2 code.
-                                         "-x" "lib2to3/.*"
-                                         ,file)))
+                                       `(,,(if (%current-target-system)
+                                               "python3"
+                                               '(string-append out
+                                                               "/bin/python3"))
+                                          ,@opt
+                                          "-m" "compileall"
+                                          "-f" ; force rebuild
+                                          ;; Don't build lib2to3, because it's Python 2 code.
+                                          "-x" "lib2to3/.*"
+                                          ,file)))
                               (find-files out "\\.py$")))
                   (list '() '("-O") '("-OO")))
-                 #t)))))))
+                 #t)))
+           ;; XXX: Apply patch on ARM platforms only to avoid a full rebuild.
+           ;; Remove this phase in the next rebuild cycle.
+           ,@(let ((system (or (%current-target-system)
+                               (%current-system))))
+               (if (any (cute string-prefix? <> system)
+                        '("arm" "aarch64"))
+                   '((add-after 'unpack 'apply-alignment-patch
+                       (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                        (invoke "patch" "-p1" "--force" "--input"
+                                (assoc-ref (or native-inputs inputs)
+                                           "arm-alignment.patch")))))
+                   '()))))))
+    (native-inputs
+     `(("tzdata" ,tzdata-for-tests)
+
+       ;; Disable unaligned accesses in the sha3 module on ARM as
+       ;; it causes a test failure when building 32-bit Python on a
+       ;; 64-bit kernel.  See <https://bugs.python.org/issue36515>.
+       ;; TODO: make this a regular patch in the next rebuild cycle.
+       ,@(let ((system (or (%current-target-system)
+                           (%current-system))))
+           (if (any (cute string-prefix? <> system)
+                    '("arm" "aarch64"))
+               `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
+               '()))
+
+       ,@(if (%current-target-system)
+             `(("python3" ,this-package))
+             '())
+       ,@(package-native-inputs python-2)))
     (native-search-paths
      (list (search-path-specification
             (variable "PYTHONPATH")
@@ -359,15 +489,7 @@ data types.")
                                         "/site-packages"))))))))
 
 ;; Current 3.x version.
-(define-public python-3 python-3.7)
-
-(define python-3/fixed
-  (package
-    (inherit python-3)
-    (source (origin
-              (inherit (package-source python-3))
-              (patches (append (origin-patches (package-source python-3))
-                               (search-patches "python-CVE-2018-14647.patch")))))))
+(define-public python-3 python-3.8)
 
 ;; Current major version.
 (define-public python python-3)
@@ -382,8 +504,10 @@ data types.")
 
     ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which
     ;; is invoked upon 'make install'.  'pip' also expects 'ctypes' and thus
-    ;; libffi.
-    (inputs `(("libffi" ,libffi)
+    ;; libffi.  Expat is needed for XML support which is expected by a lot
+    ;; of libraries out there.
+    (inputs `(("expat" ,expat)
+              ("libffi" ,libffi)
               ("zlib" ,zlib)))))
 
 (define-public python-minimal
@@ -393,8 +517,10 @@ data types.")
 
     ;; Build fails due to missing ctypes without libffi.
     ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
-    ;; zlib is required by 'zipimport', used by pip.
-    (inputs `(("libffi" ,libffi)
+    ;; zlib is required by 'zipimport', used by pip.  Expat is needed
+    ;; for XML support, which is generally expected to be available.
+    (inputs `(("expat" ,expat)
+              ("libffi" ,libffi)
               ("openssl" ,openssl)
               ("zlib" ,zlib)))))
 
@@ -455,7 +581,9 @@ for more information.")))
     (description
      "This package provides wrappers for the commands of Python@tie{}3.x such
 that they can be invoked under their usual name---e.g., @command{python}
-instead of @command{python3}.")))
+instead of @command{python3} or @command{pip} instead of @command{pip3}.
+To function properly, this package should not be installed together with the
+@command{python} package.")))
 
 (define-public python-wrapper (wrap-python3 python))
 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
@@ -463,7 +591,7 @@ instead of @command{python3}.")))
 (define-public micropython
   (package
     (name "micropython")
-    (version "1.10")
+    (version "1.12")
     (source
       (origin
         (method url-fetch)
@@ -472,7 +600,7 @@ instead of @command{python3}.")))
                             "/micropython-" version ".tar.gz"))
         (sha256
          (base32
-          "1g1zjip3rkx6bp16qi1bag72wivnbh56fcsl3nffanrx4j5f4z90"))
+          "1fl1dm2aay23hyqbarnv69qj7z2wljcvkwmvfwfac8yadcv05zcq"))
       (modules '((guix build utils)))
       (snippet
        '(begin
@@ -486,7 +614,11 @@ instead of @command{python3}.")))
     (arguments
      `(#:phases
        (modify-phases %standard-phases
-         (add-before 'build 'preprare-build
+         (add-before 'build 'build-mpy-cross
+           (lambda* (#:key make-flags #:allow-other-keys)
+             (with-directory-excursion "mpy-cross"
+               (apply invoke "make" make-flags))))
+         (add-after 'build-mpy-cross 'prepare-build
            (lambda _
              (chdir "ports/unix")
              ;; see: https://github.com/micropython/micropython/pull/4246
@@ -521,3 +653,169 @@ run within just 256k of code space and 16k of RAM.  MicroPython aims to be as
 compatible with normal Python as possible to allow you to transfer code with
 ease from the desktop to a microcontroller or embedded system.")
     (license license:expat)))
+
+(define-public pypy3
+  (package
+    (name "pypy3")
+    (version "7.3.1")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://bitbucket.org/pypy/pypy/downloads/" ;
+                                  "pypy3.6-v" version "-src.tar.bz2"))
+              (sha256
+               (base32
+                "10zsk8jby8j6visk5mzikpb1cidvz27qq4pfpa26jv53klic6b0c"))
+              (patches (search-patches "pypy3-7.3.1-fix-tests.patch"))))
+    (build-system gnu-build-system)
+    (native-inputs
+     `(("python-2" ,python-2)
+       ("pkg-config" ,pkg-config)
+       ("tar" ,tar)                     ; Required for package.py
+       ("python2-pycparser" ,python2-pycparser)
+       ("python2-hypothesis" ,python2-hypothesis)
+       ("nss-certs" ,nss-certs)         ; For ssl tests
+       ("gzip" ,gzip)))
+    (inputs
+     `(("libffi" ,libffi)
+       ("zlib" ,zlib)
+       ("ncurses" ,ncurses)
+       ("openssl" ,openssl)
+       ("expat" ,expat)
+       ("bzip2" ,bzip2)
+       ("sqlite" ,sqlite)
+       ("gdbm" ,gdbm)
+       ("tcl" ,tcl)
+       ("tk" ,tk)
+       ("glibc" ,glibc)
+       ("bash-minimal" ,bash-minimal)   ; Used as /bin/sh
+       ("xz" ,xz)))                     ; liblzma
+    (arguments
+     `(#:tests? #f     ;FIXME: Disabled for now, there are many tests failing.
+       #:modules ((ice-9 ftw) (ice-9 match)
+                  (guix build utils) (guix build gnu-build-system))
+       #:phases (modify-phases %standard-phases
+                  (delete 'configure)
+                  (add-after 'unpack 'patch-source
+                    (lambda* (#:key inputs outputs #:allow-other-keys)
+                      (substitute* '("rpython/rlib/clibffi.py")
+                        ;; find_library does not work for libc
+                        (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
+                      (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
+                        ;; Make reproducible (XXX: unused?)
+                        (("time\\.localtime\\(\\)") "time.gmtime(0)"))
+                      (substitute* '("pypy/module/sys/version.py")
+                        ;; Make reproducible
+                        (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
+                      (substitute* '("lib_pypy/_tkinter/tklib_build.py")
+                        ;; Link to versioned libtcl and libtk
+                        (("linklibs = \\['tcl', 'tk'\\]")
+                         "linklibs = ['tcl8.6', 'tk8.6']")
+                        (("incdirs = \\[\\]")
+                         (string-append "incdirs = ['"
+                                        (assoc-ref inputs "tcl")
+                                        "/include', '"
+                                        (assoc-ref inputs "tk")
+                                        "/include']")))
+                      (substitute* '("lib_pypy/_curses_build.py")
+                        ;; Find curses
+                        (("/usr/local") (assoc-ref inputs "ncurses")))
+                      (substitute* '("lib_pypy/_sqlite3_build.py")
+                        ;; Always use search paths
+                        (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
+                        ;; Find sqlite3
+                        (("/usr/local") (assoc-ref inputs "sqlite"))
+                        (("libname = 'sqlite3'")
+                         (string-append "libname = '"
+                                        (assoc-ref inputs "sqlite")
+                                        "/lib/libsqlite3.so.0'")))
+                      (substitute* '("lib-python/3/subprocess.py")
+                        ;; Fix shell path
+                        (("/bin/sh")
+                         (string-append (assoc-ref inputs "bash-minimal") "/bin/sh")))
+                      (substitute* '("lib-python/3/distutils/unixccompiler.py")
+                        ;; gcc-toolchain does not provide symlink cc -> gcc
+                        (("\"cc\"") "\"gcc\""))
+                      #t))
+                  (add-after
+                      'unpack 'set-source-file-times-to-1980
+                    ;; copied from python package, required by zip testcase
+                    (lambda _
+                      (let ((circa-1980 (* 10 366 24 60 60)))
+                        (ftw "." (lambda (file stat flag)
+                                   (utime file circa-1980 circa-1980)
+                                   #t))
+                        #t)))
+                  (replace 'build
+                    (lambda* (#:key inputs #:allow-other-keys)
+                      (with-directory-excursion "pypy/goal"
+                        ;; Build with jit optimization.
+                        (invoke "python2"
+                                "../../rpython/bin/rpython"
+                                (string-append "--make-jobs="
+                                               (number->string (parallel-job-count)))
+                                "-Ojit"
+                                "targetpypystandalone"))
+                      ;; Build c modules and package everything, so tests work.
+                      (with-directory-excursion "pypy/tool/release"
+                        (unsetenv "PYTHONPATH") ; Do not use the system’s python libs:
+                                        ; AttributeError: module 'enum' has no
+                                        ; attribute 'IntFlag'
+                        (invoke "python2" "package.py"
+                                "--archive-name" "pypy-dist"
+                                "--builddir" (getcwd)))))
+                  (replace 'check
+                    (lambda* (#:key tests? #:allow-other-keys)
+                      (if tests?
+                          (begin
+                            (setenv "HOME" "/tmp") ; test_with_pip tries to
+                                        ; access ~/.cache/pip
+                            ;; Run library tests only (no interpreter unit
+                            ;; tests). This is what Gentoo does.
+                            (invoke
+                             "python2"
+                             "pypy/test_all.py"
+                             "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
+                             "lib-python"))
+                          (format #t "test suite not run~%"))
+                      #t))
+                  (replace 'install
+                    (lambda* (#:key inputs outputs #:allow-other-keys)
+                      (with-directory-excursion "pypy/tool/release"
+                        ;; Delete test data.
+                        (for-each
+                         (lambda (x)
+                           (delete-file-recursively (string-append
+                                                     "pypy-dist/lib-python/3/" x)))
+                         '("tkinter/test"
+                           "test"
+                           "sqlite3/test"
+                           "lib2to3/tests"
+                           "idlelib/idle_test"
+                           "distutils/tests"
+                           "ctypes/test"
+                           "unittest/test"))
+                        ;; Patch shebang referencing python2
+                        (substitute* '("pypy-dist/lib-python/3/cgi.py"
+                                       "pypy-dist/lib-python/3/encodings/rot_13.py")
+                          (("#!.+/bin/python")
+                           (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3")))
+                        (with-fluids ((%default-port-encoding "ISO-8859-1"))
+                          (substitute* '("pypy-dist/lib_pypy/_md5.py"
+                                         "pypy-dist/lib_pypy/_sha1.py")
+                            (("#!.+/bin/python")
+                             (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3"))))
+                        (copy-recursively "pypy-dist" (assoc-ref outputs "out")))
+                      #t)))))
+    (home-page "https://www.pypy.org/")
+    (synopsis "Python implementation with just-in-time compilation")
+    (description "PyPy is a faster, alternative implementation of the Python
+programming language employing a just-in-time compiler.  It supports most
+Python code natively, including C extensions.")
+    (license (list license:expat        ; pypy itself; _pytest/
+                   license:psfl ; python standard library in lib-python/
+                   license:asl2.0 ; dotviewer/font/ and some of lib-python/
+                   license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
+                   license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
+                   (license:non-copyleft
+                    "http://www.unicode.org/copyright.html")))))
+