gnu: r-broom: Update to 0.5.6.
[jackhill/guix/guix.git] / gnu / packages / python.scm
index ce2e344..048941e 100644 (file)
 ;;; 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 Nils Gillmann <ng0@n0.is>
+;;; Copyright © 2016, 2017 ng0 <ng0@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 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>
@@ -44,7 +44,7 @@
 ;;; 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>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -76,6 +77,7 @@
 (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 compression)
   #:use-module (gnu packages dbm)
@@ -85,6 +87,7 @@
   #: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)
@@ -94,7 +97,7 @@
 (define-public python-2.7
   (package
     (name "python2")
-    (version "2.7.15")
+    (version "2.7.16")
     (source
      (origin
       (method url-fetch)
                           version "/Python-" version ".tar.xz"))
       (sha256
        (base32
-        "0x2mvz9dp11wj7p5ccvmk9s0hzjk2fa1m462p395l4r6bfnb3n92"))
+        "1mqfcqp5y8r0bfyr7ppl74n0lig45p9mc4b8adlcpvj74rhfy8pj"))
       (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"
-                               "python2-CVE-2018-14647.patch"
-                               "python2-CVE-2018-1000802.patch"))
+                               "python-2.7-adjust-tests.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"
+
              (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 (format #f "TESTOPTS=-j~d" (parallel-job-count)))
+       (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))
                 #t))))))
     (inputs
      `(("bzip2" ,bzip2)
+       ("expat" ,expat)
        ("gdbm" ,gdbm)
        ("libffi" ,libffi)                         ; for ctypes
        ("sqlite" ,sqlite)                         ; for sqlite extension
@@ -284,6 +308,7 @@ 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.
@@ -301,37 +326,51 @@ data types.")
 (define-public python-3.7
   (package (inherit python-2)
     (name "python")
-    (version "3.7.2")
+    (version "3.7.4")
     (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-deterministic-build-info.patch"
                         "python-3-search-paths.patch"))
-              (patch-flags '("-p0"))
               (sha256
                (base32
-                "1fzi9d2gibh0wzwidyckzbywsxcsbckgsl05ryxlifxia77fhgyq"))
+                "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv"))
+              (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.dist"
+                    ;; 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"
+                ;; XXX: test_ctypes fails on some platforms due to a problem in
+                ;; libffi 3.2.1: <https://bugs.python.org/issue23249>.
+                ,@(if (string-prefix? "aarch64" (%current-system))
+                      '(" test_ctypes")
+                      '()))))
        ((#:phases phases)
        `(modify-phases ,phases
+          (add-before 'check 'set-TZDIR
+            (lambda* (#:key inputs #:allow-other-keys)
+              ;; test_email requires the Olson time zone database.
+              (setenv "TZDIR"
+                      (string-append (assoc-ref 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
@@ -360,6 +399,9 @@ data types.")
                               (find-files out "\\.py$")))
                   (list '() '("-O") '("-OO")))
                  #t)))))))
+    (native-inputs
+     `(("tzdata" ,tzdata-for-tests)
+       ,@(package-native-inputs python-2)))
     (native-search-paths
      (list (search-path-specification
             (variable "PYTHONPATH")
@@ -367,6 +409,31 @@ data types.")
                                         (version-major+minor version)
                                         "/site-packages"))))))))
 
+(define-public python-3.8
+  (package
+    (inherit python-3.7)
+    (name "python-next")
+    (version "3.8.0")
+    (source
+     (origin
+       (inherit (package-source python-3.7))
+       (uri (string-append "https://www.python.org/ftp/python/"
+                           version "/Python-" version ".tar.xz"))
+       (sha256 (base32 "110d0did9rxn7rg85kf2fwli5hqq44xv2d8bi7d92m7v2d728mmk"))
+       (patches (search-patches
+                 "python-3.8-search-paths.patch"
+                 "python-3-fix-tests.patch"
+                 "python-3.8-fix-tests.patch"
+                 "python-3-deterministic-build-info.patch"))
+       (snippet
+        '(begin
+           ;; 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))))))
+
 ;; Current 3.x version.
 (define-public python-3 python-3.7)
 
@@ -383,8 +450,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
@@ -394,8 +463,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)))))
 
@@ -460,3 +531,65 @@ instead of @command{python3}.")))
 
 (define-public python-wrapper (wrap-python3 python))
 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
+
+(define-public micropython
+  (package
+    (name "micropython")
+    (version "1.11")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (string-append "https://github.com/micropython/micropython/"
+                            "releases/download/v" version
+                            "/micropython-" version ".tar.gz"))
+        (sha256
+         (base32
+          "0px3xhw16rl0l7qifq7jw1gq92wzlnhd17dmszv9m2c3wbzs9p9f"))
+      (modules '((guix build utils)))
+      (snippet
+       '(begin
+          (delete-file-recursively "ports/cc3200/FreeRTOS")
+          (with-directory-excursion "lib"
+            ;; TODO: Unbundle axtls and berkley-db-1.xx
+            (for-each delete-file-recursively
+                      '("libffi" "lwip" "stm32lib" "nrfx")))
+          #t))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-before 'build 'prepare-build
+           (lambda _
+             (chdir "ports/unix")
+             ;; see: https://github.com/micropython/micropython/pull/4246
+             (substitute* "Makefile"
+               (("-Os") "-Os -ffp-contract=off"))
+             #t))
+         (replace 'install-license-files
+           ;; We don't build in the root directory so the file isn't found.
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out  (assoc-ref outputs "out"))
+                    (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
+               (install-file "../../LICENSE" dest))
+             #t))
+         (delete 'configure)) ; no configure
+       #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
+                          "V=1")
+       #:test-target "test"))
+    (native-inputs
+     `(("pkg-config" ,pkg-config)
+       ("python" ,python-wrapper)))
+    (inputs
+     `(("libffi" ,libffi)))
+    (home-page "https://micropython.org/")
+    (synopsis "Python implementation for microcontrollers and constrained systems")
+    (description "MicroPython is a lean and efficient implementation of the
+Python 3 programming language that includes a small subset of the Python
+standard library and is optimised to run on microcontrollers and in constrained
+environments.  MicroPython is packed full of advanced features such as an
+interactive prompt, arbitrary precision integers, closures, list comprehension,
+generators, exception handling and more.  Still it is compact enough to fit and
+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)))