1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
3 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2021 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 Christine Lemmer-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, 2021 Marius Bakke <marius@gnu.org>
30 ;;; Copyright © 2016, 2017 Stefan Reichör <stefan@xsteve.at>
31 ;;; Copyright © 2016, 2017 Alex Vong <alexvong1995@gmail.com>
32 ;;; Copyright © 2016, 2017, 2018 Arun Isaac <arunisaac@systemreboot.net>
33 ;;; Copyright © 2016–2018, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
34 ;;; Copyright © 2016, 2017, 2018, 2021 Julien Lepiller <julien@lepiller.eu>
35 ;;; Copyright © 2016, 2017 Thomas Danckaert <post@thomasdanckaert.be>
36 ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
37 ;;; Copyright © 2017 Frederick M. Muriithi <fredmanglis@gmail.com>
38 ;;; Copyright © 2017, 2018 Adriano Peluso <catonano@gmail.com>
39 ;;; Copyright © 2017 Ben Sturmfels <ben@sturm.com.au>
40 ;;; Copyright © 2017, 2018, 2019 Mathieu Othacehe <m.othacehe@gmail.com>
41 ;;; Copyright © 2017 José Miguel Sánchez García <jmi2k@openmailbox.org>
42 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
43 ;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net>
44 ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
45 ;;; Copyright © 2017 Brendan Tildesley <mail@brendan.scot>
46 ;;; Copyright © 2018 Ethan R. Jones <ethanrjones97@gmail.com
47 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
48 ;;; Copyright © 2018 Vijayalakshmi Vedantham <vijimay12@gmail.com>
49 ;;; Copyright © 2018 Mathieu Lirzin <mthl@gnu.org>
50 ;;; Copyright © 2018 Adam Massmann <massmannak@gmail.com>
51 ;;; Copyright © 2016, 2018 Tomáš Čech <sleep_walker@gnu.org>
52 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
53 ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
54 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
55 ;;; Copyright © 2018, 2019, 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
56 ;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
57 ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
58 ;;; Copyright © 2019 Tanguy Le Carrour <tanguy@bioneland.org>
59 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
60 ;;; Copyright © 2020, 2021 Greg Hogan <code@greghogan.com>
62 ;;; This file is part of GNU Guix.
64 ;;; GNU Guix is free software; you can redistribute it and/or modify it
65 ;;; under the terms of the GNU General Public License as published by
66 ;;; the Free Software Foundation; either version 3 of the License, or (at
67 ;;; your option) any later version.
69 ;;; GNU Guix is distributed in the hope that it will be useful, but
70 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
71 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 ;;; GNU General Public License for more details.
74 ;;; You should have received a copy of the GNU General Public License
75 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
77 (define-module (gnu packages python)
78 #:use-module ((guix licenses) #:prefix license:)
79 #:use-module (gnu packages)
80 #:use-module (gnu packages base)
81 #:use-module (gnu packages bash)
82 #:use-module (gnu packages certs)
83 #:use-module (gnu packages check)
84 #:use-module (gnu packages compression)
85 #:use-module (gnu packages dbm)
86 #:use-module (gnu packages hurd)
87 #:use-module (gnu packages libffi)
88 #:use-module (gnu packages ncurses)
89 #:use-module (gnu packages pkg-config)
90 #:use-module (gnu packages python-xyz)
91 #:use-module (gnu packages readline)
92 #:use-module (gnu packages shells)
93 #:use-module (gnu packages sqlite)
94 #:use-module (gnu packages tcl)
95 #:use-module (gnu packages tls)
96 #:use-module (gnu packages xml)
97 #:use-module (guix gexp)
98 #:use-module (guix packages)
99 #:use-module (guix download)
100 #:use-module (guix utils)
101 #:use-module (guix build-system gnu)
102 #:use-module (guix build-system trivial)
103 #:use-module (srfi srfi-1)
104 #:use-module (srfi srfi-26)
106 #:export (customize-site
107 guix-pythonpath-search-path))
109 (define* (customize-site version)
110 "Generate a install-sitecustomize.py phase, using VERSION."
111 `(lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
112 (let* ((out (assoc-ref outputs "out"))
113 (site-packages (string-append
115 ,(version-major+minor version)
117 (sitecustomize.py (assoc-ref (or native-inputs inputs)
119 (dest (string-append site-packages "/sitecustomize.py")))
120 (mkdir-p site-packages)
121 (copy-file sitecustomize.py dest)
122 ;; Set the correct permissions on the installed file, else the byte
123 ;; compilation phase fails with a permission denied error.
124 (chmod dest #o644))))
126 (define (guix-pythonpath-search-path version)
127 "Generate a GUIX_PYTHONPATH search path specification, using VERSION."
128 (search-path-specification (variable "GUIX_PYTHONPATH")
129 (files (list (string-append
131 (version-major+minor version)
132 "/site-packages")))))
134 (define-public python-2.7
141 (uri (string-append "https://www.python.org/ftp/python/"
142 version "/Python-" version ".tar.xz"))
145 "0hzgxl94hnflis0d6m4szjx0b52gah7wpmcg5g00q7am6xwhwb5n"))
146 (patches (search-patches "python-2.7-search-paths.patch"
147 "python-2-deterministic-build-info.patch"
148 "python-2.7-site-prefixes.patch"
149 "python-2.7-source-date-epoch.patch"
150 "python-2.7-adjust-tests.patch"
151 "python-cross-compile.patch"
152 "python-2.7-CVE-2021-3177.patch"
153 "python-2.7-no-static-lib.patch"))
154 (modules '((guix build utils)))
157 ;; Ensure the bundled copies of these libraries are not used.
158 (for-each delete-file-recursively
159 '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
161 (substitute* "Modules/Setup.dist"
162 ;; Link Expat instead of embedding the bundled one.
163 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
165 ;; Suboptimal to delete failing tests here, but if we delete them in
166 ;; the arguments then we need to make sure to strip out that phase
167 ;; when it gets inherited by python and python-minimal.
168 (for-each delete-file
169 '("Lib/test/test_compileall.py"
170 "Lib/test/test_ctypes.py" ; fails on mips64el
171 "Lib/test/test_distutils.py"
172 "Lib/test/test_import.py"
173 "Lib/test/test_shutil.py"
174 "Lib/test/test_socket.py"
175 "Lib/test/test_subprocess.py"))))))
177 "tk" ;tkinter; adds 50 MiB to the closure
178 "idle")) ;programming environment; weighs 5MB
179 (build-system gnu-build-system)
181 `(#:test-target "test"
183 (list "--enable-shared" ;allow embedding
184 "--with-system-expat" ;for XML support
185 "--with-system-ffi" ;build ctypes
186 "--with-ensurepip=install" ;install pip and setuptools
187 "--with-computed-gotos" ;main interpreter loop optimization
188 "--enable-unicode=ucs4"
190 ;; FIXME: These flags makes Python significantly faster, but
191 ;; leads to non-reproducible binaries.
192 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
193 ;; "--enable-optimizations"
195 ;; Prevent the installed _sysconfigdata.py from retaining a reference
200 ;; Disable runtime check failing if cross-compiling, see:
201 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
202 ,@(if (%current-target-system)
203 '("ac_cv_buggy_getaddrinfo=no"
204 "ac_cv_file__dev_ptmx=no"
205 "ac_cv_file__dev_ptc=no")
207 ;; -fno-semantic-interposition reinstates some optimizations by gcc
208 ;; leading to around 15% speedup. This is the default starting from
210 "CFLAGS=-fno-semantic-interposition"
211 (string-append "LDFLAGS=-Wl,-rpath="
212 (assoc-ref %outputs "out") "/lib"
213 " -fno-semantic-interposition"))
214 ;; With no -j argument tests use all available cpus, so provide one.
217 (format #f "TESTOPTS=-j~d" (parallel-job-count))
218 ;; Exclude the following tests as they fail
219 ;; non-deterministically with "error: [Errno 104] Connection
220 ;; reset by peer." Python 3 seems unaffected. A potential fix,
221 ;; yet to be backported to Python 2, is available at:
222 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
223 " --exclude test_urllib2_localnet test_httplib"))
225 #:modules ((ice-9 ftw) (ice-9 match)
226 (guix build utils) (guix build gnu-build-system))
228 (modify-phases %standard-phases
230 'configure 'patch-lib-shells
232 ;; This variable is used in setup.py to enable cross compilation
233 ;; specific switches. As it is not set properly by configure
234 ;; script, set it manually.
235 ,@(if (%current-target-system)
236 '((setenv "_PYTHON_HOST_PLATFORM" ""))
238 ;; Filter for existing files, since some may not exist in all
239 ;; versions of python that are built with this recipe.
240 (substitute* (filter file-exists?
241 '("Lib/subprocess.py"
243 "Lib/distutils/tests/test_spawn.py"
244 "Lib/test/support/__init__.py"
245 "Lib/test/test_subprocess.py"))
246 (("/bin/sh") (which "sh")))))
248 `((add-before 'build 'patch-regen-for-hurd
249 (lambda* (#:key inputs #:allow-other-keys)
250 (let ((libc (assoc-ref inputs "libc")))
251 (substitute* "Lib/plat-generic/regen"
252 (("/usr/include/") (string-append libc "/include/")))))))
254 (add-before 'configure 'do-not-record-configure-flags
255 (lambda* (#:key configure-flags #:allow-other-keys)
256 ;; Remove configure flags from the installed '_sysconfigdata.py'
257 ;; and 'Makefile' so we don't end up keeping references to the
260 ;; Preserve at least '--with-system-ffi' since otherwise the
261 ;; thing tries to build libffi, fails, and we end up with a
262 ;; Python that lacks ctypes.
263 (substitute* "configure"
264 (("^CONFIG_ARGS=.*$")
265 (format #f "CONFIG_ARGS='~a'\n"
266 (if (member "--with-system-ffi" configure-flags)
269 (add-before 'check 'pre-check
271 ;; 'Lib/test/test_site.py' needs a valid $HOME
272 (setenv "HOME" (getcwd))))
273 (add-after 'unpack 'set-source-file-times-to-1980
274 ;; XXX One of the tests uses a ZIP library to pack up some of the
275 ;; source tree, and fails with "ZIP does not support timestamps
276 ;; before 1980". Work around this by setting the file times in the
277 ;; source tree to sometime in early 1980.
279 (let ((circa-1980 (* 10 366 24 60 60)))
280 (ftw "." (lambda (file stat flag)
281 (utime file circa-1980 circa-1980)
283 (add-after 'install 'remove-tests
284 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
285 ;; because these files are used by some libraries out there.
286 (lambda* (#:key outputs #:allow-other-keys)
287 (let ((out (assoc-ref outputs "out")))
288 (match (scandir (string-append out "/lib")
290 (string-prefix? "python" name)))
292 (let ((testdir (string-append out "/lib/" pythonX.Y
294 (with-directory-excursion testdir
295 (for-each delete-file-recursively
302 (string-prefix? "test_support."
304 (call-with-output-file "__init__.py" (const #t))))
305 (let ((libdir (string-append out "/lib/" pythonX.Y)))
308 (let ((dir (string-append libdir "/" directory)))
309 (when (file-exists? dir)
310 (delete-file-recursively dir))))
311 '("email/test" "ctypes/test" "unittest/test" "tkinter/test"
312 "sqlite3/test" "bsddb/test" "lib-tk/test" "json/tests"
313 "distutils/tests"))))))))
314 (add-after 'remove-tests 'move-tk-inter
315 (lambda* (#:key outputs #:allow-other-keys)
316 ;; When Tkinter support is built move it to a separate output so
317 ;; that the main output doesn't contain a reference to Tcl/Tk.
318 (let ((out (assoc-ref outputs "out"))
319 (tk (assoc-ref outputs "tk")))
321 (match (find-files out "tkinter.*\\.so")
323 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
324 ;; want it under TK/lib/pythonX.Y/site-packages.
325 (let* ((len (string-length out))
326 (target (string-append
329 (dirname (dirname tkinter.so))
332 (install-file tkinter.so target)
333 (delete-file tkinter.so))))))))
334 (add-after 'move-tk-inter 'move-idle
335 (lambda* (#:key outputs #:allow-other-keys)
336 ;; when idle is built, move it to a separate output to save some
338 (let ((out (assoc-ref outputs "out"))
339 (idle (assoc-ref outputs "idle")))
343 (let ((target (string-append idle "/bin/" (basename file))))
344 (install-file file (dirname target))
346 (find-files (string-append out "/bin") "^idle"))
347 (match (find-files out "^idlelib$" #:directories? #t)
349 (let* ((len (string-length out))
350 (target (string-append idle "/"
351 (string-drop idlelib len)
353 (mkdir-p (dirname target))
354 (rename-file idlelib target))))))))
355 (add-after 'move-idle 'rebuild-bytecode
356 (lambda* (#:key outputs #:allow-other-keys)
357 (let ((out (assoc-ref outputs "out")))
358 ;; Disable hash randomization to ensure the generated .pycs
360 (setenv "PYTHONHASHSEED" "0")
363 (for-each (lambda (opt)
364 (format #t "Compiling with optimization level: ~a\n"
365 (if (null? opt) "none" (car opt)))
367 `(,,(if (%current-target-system)
369 '(string-append out "/bin/python"))
373 ;; Don't build lib2to3, because it contains
377 ;; Python 2 has a single file extension (.pyo) for the
378 ;; chosen level of optimization, so it doesn't make
379 ;; sense to byte compile with more than one level.
380 (list '() '("-OO"))))
381 (map cdr outputs)))))
382 (add-after 'install 'install-sitecustomize.py
383 ,(customize-site version)))))
389 sqlite ; for sqlite extension
396 `(("pkg-config" ,pkg-config)
397 ("sitecustomize.py" ,(local-file (search-auxiliary-file
398 "python/sitecustomize.py")))
399 ;; When cross-compiling, a native version of Python itself is needed.
400 ,@(if (%current-target-system)
401 `(("python2" ,this-package)
405 (list (guix-pythonpath-search-path version)))
406 (home-page "https://www.python.org")
407 (synopsis "High-level, dynamically-typed programming language")
409 "Python is a remarkably powerful dynamic programming language that
410 is used in a wide variety of application domains. Some of its key
411 distinguishing features include: clear, readable syntax; strong
412 introspection capabilities; intuitive object orientation; natural
413 expression of procedural code; full modularity, supporting hierarchical
414 packages; exception-based error handling; and very high level dynamic
416 (properties '((cpe-name . "python")))
417 (license license:psfl)))
419 ;; Current 2.x version.
420 (define-public python-2 python-2.7)
422 (define-public python2-called-python
423 ;; Both 2.x and 3.x used to be called "python". In commit
424 ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the
425 ;; Python 2.x package to "python2".
426 (package/inherit python-2
428 (properties `((superseded . ,python-2)))))
430 (define-public python-3.9
437 (uri (string-append "https://www.python.org/ftp/python/"
438 version "/Python-" version ".tar.xz"))
439 (patches (search-patches
440 "python-3-arm-alignment.patch"
441 "python-3-deterministic-build-info.patch"
442 "python-3-fix-tests.patch"
443 "python-3-hurd-configure.patch"
444 "python-3-search-paths.patch"
445 "python-3-no-static-lib.patch"))
448 "09vd7g71i11iz5ydqghwc8kaxr0vgji94hhwwnj77h3kll28r0h6"))
449 (modules '((guix build utils)))
452 ;; Delete the bundled copy of libexpat.
453 (delete-file-recursively "Modules/expat")
454 (substitute* "Modules/Setup"
455 ;; Link Expat instead of embedding the bundled one.
456 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
457 ;; Delete windows binaries
458 (for-each delete-file
459 (find-files "Lib/distutils/command" "\\.exe$"))))))
461 (substitute-keyword-arguments (package-arguments python-2)
463 `(list (string-append
464 (format #f "TESTOPTS=-j~d" (parallel-job-count))
465 ;; test_mmap fails on low-memory systems
466 " --exclude test_mmap test_socket"
468 '(" test_posix" ;multiple errors
472 " test_tempfile" ;chflags: invalid argument:
473 ; tbv14c9t/dir0/dir0/dir0/test0.txt
474 " test_asyncio" ;runs over 10min
475 " test_os" ;stty: 'standard input':
476 ; Inappropriate ioctl for device
477 " test_openpty" ;No such file or directory
478 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
480 " test_compileall" ;multiple errors
481 " test_poll" ;list index out of range
482 " test_subprocess" ;runs over 10min
483 " test_asyncore" ;multiple errors
484 " test_threadsignals"
485 " test_eintr" ;Process return code is -14
486 " test_io" ;multiple errors
489 " test_threading" ;runs over 10min
491 " test_bidirectional_pty"
492 " test_create_unix_connection"
493 " test_unix_sock_client_ops"
494 " test_open_unix_connection"
495 " test_open_unix_connection_error"
496 " test_read_pty_output"
500 `(modify-phases ,phases
502 `((delete 'patch-regen-for-hurd)) ;regen was removed after 3.5.9
504 (add-after 'unpack 'remove-windows-binaries
506 ;; Delete .exe from embedded .whl (zip) files
509 (let ((dir "whl-content")
510 (circa-1980 (* 10 366 24 60 60)))
512 (with-directory-excursion dir
513 (let ((whl (string-append "../" whl)))
515 (for-each delete-file
516 (find-files "." "\\.exe$"))
518 ;; Reset timestamps to prevent them from ending
519 ;; up in the Zip archive.
520 (ftw "." (lambda (file stat flag)
521 (utime file circa-1980 circa-1980)
523 (apply invoke "zip" "-X" whl
524 (find-files "." #:directories? #t))))
525 (delete-file-recursively dir)))
526 (find-files "Lib/ensurepip" "\\.whl$"))))
527 (add-before 'check 'set-TZDIR
528 (lambda* (#:key inputs native-inputs #:allow-other-keys)
529 ;; test_email requires the Olson time zone database.
531 (string-append (assoc-ref
532 (or native-inputs inputs) "tzdata")
533 "/share/zoneinfo"))))
534 (replace 'rebuild-bytecode
535 (lambda* (#:key outputs #:allow-other-keys)
536 (let ((out (assoc-ref outputs "out")))
537 ;; Disable hash randomization to ensure the generated .pycs
539 (setenv "PYTHONHASHSEED" "0")
541 (for-each (lambda (output)
542 ;; XXX: Delete existing pycs generated by the build
543 ;; system beforehand because the -f argument does
544 ;; not necessarily overwrite all files, leading to
545 ;; indeterministic results.
546 (for-each (lambda (pyc)
548 (find-files output "\\.pyc$"))
551 `(,,(if (%current-target-system)
556 "-o" "0" "-o" "1" "-o" "2"
558 "--invalidation-mode=unchecked-hash"
559 ;; Don't build lib2to3, because it's
563 (map cdr outputs)))))
564 (replace 'install-sitecustomize.py
565 ,(customize-site version))))))
567 `(("tzdata" ,tzdata-for-tests)
569 ("zip" ,(@ (gnu packages compression) zip))
570 ,@(if (%current-target-system)
571 `(("python3" ,this-package))
573 ,@(package-native-inputs python-2)))
575 (list (guix-pythonpath-search-path version)
576 ;; Used to locate tzdata by the zoneinfo module introduced in
578 (search-path-specification
579 (variable "PYTHONTZPATH")
580 (files (list "share/zoneinfo")))))))
582 ;; Current 3.x version.
583 (define-public python-3 python-3.9)
585 ;; Current major version.
586 (define-public python python-3)
588 ;; Minimal variants of Python, mostly used to break the cycle between Tk and
589 ;; Python (Tk -> libxcb -> Python.)
591 (define-public python2-minimal
592 (package/inherit python-2
593 (name "python2-minimal")
596 ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which
597 ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus
598 ;; libffi. Expat is needed for XML support which is expected by a lot
599 ;; of libraries out there.
600 (inputs `(("expat" ,expat)
604 (define-public python-minimal
605 (package/inherit python
606 (name "python-minimal")
609 ;; Build fails due to missing ctypes without libffi.
610 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
611 ;; zlib is required by 'zipimport', used by pip. Expat is needed
612 ;; for XML support, which is generally expected to be available.
613 (inputs `(("expat" ,expat)
618 (define-public python-debug
619 (package/inherit python
620 (name "python-debug")
621 (outputs '("out" "debug"))
622 (build-system gnu-build-system)
624 (substitute-keyword-arguments (package-arguments python)
625 ((#:configure-flags flags '())
626 `(cons "--with-pydebug" ,flags))))
628 "High-level, dynamically-typed programming language (for debugging)")
630 "This variant of Python provides an interpreter built with
631 @code{--with-pydebug} to help develop and debug extensions. See
632 @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
633 for more information.")))
635 (define* (wrap-python3 python
637 (name (string-append (package-name python) "-wrapper")))
638 (package/inherit python
641 (build-system trivial-build-system)
643 (inputs `(("bash" ,bash)))
644 (propagated-inputs `(("python" ,python)))
646 `(#:modules ((guix build utils))
649 (use-modules (guix build utils))
650 (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
651 (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
655 (symlink (string-append python old)
656 (string-append bin "/" new)))
657 `("python3" ,"pydoc3" ,"pip3")
658 `("python" ,"pydoc" ,"pip"))
659 ;; python-config outputs search paths based upon its location,
660 ;; use a bash wrapper to avoid changing its outputs.
661 (let ((bash (string-append (assoc-ref %build-inputs "bash")
663 (old (string-append python "python3-config"))
664 (new (string-append bin "/python-config")))
665 (with-output-to-file new
667 (format #t "#!~a~%" bash)
668 (format #t "exec \"~a\" \"$@\"~%" old)
669 (chmod new #o755))))))))
670 (synopsis "Wrapper for the Python 3 commands")
672 "This package provides wrappers for the commands of Python@tie{}3.x such
673 that they can be invoked under their usual name---e.g., @command{python}
674 instead of @command{python3} or @command{pip} instead of @command{pip3}.
675 To function properly, this package should not be installed together with the
676 @command{python} package.")))
678 (define-public python-wrapper (wrap-python3 python))
679 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
681 (define-public micropython
688 (uri (string-append "https://github.com/micropython/micropython/"
689 "releases/download/v" version
690 "/micropython-" version ".tar.xz"))
692 (base32 "04sfrfcljhfps340l4wh5ffwkhw1ydraday8nv92nv7gmnrj1l2j"))
693 (modules '((guix build utils)))
696 (delete-file-recursively "ports/cc3200/FreeRTOS")
697 (with-directory-excursion "lib"
698 ;; TODO: Unbundle axtls and berkley-db-1.xx
699 (for-each delete-file-recursively
700 '("libffi" "lwip" "stm32lib" "nrfx")))
702 (build-system gnu-build-system)
705 (modify-phases %standard-phases
706 (add-before 'build 'build-mpy-cross
707 (lambda* (#:key make-flags #:allow-other-keys)
708 (with-directory-excursion "mpy-cross"
709 (apply invoke "make" make-flags))))
710 (add-after 'build-mpy-cross 'prepare-build
713 ;; see: https://github.com/micropython/micropython/pull/4246
714 (substitute* "Makefile"
715 (("-Os") "-Os -ffp-contract=off"))
717 (replace 'install-license-files
718 ;; We don't build in the root directory so the file isn't found.
719 (lambda* (#:key outputs #:allow-other-keys)
720 (let* ((out (assoc-ref outputs "out"))
721 (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
722 (install-file "../../LICENSE" dest))
724 (delete 'configure)) ; no configure
725 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
727 #:test-target "test"))
729 `(("pkg-config" ,pkg-config)
730 ("python" ,python-wrapper)))
733 (home-page "https://micropython.org/")
734 (synopsis "Python implementation for microcontrollers and constrained systems")
735 (description "MicroPython is a lean and efficient implementation of the
736 Python 3 programming language that includes a small subset of the Python
737 standard library and is optimised to run on microcontrollers and in constrained
738 environments. MicroPython is packed full of advanced features such as an
739 interactive prompt, arbitrary precision integers, closures, list comprehension,
740 generators, exception handling and more. Still it is compact enough to fit and
741 run within just 256k of code space and 16k of RAM. MicroPython aims to be as
742 compatible with normal Python as possible to allow you to transfer code with
743 ease from the desktop to a microcontroller or embedded system.")
744 (license license:expat)))
752 (uri (string-append "https://downloads.python.org/pypy/"
753 "pypy3.7-v" version "-src.tar.bz2"))
756 "18lrdmpcczlbk3cfarkgwqdmilrybz56i1dafk8dkjlyk90gw86r"))))
757 (build-system gnu-build-system)
759 `(("python-2" ,python-2)
760 ("pkg-config" ,pkg-config)
761 ("tar" ,tar) ; Required for package.py
762 ("python2-pycparser" ,python2-pycparser)
763 ("python2-hypothesis" ,python2-hypothesis)
764 ("nss-certs" ,nss-certs) ; For ssl tests
780 `(#:tests? #f ;FIXME: 43 out of 364 tests are failing
781 #:modules ((ice-9 ftw) (ice-9 match)
782 (guix build utils) (guix build gnu-build-system))
783 #:disallowed-references (,nss-certs)
784 #:phases (modify-phases %standard-phases
786 (add-after 'unpack 'patch-source
787 (lambda* (#:key inputs outputs #:allow-other-keys)
788 (substitute* '("rpython/rlib/clibffi.py")
789 ;; find_library does not work for libc
790 (("ctypes\\.util\\.find_library\\('c'\\)") "'libc.so'"))
791 (substitute* '("lib_pypy/cffi/_pycparser/ply/cpp.py")
792 ;; Make reproducible (XXX: unused?)
793 (("time\\.localtime\\(\\)") "time.gmtime(0)"))
794 (substitute* '("pypy/module/sys/version.py")
796 (("t\\.gmtime\\(\\)") "t.gmtime(0)"))
797 (substitute* '("lib_pypy/_tkinter/tklib_build.py")
798 ;; Link to versioned libtcl and libtk
799 (("linklibs = \\['tcl', 'tk'\\]")
800 "linklibs = ['tcl8.6', 'tk8.6']")
801 (("incdirs = \\[\\]")
802 (string-append "incdirs = ['"
803 (assoc-ref inputs "tcl")
805 (assoc-ref inputs "tk")
807 (substitute* '("lib_pypy/_curses_build.py")
809 (("/usr/local") (assoc-ref inputs "ncurses")))
810 (substitute* '("lib_pypy/_dbm.py")
811 ;; Use gdbm compat library, so we don’t need to pull
813 (("ctypes.util.find_library\\('db'\\)")
814 (format #f "'~a/lib/libgdbm_compat.so'"
815 (assoc-ref inputs "gdbm"))))
816 (substitute* '("lib_pypy/_sqlite3_build.py")
817 ;; Always use search paths
818 (("sys\\.platform\\.startswith\\('freebsd'\\)") "True")
820 (("/usr/local") (assoc-ref inputs "sqlite"))
821 (("libname = 'sqlite3'")
822 (string-append "libname = '"
823 (assoc-ref inputs "sqlite")
824 "/lib/libsqlite3.so.0'")))
825 (substitute* '("lib-python/3/subprocess.py")
828 (search-input-file inputs "/bin/sh")))
829 (substitute* '("lib-python/3/distutils/unixccompiler.py")
830 ;; gcc-toolchain does not provide symlink cc -> gcc
831 (("\"cc\"") "\"gcc\""))))
833 'unpack 'set-source-file-times-to-1980
834 ;; copied from python package, required by zip testcase
836 (let ((circa-1980 (* 10 366 24 60 60)))
837 (ftw "." (lambda (file stat flag)
838 (utime file circa-1980 circa-1980)
841 (lambda* (#:key inputs #:allow-other-keys)
842 (with-directory-excursion "pypy/goal"
843 ;; Build with jit optimization.
845 "../../rpython/bin/rpython"
846 (string-append "--make-jobs="
847 (number->string (parallel-job-count)))
849 "targetpypystandalone"
850 "--allworkingmodules"))
851 ;; Build c modules and package everything, so tests work.
852 (with-directory-excursion "pypy/tool/release"
853 (invoke "python2" "package.py"
854 "--archive-name" "pypy-dist"
855 "--builddir" (getcwd)))))
857 (lambda* (#:key tests? #:allow-other-keys)
860 (setenv "HOME" "/tmp") ; test_with_pip tries to
861 ; access ~/.cache/pip
862 ;; Run library tests only (no interpreter unit
863 ;; tests). This is what Gentoo does.
867 "--pypy=pypy/tool/release/pypy-dist/bin/pypy3"
869 (format #t "test suite not run~%"))))
871 (lambda* (#:key inputs outputs #:allow-other-keys)
872 (let* ((out (assoc-ref outputs "out"))
873 (bin-pypy3 (string-append out "/bin/pypy3"))
874 (shebang-match-python "#!.+/bin/python")
875 (shebang-pypy3 (string-append "#!" bin-pypy3))
876 (dist-dir "pypy/tool/release/pypy-dist"))
877 (with-directory-excursion dist-dir
881 (delete-file-recursively (string-append
891 ;; Patch shebang referencing python2
892 (substitute* '("lib-python/3/cgi.py"
893 "lib-python/3/encodings/rot_13.py")
894 ((shebang-match-python) shebang-pypy3))
895 (with-fluids ((%default-port-encoding "ISO-8859-1"))
896 (substitute* '("lib_pypy/_md5.py"
898 ((shebang-match-python) shebang-pypy3))))
899 (copy-recursively dist-dir out)))))))
900 (home-page "https://www.pypy.org/")
901 (synopsis "Python implementation with just-in-time compilation")
902 (description "PyPy is a faster, alternative implementation of the Python
903 programming language employing a just-in-time compiler. It supports most
904 Python code natively, including C extensions.")
905 (license (list license:expat ; pypy itself; _pytest/
906 license:psfl ; python standard library in lib-python/
907 license:asl2.0 ; dotviewer/font/ and some of lib-python/
908 license:gpl3+ ; ./rpython/rlib/rvmprof/src/shared/libbacktrace/dwarf2.*
909 license:bsd-3 ; lib_pypy/cffi/_pycparser/ply/
910 (license:non-copyleft
911 "http://www.unicode.org/copyright.html")))))