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".
369 (package/inherit python-2
371 (properties `((superseded . ,python-2)))))
373 (define-public python-3.8
374 (package (inherit python-2)
376 (replacement python-3.8/fixed)
380 (uri (string-append "https://www.python.org/ftp/python/"
381 version "/Python-" version ".tar.xz"))
382 (patches (search-patches
383 "python-CVE-2020-26116.patch"
384 "python-3-fix-tests.patch"
385 "python-3.8-fix-tests.patch"
386 "python-3-deterministic-build-info.patch"
387 "python-3-search-paths.patch"))
390 "1ps5v323cp5czfshqjmbsqw7nvrdpcbk06f62jbzaqik4gfffii6"))
391 (modules '((guix build utils)))
394 ;; Delete the bundled copy of libexpat.
395 (delete-file-recursively "Modules/expat")
396 (substitute* "Modules/Setup"
397 ;; Link Expat instead of embedding the bundled one.
398 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
401 (substitute-keyword-arguments (package-arguments python-2)
403 `(list (string-append
404 (format #f "TESTOPTS=-j~d" (parallel-job-count))
405 ;; test_mmap fails on low-memory systems.
406 " --exclude test_mmap"
407 ;; test_socket may hang and eventually run out of memory
408 ;; on some systems: <https://bugs.python.org/issue34587>.
411 '(" test_posix" ;multiple errors
415 " test_tempfile" ;chflags: invalid argument:
416 ; tbv14c9t/dir0/dir0/dir0/test0.txt
417 " test_asyncio" ;runs over 10min
418 " test_os" ;stty: 'standard input':
419 ; Inappropriate ioctl for device
420 " test_openpty" ;No such file or directory
421 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
423 " test_compileall" ;multiple errors
424 " test_poll" ;list index out of range
425 " test_subprocess" ;runs over 10min
426 " test_asyncore" ;multiple errors
427 " test_threadsignals"
428 " test_eintr" ;Process return code is -14
429 " test_io" ;multiple errors
432 " test_threading" ;runs over 10min
434 " test_bidirectional_pty"
435 " test_create_unix_connection"
436 " test_unix_sock_client_ops"
437 " test_open_unix_connection"
438 " test_open_unix_connection_error"
439 " test_read_pty_output"
443 `(modify-phases ,phases
445 `((delete 'patch-regen-for-hurd)) ;regen was removed after 3.5.9
448 ;; The build system refuses to cross-compile for unknown targets
449 ;; even though it works fine. Add GNU/Hurd target.
450 ;; TODO: Make it a patch in a future rebuild cycle.
451 '((add-before 'configure 'support-hurd-cross-compile
453 (substitute* "configure"
454 (("\\*-\\*-vxworks.*" all)
455 (string-append "*-*-gnu)\nac_sys_system=GNU\n;;\n" all)))
458 (add-before 'check 'set-TZDIR
459 (lambda* (#:key inputs native-inputs #:allow-other-keys)
460 ;; test_email requires the Olson time zone database.
462 (string-append (assoc-ref
463 (or native-inputs inputs) "tzdata")
466 ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it
467 ;; again afterwards. See <https://bugs.python.org/issue34022>.
468 (add-before 'check 'unset-SOURCE_DATE_EPOCH
469 (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
470 (add-after 'check 'reset-SOURCE_DATE_EPOCH
471 (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
472 (replace 'rebuild-bytecode
473 (lambda* (#:key outputs #:allow-other-keys)
474 (let ((out (assoc-ref outputs "out")))
475 ;; Disable hash randomization to ensure the generated .pycs
477 (setenv "PYTHONHASHSEED" "0")
480 (format #t "Compiling with optimization level: ~a\n"
481 (if (null? opt) "none" (car opt)))
482 (for-each (lambda (file)
484 `(,,(if (%current-target-system)
491 ;; Don't build lib2to3, because it's Python 2 code.
494 (find-files out "\\.py$")))
495 (list '() '("-O") '("-OO")))
497 ;; XXX: Apply patch on ARM platforms only to avoid a full rebuild.
498 ;; Remove this phase in the next rebuild cycle.
499 ,@(let ((system (or (%current-target-system)
501 (if (any (cute string-prefix? <> system)
503 '((add-after 'unpack 'apply-alignment-patch
504 (lambda* (#:key native-inputs inputs #:allow-other-keys)
505 (invoke "patch" "-p1" "--force" "--input"
506 (assoc-ref (or native-inputs inputs)
507 "arm-alignment.patch")))))
510 `(("tzdata" ,tzdata-for-tests)
512 ;; Disable unaligned accesses in the sha3 module on ARM as
513 ;; it causes a test failure when building 32-bit Python on a
514 ;; 64-bit kernel. See <https://bugs.python.org/issue36515>.
515 ;; TODO: make this a regular patch in the next rebuild cycle.
516 ,@(let ((system (or (%current-target-system)
518 (if (any (cute string-prefix? <> system)
520 `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
523 ,@(if (%current-target-system)
524 `(("python3" ,this-package))
526 ,@(package-native-inputs python-2)))
528 (list (search-path-specification
529 (variable "PYTHONPATH")
530 (files (list (string-append "lib/python"
531 (version-major+minor version)
532 "/site-packages"))))))))
534 (define python-3.8/fixed
538 (inherit (package-source python-3.8))
539 (patches (append (search-patches "python-3.8-CVE-2021-3177.patch")
540 (origin-patches (package-source python-3.8))))))))
542 (define-public python-3.9
543 (package (inherit python-3.8)
548 (uri (string-append "https://www.python.org/ftp/python/"
549 version "/Python-" version ".tar.xz"))
550 (patches (search-patches
551 "python-3.9-fix-tests.patch"
552 "python-3-deterministic-build-info.patch"
553 "python-3-search-paths.patch"))
556 "0z94vv5qhlwvcgc4sy9sdiqs0220s84wx3b62vslh5419z2k881w"))
557 (modules '((guix build utils)))
560 ;; Delete the bundled copy of libexpat.
561 (delete-file-recursively "Modules/expat")
562 (substitute* "Modules/Setup"
563 ;; Link Expat instead of embedding the bundled one.
564 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
567 ;; Current 3.x version.
568 (define-public python-3 python-3.8)
570 ;; Current major version.
571 (define-public python python-3)
573 ;; Minimal variants of Python, mostly used to break the cycle between Tk and
574 ;; Python (Tk -> libxcb -> Python.)
576 (define-public python2-minimal
577 (package/inherit python-2
578 (name "python2-minimal")
581 ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which
582 ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus
583 ;; libffi. Expat is needed for XML support which is expected by a lot
584 ;; of libraries out there.
585 (inputs `(("expat" ,expat)
589 (define-public python-minimal
590 (package/inherit python
591 (name "python-minimal")
594 ;; Build fails due to missing ctypes without libffi.
595 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
596 ;; zlib is required by 'zipimport', used by pip. Expat is needed
597 ;; for XML support, which is generally expected to be available.
598 (inputs `(("expat" ,expat)
603 (define-public python-debug
604 (package/inherit python
605 (name "python-debug")
606 (outputs '("out" "debug"))
607 (build-system gnu-build-system)
609 (substitute-keyword-arguments (package-arguments python)
610 ((#:configure-flags flags '())
611 `(cons "--with-pydebug" ,flags))))
613 "High-level, dynamically-typed programming language (for debugging)")
615 "This variant of Python provides an interpreter built with
616 @code{--with-pydebug} to help develop and debug extensions. See
617 @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
618 for more information.")))
620 (define* (wrap-python3 python
622 (name (string-append (package-name python) "-wrapper")))
623 (package/inherit python
626 (build-system trivial-build-system)
628 (inputs `(("bash" ,bash)))
629 (propagated-inputs `(("python" ,python)))
631 `(#:modules ((guix build utils))
634 (use-modules (guix build utils))
635 (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
636 (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
640 (symlink (string-append python old)
641 (string-append bin "/" new)))
642 `("python3" ,"pydoc3" ,"idle3" ,"pip3")
643 `("python" ,"pydoc" ,"idle" ,"pip"))
644 ;; python-config outputs search paths based upon its location,
645 ;; use a bash wrapper to avoid changing its outputs.
646 (let ((bash (string-append (assoc-ref %build-inputs "bash")
648 (old (string-append python "python3-config"))
649 (new (string-append bin "/python-config")))
650 (with-output-to-file new
652 (format #t "#!~a~%" bash)
653 (format #t "exec \"~a\" \"$@\"~%" old)
656 (synopsis "Wrapper for the Python 3 commands")
658 "This package provides wrappers for the commands of Python@tie{}3.x such
659 that they can be invoked under their usual name---e.g., @command{python}
660 instead of @command{python3} or @command{pip} instead of @command{pip3}.
661 To function properly, this package should not be installed together with the
662 @command{python} package.")))
664 (define-public python-wrapper (wrap-python3 python))
665 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
667 (define-public micropython
674 (uri (string-append "https://github.com/micropython/micropython/"
675 "releases/download/v" version
676 "/micropython-" version ".tar.xz"))
678 (base32 "0k6ri3rxxnnmvcbi7z7x59r21f4vj9dcf9j64jhj1cgazmb62c4p"))
679 (modules '((guix build utils)))
682 (delete-file-recursively "ports/cc3200/FreeRTOS")
683 (with-directory-excursion "lib"
684 ;; TODO: Unbundle axtls and berkley-db-1.xx
685 (for-each delete-file-recursively
686 '("libffi" "lwip" "stm32lib" "nrfx")))
688 (build-system gnu-build-system)
691 (modify-phases %standard-phases
692 (add-before 'build 'build-mpy-cross
693 (lambda* (#:key make-flags #:allow-other-keys)
694 (with-directory-excursion "mpy-cross"
695 (apply invoke "make" make-flags))))
696 (add-after 'build-mpy-cross 'prepare-build
699 ;; see: https://github.com/micropython/micropython/pull/4246
700 (substitute* "Makefile"
701 (("-Os") "-Os -ffp-contract=off"))
703 (replace 'install-license-files
704 ;; We don't build in the root directory so the file isn't found.
705 (lambda* (#:key outputs #:allow-other-keys)
706 (let* ((out (assoc-ref outputs "out"))
707 (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
708 (install-file "../../LICENSE" dest))
710 (delete 'configure)) ; no configure
711 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
713 #:test-target "test"))
715 `(("pkg-config" ,pkg-config)
716 ("python" ,python-wrapper)))
718 `(("libffi" ,libffi)))
719 (home-page "https://micropython.org/")
720 (synopsis "Python implementation for microcontrollers and constrained systems")
721 (description "MicroPython is a lean and efficient implementation of the
722 Python 3 programming language that includes a small subset of the Python
723 standard library and is optimised to run on microcontrollers and in constrained
724 environments. MicroPython is packed full of advanced features such as an
725 interactive prompt, arbitrary precision integers, closures, list comprehension,
726 generators, exception handling and more. Still it is compact enough to fit and
727 run within just 256k of code space and 16k of RAM. MicroPython aims to be as
728 compatible with normal Python as possible to allow you to transfer code with
729 ease from the desktop to a microcontroller or embedded system.")
730 (license license:expat)))
738 (uri (string-append "https://bitbucket.org/pypy/pypy/downloads/" ;
739 "pypy3.6-v" version "-src.tar.bz2"))
742 "10zsk8jby8j6visk5mzikpb1cidvz27qq4pfpa26jv53klic6b0c"))
743 (patches (search-patches "pypy3-7.3.1-fix-tests.patch"))))
744 (build-system gnu-build-system)
746 `(("python-2" ,python-2)
747 ("pkg-config" ,pkg-config)
748 ("tar" ,tar) ; Required for package.py
749 ("python2-pycparser" ,python2-pycparser)
750 ("python2-hypothesis" ,python2-hypothesis)
751 ("nss-certs" ,nss-certs) ; For ssl tests
765 ("bash-minimal" ,bash-minimal) ; Used as /bin/sh
766 ("xz" ,xz))) ; liblzma
768 `(#:tests? #f ;FIXME: Disabled for now, there are many tests failing.
769 #:modules ((ice-9 ftw) (ice-9 match)
770 (guix build utils) (guix build gnu-build-system))
771 #:phases (modify-phases %standard-phases
773 (add-after 'unpack 'patch-source
774 (lambda* (#:key inputs outputs #:allow-other-keys)
775 (substitute* '("rpython/rlib/clibffi.py")
776 ;; find_library does not work for libc
777 (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
778 (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
779 ;; Make reproducible (XXX: unused?)
780 (("time\\.localtime\\(\\)") "time.gmtime(0)"))
781 (substitute* '("pypy/module/sys/version.py")
783 (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
784 (substitute* '("lib_pypy/_tkinter/tklib_build.py")
785 ;; Link to versioned libtcl and libtk
786 (("linklibs = \\['tcl', 'tk'\\]")
787 "linklibs = ['tcl8.6', 'tk8.6']")
788 (("incdirs = \\[\\]")
789 (string-append "incdirs = ['"
790 (assoc-ref inputs "tcl")
792 (assoc-ref inputs "tk")
794 (substitute* '("lib_pypy/_curses_build.py")
796 (("/usr/local") (assoc-ref inputs "ncurses")))
797 (substitute* '("lib_pypy/_sqlite3_build.py")
798 ;; Always use search paths
799 (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
801 (("/usr/local") (assoc-ref inputs "sqlite"))
802 (("libname = 'sqlite3'")
803 (string-append "libname = '"
804 (assoc-ref inputs "sqlite")
805 "/lib/libsqlite3.so.0'")))
806 (substitute* '("lib-python/3/subprocess.py")
809 (string-append (assoc-ref inputs "bash-minimal") "/bin/sh")))
810 (substitute* '("lib-python/3/distutils/unixccompiler.py")
811 ;; gcc-toolchain does not provide symlink cc -> gcc
812 (("\"cc\"") "\"gcc\""))
815 'unpack 'set-source-file-times-to-1980
816 ;; copied from python package, required by zip testcase
818 (let ((circa-1980 (* 10 366 24 60 60)))
819 (ftw "." (lambda (file stat flag)
820 (utime file circa-1980 circa-1980)
824 (lambda* (#:key inputs #:allow-other-keys)
825 (with-directory-excursion "pypy/goal"
826 ;; Build with jit optimization.
828 "../../rpython/bin/rpython"
829 (string-append "--make-jobs="
830 (number->string (parallel-job-count)))
832 "targetpypystandalone"))
833 ;; Build c modules and package everything, so tests work.
834 (with-directory-excursion "pypy/tool/release"
835 (unsetenv "PYTHONPATH") ; Do not use the system’s python libs:
836 ; AttributeError: module 'enum' has no
837 ; attribute 'IntFlag'
838 (invoke "python2" "package.py"
839 "--archive-name" "pypy-dist"
840 "--builddir" (getcwd)))))
842 (lambda* (#:key tests? #:allow-other-keys)
845 (setenv "HOME" "/tmp") ; test_with_pip tries to
846 ; access ~/.cache/pip
847 ;; Run library tests only (no interpreter unit
848 ;; tests). This is what Gentoo does.
852 "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
854 (format #t "test suite not run~%"))
857 (lambda* (#:key inputs outputs #:allow-other-keys)
858 (with-directory-excursion "pypy/tool/release"
862 (delete-file-recursively (string-append
863 "pypy-dist/lib-python/3/" x)))
872 ;; Patch shebang referencing python2
873 (substitute* '("pypy-dist/lib-python/3/cgi.py"
874 "pypy-dist/lib-python/3/encodings/rot_13.py")
876 (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3")))
877 (with-fluids ((%default-port-encoding "ISO-8859-1"))
878 (substitute* '("pypy-dist/lib_pypy/_md5.py"
879 "pypy-dist/lib_pypy/_sha1.py")
881 (string-append "#!" (assoc-ref outputs "out") "/bin/pypy3"))))
882 (copy-recursively "pypy-dist" (assoc-ref outputs "out")))
884 (home-page "https://www.pypy.org/")
885 (synopsis "Python implementation with just-in-time compilation")
886 (description "PyPy is a faster, alternative implementation of the Python
887 programming language employing a just-in-time compiler. It supports most
888 Python code natively, including C extensions.")
889 (license (list license:expat ; pypy itself; _pytest/
890 license:psfl ; python standard library in lib-python/
891 license:asl2.0 ; dotviewer/font/ and some of lib-python/
892 license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
893 license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
894 (license:non-copyleft
895 "http://www.unicode.org/copyright.html")))))