1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
3 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2013, 2014, 2015, 2016 Andreas Enge <andreas@enge.fr>
5 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2014, 2017, 2019 Eric Bavier <bavier@member.fsf.org>
7 ;;; Copyright © 2014, 2015 Federico Beffa <beffa@fbengineering.ch>
8 ;;; Copyright © 2015 Omar Radwan <toxemicsquire4@gmail.com>
9 ;;; Copyright © 2015 Pierre-Antoine Rault <par@rigelk.eu>
10 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
11 ;;; Copyright © 2015, 2016 Christopher Allan Webber <cwebber@dustycloud.org>
12 ;;; Copyright © 2015 Eric Dvorsak <eric@dvorsak.fr>
13 ;;; Copyright © 2015, 2016 David Thompson <davet@gnu.org>
14 ;;; Copyright © 2015, 2016, 2017, 2021 Leo Famulari <leo@famulari.name>
15 ;;; Copyright © 2015, 2017 Ben Woodcroft <donttrustben@gmail.com>
16 ;;; Copyright © 2015, 2016 Erik Edrosa <erik.edrosa@gmail.com>
17 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
18 ;;; Copyright © 2015, 2017 Kyle Meyer <kyle@kyleam.com>
19 ;;; Copyright © 2015, 2016 Chris Marusich <cmmarusich@gmail.com>
20 ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
21 ;;; Copyright © 2016 Lukas Gradl <lgradl@openmailbox.org>
22 ;;; Copyright © 2016, 2018 Hartmut Goebel <h.goebel@crazy-compilers.com>
23 ;;; Copyright © 2016 Daniel Pimentel <d4n1@d4n1.org>
24 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
25 ;;; Copyright © 2016, 2017 Troy Sankey <sankeytms@gmail.com>
26 ;;; Copyright © 2016, 2017 Nikita <nikita@n0.is>
27 ;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
28 ;;; Copyright © 2016 David Craven <david@craven.ch>
29 ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
30 ;;; Copyright © 2016, 2017 Stefan Reichör <stefan@xsteve.at>
31 ;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
32 ;;; Copyright © 2016, 2017 Alex Vong <alexvong1995@gmail.com>
33 ;;; Copyright © 2016, 2017, 2018 Arun Isaac <arunisaac@systemreboot.net>
34 ;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
35 ;;; Copyright © 2016–2018, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
36 ;;; Copyright © 2016, 2017 Thomas Danckaert <post@thomasdanckaert.be>
37 ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
38 ;;; Copyright © 2017 Frederick M. Muriithi <fredmanglis@gmail.com>
39 ;;; Copyright © 2017, 2018 Adriano Peluso <catonano@gmail.com>
40 ;;; Copyright © 2017 Ben Sturmfels <ben@sturm.com.au>
41 ;;; Copyright © 2017, 2018, 2019 Mathieu Othacehe <m.othacehe@gmail.com>
42 ;;; Copyright © 2017 José Miguel Sánchez García <jmi2k@openmailbox.org>
43 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
44 ;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net>
45 ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
46 ;;; Copyright © 2017 Muriithi Frederick Muriuki <fredmanglis@gmail.com>
47 ;;; Copyright © 2017 Brendan Tildesley <mail@brendan.scot>
48 ;;; Copyright © 2018 Ethan R. Jones <ethanrjones97@gmail.com
49 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
50 ;;; Copyright © 2018 Vijayalakshmi Vedantham <vijimay12@gmail.com>
51 ;;; Copyright © 2018 Mathieu Lirzin <mthl@gnu.org>
52 ;;; Copyright © 2018 Adam Massmann <massmannak@gmail.com>
53 ;;; Copyright © 2016, 2018 Tomáš Čech <sleep_walker@gnu.org>
54 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
55 ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
56 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
57 ;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
58 ;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
59 ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
60 ;;; Copyright © 2019 Tanguy Le Carrour <tanguy@bioneland.org>
61 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
62 ;;; Copyright © 2021 Greg Hogan <code@greghogan.com>
64 ;;; This file is part of GNU Guix.
66 ;;; GNU Guix is free software; you can redistribute it and/or modify it
67 ;;; under the terms of the GNU General Public License as published by
68 ;;; the Free Software Foundation; either version 3 of the License, or (at
69 ;;; your option) any later version.
71 ;;; GNU Guix is distributed in the hope that it will be useful, but
72 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
73 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 ;;; GNU General Public License for more details.
76 ;;; You should have received a copy of the GNU General Public License
77 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
79 (define-module (gnu packages python)
80 #:use-module ((guix licenses) #:prefix license:)
81 #:use-module (gnu packages)
82 #:use-module (gnu packages base)
83 #:use-module (gnu packages bash)
84 #:use-module (gnu packages certs)
85 #:use-module (gnu packages check)
86 #:use-module (gnu packages compression)
87 #:use-module (gnu packages dbm)
88 #:use-module (gnu packages hurd)
89 #:use-module (gnu packages libffi)
90 #:use-module (gnu packages ncurses)
91 #:use-module (gnu packages pkg-config)
92 #:use-module (gnu packages python-xyz)
93 #:use-module (gnu packages readline)
94 #:use-module (gnu packages shells)
95 #:use-module (gnu packages sqlite)
96 #:use-module (gnu packages tcl)
97 #:use-module (gnu packages tls)
98 #:use-module (gnu packages xml)
99 #:use-module (guix packages)
100 #:use-module (guix download)
101 #:use-module (guix utils)
102 #:use-module (guix build-system gnu)
103 #:use-module (guix build-system trivial)
104 #:use-module (srfi srfi-1)
105 #:use-module (srfi srfi-26))
107 (define-public python-2.7
110 (replacement python-2.7/fixed)
115 (uri (string-append "https://www.python.org/ftp/python/"
116 version "/Python-" version ".tar.xz"))
119 "0hds28cg226m8j8sr394nm9yc4gxhvlv109w0avsf2mxrlrz0hsd"))
120 (patches (search-patches "python-2.7-search-paths.patch"
121 "python-2-deterministic-build-info.patch"
122 "python-2.7-site-prefixes.patch"
123 "python-2.7-source-date-epoch.patch"
124 "python-2.7-adjust-tests.patch"
125 "python-cross-compile.patch"))
126 (modules '((guix build utils)))
129 ;; Ensure the bundled copies of these libraries are not used.
130 (for-each delete-file-recursively
131 '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
133 (substitute* "Modules/Setup.dist"
134 ;; Link Expat instead of embedding the bundled one.
135 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
137 ;; Suboptimal to delete failing tests here, but if we delete them in
138 ;; the arguments then we need to make sure to strip out that phase
139 ;; when it gets inherited by python and python-minimal.
140 (for-each delete-file
141 '("Lib/test/test_compileall.py"
142 "Lib/test/test_ctypes.py" ; fails on mips64el
143 "Lib/test/test_distutils.py"
144 "Lib/test/test_import.py"
145 "Lib/test/test_shutil.py"
146 "Lib/test/test_socket.py"
147 "Lib/test/test_subprocess.py"))
150 "tk")) ;tkinter; adds 50 MiB to the closure
151 (build-system gnu-build-system)
153 `(#:test-target "test"
155 (list "--enable-shared" ;allow embedding
156 "--with-system-expat" ;for XML support
157 "--with-system-ffi" ;build ctypes
158 "--with-ensurepip=install" ;install pip and setuptools
159 "--enable-unicode=ucs4"
161 ;; Prevent the installed _sysconfigdata.py from retaining a reference
166 ;; Disable runtime check failing if cross-compiling, see:
167 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
168 ,@(if (%current-target-system)
169 '("ac_cv_buggy_getaddrinfo=no"
170 "ac_cv_file__dev_ptmx=no"
171 "ac_cv_file__dev_ptc=no")
173 (string-append "LDFLAGS=-Wl,-rpath="
174 (assoc-ref %outputs "out") "/lib"))
175 ;; With no -j argument tests use all available cpus, so provide one.
178 (format #f "TESTOPTS=-j~d" (parallel-job-count))
179 ;; Exclude the following tests as they fail
180 ;; non-deterministically with "error: [Errno 104] Connection
181 ;; reset by peer." Python 3 seems unaffected. A potential fix,
182 ;; yet to be backported to Python 2, is available at:
183 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
184 " --exclude test_urllib2_localnet test_httplib"))
186 #:modules ((ice-9 ftw) (ice-9 match)
187 (guix build utils) (guix build gnu-build-system))
189 (modify-phases %standard-phases
191 'configure 'patch-lib-shells
193 ;; This variable is used in setup.py to enable cross compilation
194 ;; specific switches. As it is not set properly by configure
195 ;; script, set it manually.
196 ,@(if (%current-target-system)
197 '((setenv "_PYTHON_HOST_PLATFORM" ""))
199 ;; Filter for existing files, since some may not exist in all
200 ;; versions of python that are built with this recipe.
201 (substitute* (filter file-exists?
202 '("Lib/subprocess.py"
204 "Lib/distutils/tests/test_spawn.py"
205 "Lib/test/support/__init__.py"
206 "Lib/test/test_subprocess.py"))
207 (("/bin/sh") (which "sh")))
210 `((add-before 'build 'patch-regen-for-hurd
211 (lambda* (#:key inputs #:allow-other-keys)
212 (let ((libc (assoc-ref inputs "libc")))
213 (substitute* "Lib/plat-generic/regen"
214 (("/usr/include/") (string-append libc "/include/")))
217 (add-before 'configure 'do-not-record-configure-flags
218 (lambda* (#:key configure-flags #:allow-other-keys)
219 ;; Remove configure flags from the installed '_sysconfigdata.py'
220 ;; and 'Makefile' so we don't end up keeping references to the
223 ;; Preserve at least '--with-system-ffi' since otherwise the
224 ;; thing tries to build libffi, fails, and we end up with a
225 ;; Python that lacks ctypes.
226 (substitute* "configure"
227 (("^CONFIG_ARGS=.*$")
228 (format #f "CONFIG_ARGS='~a'\n"
229 (if (member "--with-system-ffi" configure-flags)
236 ;; 'Lib/test/test_site.py' needs a valid $HOME
237 (setenv "HOME" (getcwd))
240 'unpack 'set-source-file-times-to-1980
241 ;; XXX One of the tests uses a ZIP library to pack up some of the
242 ;; source tree, and fails with "ZIP does not support timestamps
243 ;; before 1980". Work around this by setting the file times in the
244 ;; source tree to sometime in early 1980.
246 (let ((circa-1980 (* 10 366 24 60 60)))
247 (ftw "." (lambda (file stat flag)
248 (utime file circa-1980 circa-1980)
251 (add-after 'install 'remove-tests
252 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
253 ;; because these files are used by some libraries out there.
254 (lambda* (#:key outputs #:allow-other-keys)
255 (let ((out (assoc-ref outputs "out")))
256 (match (scandir (string-append out "/lib")
258 (string-prefix? "python" name)))
260 (let ((testdir (string-append out "/lib/" pythonX.Y
262 (with-directory-excursion testdir
263 (for-each delete-file-recursively
270 (string-prefix? "test_support."
272 (call-with-output-file "__init__.py" (const #t))
274 (add-after 'remove-tests 'rebuild-bytecode
275 (lambda* (#:key outputs #:allow-other-keys)
276 (let ((out (assoc-ref outputs "out")))
277 ;; Disable hash randomization to ensure the generated .pycs
279 (setenv "PYTHONHASHSEED" "0")
282 (format #t "Compiling with optimization level: ~a\n"
283 (if (null? opt) "none" (car opt)))
284 (for-each (lambda (file)
286 `(,,(if (%current-target-system)
288 '(string-append out "/bin/python"))
292 ;; Don't build lib2to3, because it contains Python 3 code.
295 (find-files out "\\.py$")))
296 (list '() '("-O") '("-OO")))
298 (add-after 'install 'move-tk-inter
299 (lambda* (#:key outputs #:allow-other-keys)
300 ;; When Tkinter support is built move it to a separate output so
301 ;; that the main output doesn't contain a reference to Tcl/Tk.
302 (let ((out (assoc-ref outputs "out"))
303 (tk (assoc-ref outputs "tk")))
305 (match (find-files out "tkinter.*\\.so")
307 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
308 ;; want it under TK/lib/pythonX.Y/site-packages.
309 (let* ((len (string-length out))
310 (target (string-append
313 (dirname (dirname tkinter.so))
316 (install-file tkinter.so target)
317 (delete-file tkinter.so)))))
323 ("libffi" ,libffi) ; for ctypes
324 ("sqlite" ,sqlite) ; for sqlite extension
326 ("readline" ,readline)
329 ("tk" ,tk))) ; for tkinter
331 `(("pkg-config" ,pkg-config)
332 ;; When cross-compiling, a native version of Python itself is needed.
333 ,@(if (%current-target-system)
334 `(("python2" ,this-package)
338 (list (search-path-specification
339 (variable "PYTHONPATH")
340 (files '("lib/python2.7/site-packages")))))
341 (home-page "https://www.python.org")
342 (synopsis "High-level, dynamically-typed programming language")
344 "Python is a remarkably powerful dynamic programming language that
345 is used in a wide variety of application domains. Some of its key
346 distinguishing features include: clear, readable syntax; strong
347 introspection capabilities; intuitive object orientation; natural
348 expression of procedural code; full modularity, supporting hierarchical
349 packages; exception-based error handling; and very high level dynamic
351 (properties '((cpe-name . "python")))
352 (license license:psfl)))
354 (define python-2.7/fixed
358 (inherit (package-source python-2.7))
359 (patches (append (search-patches "python-2.7-CVE-2021-3177.patch")
360 (origin-patches (package-source python-2.7))))))))
362 ;; Current 2.x version.
363 (define-public python-2 python-2.7)
365 (define-public python2-called-python
366 ;; Both 2.x and 3.x used to be called "python". In commit
367 ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the
368 ;; Python 2.x package to "python2".
372 (properties `((superseded . ,python-2)))))
374 (define-public python-3.8
375 (package (inherit python-2)
377 (replacement python-3.8/fixed)
381 (uri (string-append "https://www.python.org/ftp/python/"
382 version "/Python-" version ".tar.xz"))
383 (patches (search-patches
384 "python-CVE-2020-26116.patch"
385 "python-3-fix-tests.patch"
386 "python-3.8-fix-tests.patch"
387 "python-3-deterministic-build-info.patch"
388 "python-3-search-paths.patch"))
391 "1ps5v323cp5czfshqjmbsqw7nvrdpcbk06f62jbzaqik4gfffii6"))
392 (modules '((guix build utils)))
395 ;; Delete the bundled copy of libexpat.
396 (delete-file-recursively "Modules/expat")
397 (substitute* "Modules/Setup"
398 ;; Link Expat instead of embedding the bundled one.
399 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
402 (substitute-keyword-arguments (package-arguments python-2)
404 `(list (string-append
405 (format #f "TESTOPTS=-j~d" (parallel-job-count))
406 ;; test_mmap fails on low-memory systems.
407 " --exclude test_mmap"
408 ;; test_socket may hang and eventually run out of memory
409 ;; on some systems: <https://bugs.python.org/issue34587>.
412 '(" test_posix" ;multiple errors
416 " test_tempfile" ;chflags: invalid argument:
417 ; tbv14c9t/dir0/dir0/dir0/test0.txt
418 " test_asyncio" ;runs over 10min
419 " test_os" ;stty: 'standard input':
420 ; Inappropriate ioctl for device
421 " test_openpty" ;No such file or directory
422 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
424 " test_compileall" ;multiple errors
425 " test_poll" ;list index out of range
426 " test_subprocess" ;runs over 10min
427 " test_asyncore" ;multiple errors
428 " test_threadsignals"
429 " test_eintr" ;Process return code is -14
430 " test_io" ;multiple errors
433 " test_threading" ;runs over 10min
435 " test_bidirectional_pty"
436 " test_create_unix_connection"
437 " test_unix_sock_client_ops"
438 " test_open_unix_connection"
439 " test_open_unix_connection_error"
440 " test_read_pty_output"
444 `(modify-phases ,phases
446 `((delete 'patch-regen-for-hurd)) ;regen was removed after 3.5.9
449 ;; The build system refuses to cross-compile for unknown targets
450 ;; even though it works fine. Add GNU/Hurd target.
451 ;; TODO: Make it a patch in a future rebuild cycle.
452 '((add-before 'configure 'support-hurd-cross-compile
454 (substitute* "configure"
455 (("\\*-\\*-vxworks.*" all)
456 (string-append "*-*-gnu)\nac_sys_system=GNU\n;;\n" all)))
459 (add-before 'check 'set-TZDIR
460 (lambda* (#:key inputs native-inputs #:allow-other-keys)
461 ;; test_email requires the Olson time zone database.
463 (string-append (assoc-ref
464 (or native-inputs inputs) "tzdata")
467 ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it
468 ;; again afterwards. See <https://bugs.python.org/issue34022>.
469 (add-before 'check 'unset-SOURCE_DATE_EPOCH
470 (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
471 (add-after 'check 'reset-SOURCE_DATE_EPOCH
472 (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
473 (replace 'rebuild-bytecode
474 (lambda* (#:key outputs #:allow-other-keys)
475 (let ((out (assoc-ref outputs "out")))
476 ;; Disable hash randomization to ensure the generated .pycs
478 (setenv "PYTHONHASHSEED" "0")
481 (format #t "Compiling with optimization level: ~a\n"
482 (if (null? opt) "none" (car opt)))
483 (for-each (lambda (file)
485 `(,,(if (%current-target-system)
492 ;; Don't build lib2to3, because it's Python 2 code.
495 (find-files out "\\.py$")))
496 (list '() '("-O") '("-OO")))
498 ;; XXX: Apply patch on ARM platforms only to avoid a full rebuild.
499 ;; Remove this phase in the next rebuild cycle.
500 ,@(let ((system (or (%current-target-system)
502 (if (any (cute string-prefix? <> system)
504 '((add-after 'unpack 'apply-alignment-patch
505 (lambda* (#:key native-inputs inputs #:allow-other-keys)
506 (invoke "patch" "-p1" "--force" "--input"
507 (assoc-ref (or native-inputs inputs)
508 "arm-alignment.patch")))))
511 `(("tzdata" ,tzdata-for-tests)
513 ;; Disable unaligned accesses in the sha3 module on ARM as
514 ;; it causes a test failure when building 32-bit Python on a
515 ;; 64-bit kernel. See <https://bugs.python.org/issue36515>.
516 ;; TODO: make this a regular patch in the next rebuild cycle.
517 ,@(let ((system (or (%current-target-system)
519 (if (any (cute string-prefix? <> system)
521 `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
524 ,@(if (%current-target-system)
525 `(("python3" ,this-package))
527 ,@(package-native-inputs python-2)))
529 (list (search-path-specification
530 (variable "PYTHONPATH")
531 (files (list (string-append "lib/python"
532 (version-major+minor version)
533 "/site-packages"))))))))
535 (define python-3.8/fixed
539 (inherit (package-source python-3.8))
540 (patches (append (search-patches "python-3.8-CVE-2021-3177.patch")
541 (origin-patches (package-source python-3.8))))))))
543 (define-public python-3.9
544 (package (inherit python-3.8)
549 (uri (string-append "https://www.python.org/ftp/python/"
550 version "/Python-" version ".tar.xz"))
551 (patches (search-patches
552 "python-3.9-fix-tests.patch"
553 "python-3-deterministic-build-info.patch"
554 "python-3-search-paths.patch"))
557 "0z94vv5qhlwvcgc4sy9sdiqs0220s84wx3b62vslh5419z2k881w"))
558 (modules '((guix build utils)))
561 ;; Delete the bundled copy of libexpat.
562 (delete-file-recursively "Modules/expat")
563 (substitute* "Modules/Setup"
564 ;; Link Expat instead of embedding the bundled one.
565 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
568 ;; Current 3.x version.
569 (define-public python-3 python-3.8)
571 ;; Current major version.
572 (define-public python python-3)
574 ;; Minimal variants of Python, mostly used to break the cycle between Tk and
575 ;; Python (Tk -> libxcb -> Python.)
577 (define-public python2-minimal
578 (package/inherit python-2
579 (name "python2-minimal")
582 ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which
583 ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus
584 ;; libffi. Expat is needed for XML support which is expected by a lot
585 ;; of libraries out there.
586 (inputs `(("expat" ,expat)
590 (define-public python-minimal
591 (package/inherit python
592 (name "python-minimal")
595 ;; Build fails due to missing ctypes without libffi.
596 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
597 ;; zlib is required by 'zipimport', used by pip. Expat is needed
598 ;; for XML support, which is generally expected to be available.
599 (inputs `(("expat" ,expat)
604 (define-public python-debug
605 (package/inherit python
606 (name "python-debug")
607 (outputs '("out" "debug"))
608 (build-system gnu-build-system)
610 (substitute-keyword-arguments (package-arguments python)
611 ((#:configure-flags flags '())
612 `(cons "--with-pydebug" ,flags))))
614 "High-level, dynamically-typed programming language (for debugging)")
616 "This variant of Python provides an interpreter built with
617 @code{--with-pydebug} to help develop and debug extensions. See
618 @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
619 for more information.")))
621 (define* (wrap-python3 python
623 (name (string-append (package-name python) "-wrapper")))
624 (package/inherit python
627 (build-system trivial-build-system)
629 (inputs `(("bash" ,bash)))
630 (propagated-inputs `(("python" ,python)))
632 `(#:modules ((guix build utils))
635 (use-modules (guix build utils))
636 (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
637 (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
641 (symlink (string-append python old)
642 (string-append bin "/" new)))
643 `("python3" ,"pydoc3" ,"idle3" ,"pip3")
644 `("python" ,"pydoc" ,"idle" ,"pip"))
645 ;; python-config outputs search paths based upon its location,
646 ;; use a bash wrapper to avoid changing its outputs.
647 (let ((bash (string-append (assoc-ref %build-inputs "bash")
649 (old (string-append python "python3-config"))
650 (new (string-append bin "/python-config")))
651 (with-output-to-file new
653 (format #t "#!~a~%" bash)
654 (format #t "exec \"~a\" \"$@\"~%" old)
657 (synopsis "Wrapper for the Python 3 commands")
659 "This package provides wrappers for the commands of Python@tie{}3.x such
660 that they can be invoked under their usual name---e.g., @command{python}
661 instead of @command{python3} or @command{pip} instead of @command{pip3}.
662 To function properly, this package should not be installed together with the
663 @command{python} package.")))
665 (define-public python-wrapper (wrap-python3 python))
666 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
668 (define-public micropython
675 (uri (string-append "https://github.com/micropython/micropython/"
676 "releases/download/v" version
677 "/micropython-" version ".tar.xz"))
679 (base32 "0k6ri3rxxnnmvcbi7z7x59r21f4vj9dcf9j64jhj1cgazmb62c4p"))
680 (modules '((guix build utils)))
683 (delete-file-recursively "ports/cc3200/FreeRTOS")
684 (with-directory-excursion "lib"
685 ;; TODO: Unbundle axtls and berkley-db-1.xx
686 (for-each delete-file-recursively
687 '("libffi" "lwip" "stm32lib" "nrfx")))
689 (build-system gnu-build-system)
692 (modify-phases %standard-phases
693 (add-before 'build 'build-mpy-cross
694 (lambda* (#:key make-flags #:allow-other-keys)
695 (with-directory-excursion "mpy-cross"
696 (apply invoke "make" make-flags))))
697 (add-after 'build-mpy-cross 'prepare-build
700 ;; see: https://github.com/micropython/micropython/pull/4246
701 (substitute* "Makefile"
702 (("-Os") "-Os -ffp-contract=off"))
704 (replace 'install-license-files
705 ;; We don't build in the root directory so the file isn't found.
706 (lambda* (#:key outputs #:allow-other-keys)
707 (let* ((out (assoc-ref outputs "out"))
708 (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
709 (install-file "../../LICENSE" dest))
711 (delete 'configure)) ; no configure
712 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
714 #:test-target "test"))
716 `(("pkg-config" ,pkg-config)
717 ("python" ,python-wrapper)))
719 `(("libffi" ,libffi)))
720 (home-page "https://micropython.org/")
721 (synopsis "Python implementation for microcontrollers and constrained systems")
722 (description "MicroPython is a lean and efficient implementation of the
723 Python 3 programming language that includes a small subset of the Python
724 standard library and is optimised to run on microcontrollers and in constrained
725 environments. MicroPython is packed full of advanced features such as an
726 interactive prompt, arbitrary precision integers, closures, list comprehension,
727 generators, exception handling and more. Still it is compact enough to fit and
728 run within just 256k of code space and 16k of RAM. MicroPython aims to be as
729 compatible with normal Python as possible to allow you to transfer code with
730 ease from the desktop to a microcontroller or embedded system.")
731 (license license:expat)))
739 (uri (string-append "https://bitbucket.org/pypy/pypy/downloads/" ;
740 "pypy3.6-v" version "-src.tar.bz2"))
743 "10zsk8jby8j6visk5mzikpb1cidvz27qq4pfpa26jv53klic6b0c"))
744 (patches (search-patches "pypy3-7.3.1-fix-tests.patch"))))
745 (build-system gnu-build-system)
747 `(("python-2" ,python-2)
748 ("pkg-config" ,pkg-config)
749 ("tar" ,tar) ; Required for package.py
750 ("python2-pycparser" ,python2-pycparser)
751 ("python2-hypothesis" ,python2-hypothesis)
752 ("nss-certs" ,nss-certs) ; For ssl tests
766 ("bash-minimal" ,bash-minimal) ; Used as /bin/sh
767 ("xz" ,xz))) ; liblzma
769 `(#:tests? #f ;FIXME: Disabled for now, there are many tests failing.
770 #:modules ((ice-9 ftw) (ice-9 match)
771 (guix build utils) (guix build gnu-build-system))
772 #:phases (modify-phases %standard-phases
774 (add-after 'unpack 'patch-source
775 (lambda* (#:key inputs outputs #:allow-other-keys)
776 (substitute* '("rpython/rlib/clibffi.py")
777 ;; find_library does not work for libc
778 (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
779 (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
780 ;; Make reproducible (XXX: unused?)
781 (("time\\.localtime\\(\\)") "time.gmtime(0)"))
782 (substitute* '("pypy/module/sys/version.py")
784 (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
785 (substitute* '("lib_pypy/_tkinter/tklib_build.py")
786 ;; Link to versioned libtcl and libtk
787 (("linklibs = \\['tcl', 'tk'\\]")
788 "linklibs = ['tcl8.6', 'tk8.6']")
789 (("incdirs = \\[\\]")
790 (string-append "incdirs = ['"
791 (assoc-ref inputs "tcl")
793 (assoc-ref inputs "tk")
795 (substitute* '("lib_pypy/_curses_build.py")
797 (("/usr/local") (assoc-ref inputs "ncurses")))
798 (substitute* '("lib_pypy/_sqlite3_build.py")
799 ;; Always use search paths
800 (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
802 (("/usr/local") (assoc-ref inputs "sqlite"))
803 (("libname = 'sqlite3'")
804 (string-append "libname = '"
805 (assoc-ref inputs "sqlite")
806 "/lib/libsqlite3.so.0'")))
807 (substitute* '("lib-python/3/subprocess.py")
810 (string-append (assoc-ref inputs "bash-minimal") "/bin/sh")))
811 (substitute* '("lib-python/3/distutils/unixccompiler.py")
812 ;; gcc-toolchain does not provide symlink cc -> gcc
813 (("\"cc\"") "\"gcc\""))
816 'unpack 'set-source-file-times-to-1980
817 ;; copied from python package, required by zip testcase
819 (let ((circa-1980 (* 10 366 24 60 60)))
820 (ftw "." (lambda (file stat flag)
821 (utime file circa-1980 circa-1980)
825 (lambda* (#:key inputs #:allow-other-keys)
826 (with-directory-excursion "pypy/goal"
827 ;; Build with jit optimization.
829 "../../rpython/bin/rpython"
830 (string-append "--make-jobs="
831 (number->string (parallel-job-count)))
833 "targetpypystandalone"))
834 ;; Build c modules and package everything, so tests work.
835 (with-directory-excursion "pypy/tool/release"
836 (unsetenv "PYTHONPATH") ; Do not use the system’s python libs:
837 ; AttributeError: module 'enum' has no
838 ; attribute 'IntFlag'
839 (invoke "python2" "package.py"
840 "--archive-name" "pypy-dist"
841 "--builddir" (getcwd)))))
843 (lambda* (#:key tests? #:allow-other-keys)
846 (setenv "HOME" "/tmp") ; test_with_pip tries to
847 ; access ~/.cache/pip
848 ;; Run library tests only (no interpreter unit
849 ;; tests). This is what Gentoo does.
853 "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
855 (format #t "test suite not run~%"))
858 (lambda* (#:key inputs outputs #:allow-other-keys)
859 (with-directory-excursion "pypy/tool/release"
863 (delete-file-recursively (string-append
864 "pypy-dist/lib-python/3/" x)))
873 ;; Patch shebang referencing python2
874 (substitute* '("pypy-dist/lib-python/3/cgi.py"
875 "pypy-dist/lib-python/3/encodings/rot_13.py")
877 (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3")))
878 (with-fluids ((%default-port-encoding "ISO-8859-1"))
879 (substitute* '("pypy-dist/lib_pypy/_md5.py"
880 "pypy-dist/lib_pypy/_sha1.py")
882 (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3"))))
883 (copy-recursively "pypy-dist" (assoc-ref outputs "out")))
885 (home-page "https://www.pypy.org/")
886 (synopsis "Python implementation with just-in-time compilation")
887 (description "PyPy is a faster, alternative implementation of the Python
888 programming language employing a just-in-time compiler. It supports most
889 Python code natively, including C extensions.")
890 (license (list license:expat ; pypy itself; _pytest/
891 license:psfl ; python standard library in lib-python/
892 license:asl2.0 ; dotviewer/font/ and some of lib-python/
893 license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
894 license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
895 (license:non-copyleft
896 "http://www.unicode.org/copyright.html")))))