gnu: Add cl-ana.statistical-learning.
[jackhill/guix/guix.git] / gnu / packages / python.scm
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 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 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 ng0 <ng0@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 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, 2017, 2018 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 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 ;;;
62 ;;; This file is part of GNU Guix.
63 ;;;
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.
68 ;;;
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.
73 ;;;
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/>.
76
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 compression)
83 #:use-module (gnu packages dbm)
84 #:use-module (gnu packages libffi)
85 #:use-module (gnu packages pkg-config)
86 #:use-module (gnu packages readline)
87 #:use-module (gnu packages sqlite)
88 #:use-module (gnu packages tcl)
89 #:use-module (gnu packages tls)
90 #:use-module (gnu packages xml)
91 #:use-module (guix packages)
92 #:use-module (guix download)
93 #:use-module (guix utils)
94 #:use-module (guix build-system gnu)
95 #:use-module (guix build-system trivial))
96
97 (define-public python-2.7
98 (package
99 (name "python2")
100 (version "2.7.16")
101 (source
102 (origin
103 (method url-fetch)
104 (uri (string-append "https://www.python.org/ftp/python/"
105 version "/Python-" version ".tar.xz"))
106 (sha256
107 (base32
108 "1mqfcqp5y8r0bfyr7ppl74n0lig45p9mc4b8adlcpvj74rhfy8pj"))
109 (patches (search-patches "python-2.7-search-paths.patch"
110 "python-2-deterministic-build-info.patch"
111 "python-2.7-site-prefixes.patch"
112 "python-2.7-source-date-epoch.patch"
113 "python-2.7-adjust-tests.patch"))
114 (modules '((guix build utils)))
115 (snippet
116 '(begin
117 ;; Ensure the bundled copies of these libraries are not used.
118 (for-each delete-file-recursively
119 '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
120
121 (substitute* "Modules/Setup.dist"
122 ;; Link Expat instead of embedding the bundled one.
123 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
124
125 ;; Suboptimal to delete failing tests here, but if we delete them in
126 ;; the arguments then we need to make sure to strip out that phase
127 ;; when it gets inherited by python and python-minimal.
128 (for-each delete-file
129 '("Lib/test/test_compileall.py"
130 "Lib/test/test_ctypes.py" ; fails on mips64el
131 "Lib/test/test_distutils.py"
132 "Lib/test/test_import.py"
133 "Lib/test/test_shutil.py"
134 "Lib/test/test_socket.py"
135 "Lib/test/test_subprocess.py"))
136 #t))))
137 (outputs '("out"
138 "tk")) ;tkinter; adds 50 MiB to the closure
139 (build-system gnu-build-system)
140 (arguments
141 `(#:test-target "test"
142 #:configure-flags
143 (list "--enable-shared" ;allow embedding
144 "--with-system-expat" ;for XML support
145 "--with-system-ffi" ;build ctypes
146 "--with-ensurepip=install" ;install pip and setuptools
147 "--enable-unicode=ucs4"
148
149 ;; Prevent the installed _sysconfigdata.py from retaining a reference
150 ;; to coreutils.
151 "INSTALL=install -c"
152 "MKDIR_P=mkdir -p"
153
154 (string-append "LDFLAGS=-Wl,-rpath="
155 (assoc-ref %outputs "out") "/lib"))
156 ;; With no -j argument tests use all available cpus, so provide one.
157 #:make-flags
158 (list (string-append
159 (format #f "TESTOPTS=-j~d" (parallel-job-count))
160 ;; Exclude the following tests as they fail
161 ;; non-deterministically with "error: [Errno 104] Connection
162 ;; reset by peer." Python 3 seems unaffected. A potential fix,
163 ;; yet to be backported to Python 2, is available at:
164 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
165 " --exclude test_urllib2_localnet test_httplib"))
166
167 #:modules ((ice-9 ftw) (ice-9 match)
168 (guix build utils) (guix build gnu-build-system))
169 #:phases
170 (modify-phases %standard-phases
171 (add-before
172 'configure 'patch-lib-shells
173 (lambda _
174 ;; Filter for existing files, since some may not exist in all
175 ;; versions of python that are built with this recipe.
176 (substitute* (filter file-exists?
177 '("Lib/subprocess.py"
178 "Lib/popen2.py"
179 "Lib/distutils/tests/test_spawn.py"
180 "Lib/test/support/__init__.py"
181 "Lib/test/test_subprocess.py"))
182 (("/bin/sh") (which "sh")))
183 #t))
184 (add-before 'configure 'do-not-record-configure-flags
185 (lambda* (#:key configure-flags #:allow-other-keys)
186 ;; Remove configure flags from the installed '_sysconfigdata.py'
187 ;; and 'Makefile' so we don't end up keeping references to the
188 ;; build tools.
189 ;;
190 ;; Preserve at least '--with-system-ffi' since otherwise the
191 ;; thing tries to build libffi, fails, and we end up with a
192 ;; Python that lacks ctypes.
193 (substitute* "configure"
194 (("^CONFIG_ARGS=.*$")
195 (format #f "CONFIG_ARGS='~a'\n"
196 (if (member "--with-system-ffi" configure-flags)
197 "--with-system-ffi"
198 ""))))
199 #t))
200 (add-before
201 'check 'pre-check
202 (lambda _
203 ;; 'Lib/test/test_site.py' needs a valid $HOME
204 (setenv "HOME" (getcwd))
205 #t))
206 (add-after
207 'unpack 'set-source-file-times-to-1980
208 ;; XXX One of the tests uses a ZIP library to pack up some of the
209 ;; source tree, and fails with "ZIP does not support timestamps
210 ;; before 1980". Work around this by setting the file times in the
211 ;; source tree to sometime in early 1980.
212 (lambda _
213 (let ((circa-1980 (* 10 366 24 60 60)))
214 (ftw "." (lambda (file stat flag)
215 (utime file circa-1980 circa-1980)
216 #t))
217 #t)))
218 (add-after 'install 'remove-tests
219 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
220 ;; because these files are used by some libraries out there.
221 (lambda* (#:key outputs #:allow-other-keys)
222 (let ((out (assoc-ref outputs "out")))
223 (match (scandir (string-append out "/lib")
224 (lambda (name)
225 (string-prefix? "python" name)))
226 ((pythonX.Y)
227 (let ((testdir (string-append out "/lib/" pythonX.Y
228 "/test")))
229 (with-directory-excursion testdir
230 (for-each delete-file-recursively
231 (scandir testdir
232 (match-lambda
233 ((or "." "..") #f)
234 ("support" #f)
235 (file
236 (not
237 (string-prefix? "test_support."
238 file))))))
239 (call-with-output-file "__init__.py" (const #t))
240 #t)))))))
241 (add-after 'remove-tests 'rebuild-bytecode
242 (lambda* (#:key outputs #:allow-other-keys)
243 (let ((out (assoc-ref outputs "out")))
244 ;; Disable hash randomization to ensure the generated .pycs
245 ;; are reproducible.
246 (setenv "PYTHONHASHSEED" "0")
247 (for-each
248 (lambda (opt)
249 (format #t "Compiling with optimization level: ~a\n"
250 (if (null? opt) "none" (car opt)))
251 (for-each (lambda (file)
252 (apply invoke
253 `(,(string-append out "/bin/python")
254 ,@opt
255 "-m" "compileall"
256 "-f" ; force rebuild
257 ;; Don't build lib2to3, because it contains Python 3 code.
258 "-x" "lib2to3/.*"
259 ,file)))
260 (find-files out "\\.py$")))
261 (list '() '("-O") '("-OO")))
262 #t)))
263 (add-after 'install 'move-tk-inter
264 (lambda* (#:key outputs #:allow-other-keys)
265 ;; When Tkinter support is built move it to a separate output so
266 ;; that the main output doesn't contain a reference to Tcl/Tk.
267 (let ((out (assoc-ref outputs "out"))
268 (tk (assoc-ref outputs "tk")))
269 (when tk
270 (match (find-files out "tkinter.*\\.so")
271 ((tkinter.so)
272 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
273 ;; want it under TK/lib/pythonX.Y/site-packages.
274 (let* ((len (string-length out))
275 (target (string-append
276 tk "/"
277 (string-drop
278 (dirname (dirname tkinter.so))
279 len)
280 "/site-packages")))
281 (install-file tkinter.so target)
282 (delete-file tkinter.so)))))
283 #t))))))
284 (inputs
285 `(("bzip2" ,bzip2)
286 ("expat" ,expat)
287 ("gdbm" ,gdbm)
288 ("libffi" ,libffi) ; for ctypes
289 ("sqlite" ,sqlite) ; for sqlite extension
290 ("openssl" ,openssl)
291 ("readline" ,readline)
292 ("zlib" ,zlib)
293 ("tcl" ,tcl)
294 ("tk" ,tk))) ; for tkinter
295 (native-inputs
296 `(("pkg-config" ,pkg-config)))
297 (native-search-paths
298 (list (search-path-specification
299 (variable "PYTHONPATH")
300 (files '("lib/python2.7/site-packages")))))
301 (home-page "https://www.python.org")
302 (synopsis "High-level, dynamically-typed programming language")
303 (description
304 "Python is a remarkably powerful dynamic programming language that
305 is used in a wide variety of application domains. Some of its key
306 distinguishing features include: clear, readable syntax; strong
307 introspection capabilities; intuitive object orientation; natural
308 expression of procedural code; full modularity, supporting hierarchical
309 packages; exception-based error handling; and very high level dynamic
310 data types.")
311 (properties '((cpe-name . "python")))
312 (license license:psfl)))
313
314 ;; Current 2.x version.
315 (define-public python-2 python-2.7)
316
317 (define-public python2-called-python
318 ;; Both 2.x and 3.x used to be called "python". In commit
319 ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the
320 ;; Python 2.x package to "python2".
321 (package
322 (inherit python-2)
323 (name "python")
324 (properties `((superseded . ,python-2)))))
325
326 (define-public python-3.7
327 (package (inherit python-2)
328 (name "python")
329 (version "3.7.4")
330 (source (origin
331 (method url-fetch)
332 (uri (string-append "https://www.python.org/ftp/python/"
333 version "/Python-" version ".tar.xz"))
334 (patches (search-patches
335 "python-3-fix-tests.patch"
336 "python-3-deterministic-build-info.patch"
337 "python-3-search-paths.patch"))
338 (sha256
339 (base32
340 "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv"))
341 (modules '((guix build utils)))
342 (snippet
343 '(begin
344 ;; Delete the bundled copy of libexpat.
345 (delete-file-recursively "Modules/expat")
346 (substitute* "Modules/Setup.dist"
347 ;; Link Expat instead of embedding the bundled one.
348 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
349 #t))))
350 (arguments
351 (substitute-keyword-arguments (package-arguments python-2)
352 ((#:make-flags _)
353 `(list (string-append
354 (format #f "TESTOPTS=-j~d" (parallel-job-count))
355 ;; test_mmap fails on low-memory systems.
356 " --exclude test_mmap"
357 ;; test_socket may hang and eventually run out of memory
358 ;; on some systems: <https://bugs.python.org/issue34587>.
359 " test_socket"
360 ;; XXX: test_ctypes fails on some platforms due to a problem in
361 ;; libffi 3.2.1: <https://bugs.python.org/issue23249>.
362 ,@(if (string-prefix? "aarch64" (%current-system))
363 '(" test_ctypes")
364 '()))))
365 ((#:phases phases)
366 `(modify-phases ,phases
367 (add-before 'check 'set-TZDIR
368 (lambda* (#:key inputs #:allow-other-keys)
369 ;; test_email requires the Olson time zone database.
370 (setenv "TZDIR"
371 (string-append (assoc-ref inputs "tzdata")
372 "/share/zoneinfo"))
373 #t))
374 ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it
375 ;; again afterwards. See <https://bugs.python.org/issue34022>.
376 (add-before 'check 'unset-SOURCE_DATE_EPOCH
377 (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t))
378 (add-after 'check 'reset-SOURCE_DATE_EPOCH
379 (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t))
380 (replace 'rebuild-bytecode
381 (lambda* (#:key outputs #:allow-other-keys)
382 (let ((out (assoc-ref outputs "out")))
383 ;; Disable hash randomization to ensure the generated .pycs
384 ;; are reproducible.
385 (setenv "PYTHONHASHSEED" "0")
386 (for-each
387 (lambda (opt)
388 (format #t "Compiling with optimization level: ~a\n"
389 (if (null? opt) "none" (car opt)))
390 (for-each (lambda (file)
391 (apply invoke
392 `(,(string-append out "/bin/python3")
393 ,@opt
394 "-m" "compileall"
395 "-f" ; force rebuild
396 ;; Don't build lib2to3, because it's Python 2 code.
397 "-x" "lib2to3/.*"
398 ,file)))
399 (find-files out "\\.py$")))
400 (list '() '("-O") '("-OO")))
401 #t)))))))
402 (native-inputs
403 `(("tzdata" ,tzdata-for-tests)
404 ,@(package-native-inputs python-2)))
405 (native-search-paths
406 (list (search-path-specification
407 (variable "PYTHONPATH")
408 (files (list (string-append "lib/python"
409 (version-major+minor version)
410 "/site-packages"))))))))
411
412 (define-public python-3.8
413 (package
414 (inherit python-3.7)
415 (name "python-next")
416 (version "3.8.0")
417 (source
418 (origin
419 (inherit (package-source python-3.7))
420 (uri (string-append "https://www.python.org/ftp/python/"
421 version "/Python-" version ".tar.xz"))
422 (sha256 (base32 "110d0did9rxn7rg85kf2fwli5hqq44xv2d8bi7d92m7v2d728mmk"))
423 (patches (search-patches
424 "python-3.8-search-paths.patch"
425 "python-3-fix-tests.patch"
426 "python-3.8-fix-tests.patch"
427 "python-3-deterministic-build-info.patch"))
428 (snippet
429 '(begin
430 ;; Delete the bundled copy of libexpat.
431 (delete-file-recursively "Modules/expat")
432 (substitute* "Modules/Setup"
433 ;; Link Expat instead of embedding the bundled one.
434 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
435 #t))))))
436
437 ;; Current 3.x version.
438 (define-public python-3 python-3.7)
439
440 ;; Current major version.
441 (define-public python python-3)
442
443 ;; Minimal variants of Python, mostly used to break the cycle between Tk and
444 ;; Python (Tk -> libxcb -> Python.)
445
446 (define-public python2-minimal
447 (package/inherit python-2
448 (name "python2-minimal")
449 (outputs '("out"))
450
451 ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which
452 ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus
453 ;; libffi. Expat is needed for XML support which is expected by a lot
454 ;; of libraries out there.
455 (inputs `(("expat" ,expat)
456 ("libffi" ,libffi)
457 ("zlib" ,zlib)))))
458
459 (define-public python-minimal
460 (package/inherit python
461 (name "python-minimal")
462 (outputs '("out"))
463
464 ;; Build fails due to missing ctypes without libffi.
465 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
466 ;; zlib is required by 'zipimport', used by pip. Expat is needed
467 ;; for XML support, which is generally expected to be available.
468 (inputs `(("expat" ,expat)
469 ("libffi" ,libffi)
470 ("openssl" ,openssl)
471 ("zlib" ,zlib)))))
472
473 (define-public python-debug
474 (package/inherit python
475 (name "python-debug")
476 (outputs '("out" "debug"))
477 (build-system gnu-build-system)
478 (arguments
479 (substitute-keyword-arguments (package-arguments python)
480 ((#:configure-flags flags '())
481 `(cons "--with-pydebug" ,flags))))
482 (synopsis
483 "High-level, dynamically-typed programming language (for debugging)")
484 (description
485 "This variant of Python provides an interpreter built with
486 @code{--with-pydebug} to help develop and debug extensions. See
487 @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
488 for more information.")))
489
490 (define* (wrap-python3 python
491 #:optional
492 (name (string-append (package-name python) "-wrapper")))
493 (package/inherit python
494 (name name)
495 (source #f)
496 (build-system trivial-build-system)
497 (outputs '("out"))
498 (inputs `(("bash" ,bash)))
499 (propagated-inputs `(("python" ,python)))
500 (arguments
501 `(#:modules ((guix build utils))
502 #:builder
503 (begin
504 (use-modules (guix build utils))
505 (let ((bin (string-append (assoc-ref %outputs "out") "/bin"))
506 (python (string-append (assoc-ref %build-inputs "python") "/bin/")))
507 (mkdir-p bin)
508 (for-each
509 (lambda (old new)
510 (symlink (string-append python old)
511 (string-append bin "/" new)))
512 `("python3" ,"pydoc3" ,"idle3" ,"pip3")
513 `("python" ,"pydoc" ,"idle" ,"pip"))
514 ;; python-config outputs search paths based upon its location,
515 ;; use a bash wrapper to avoid changing its outputs.
516 (let ((bash (string-append (assoc-ref %build-inputs "bash")
517 "/bin/bash"))
518 (old (string-append python "python3-config"))
519 (new (string-append bin "/python-config")))
520 (with-output-to-file new
521 (lambda ()
522 (format #t "#!~a~%" bash)
523 (format #t "exec \"~a\" \"$@\"~%" old)
524 (chmod new #o755)
525 #t)))))))
526 (synopsis "Wrapper for the Python 3 commands")
527 (description
528 "This package provides wrappers for the commands of Python@tie{}3.x such
529 that they can be invoked under their usual name---e.g., @command{python}
530 instead of @command{python3}.")))
531
532 (define-public python-wrapper (wrap-python3 python))
533 (define-public python-minimal-wrapper (wrap-python3 python-minimal))
534
535 (define-public micropython
536 (package
537 (name "micropython")
538 (version "1.11")
539 (source
540 (origin
541 (method url-fetch)
542 (uri (string-append "https://github.com/micropython/micropython/"
543 "releases/download/v" version
544 "/micropython-" version ".tar.gz"))
545 (sha256
546 (base32
547 "0px3xhw16rl0l7qifq7jw1gq92wzlnhd17dmszv9m2c3wbzs9p9f"))
548 (modules '((guix build utils)))
549 (snippet
550 '(begin
551 (delete-file-recursively "ports/cc3200/FreeRTOS")
552 (with-directory-excursion "lib"
553 ;; TODO: Unbundle axtls and berkley-db-1.xx
554 (for-each delete-file-recursively
555 '("libffi" "lwip" "stm32lib" "nrfx")))
556 #t))))
557 (build-system gnu-build-system)
558 (arguments
559 `(#:phases
560 (modify-phases %standard-phases
561 (add-before 'build 'prepare-build
562 (lambda _
563 (chdir "ports/unix")
564 ;; see: https://github.com/micropython/micropython/pull/4246
565 (substitute* "Makefile"
566 (("-Os") "-Os -ffp-contract=off"))
567 #t))
568 (replace 'install-license-files
569 ;; We don't build in the root directory so the file isn't found.
570 (lambda* (#:key outputs #:allow-other-keys)
571 (let* ((out (assoc-ref outputs "out"))
572 (dest (string-append out "/share/doc/" ,name "-" ,version "/")))
573 (install-file "../../LICENSE" dest))
574 #t))
575 (delete 'configure)) ; no configure
576 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
577 "V=1")
578 #:test-target "test"))
579 (native-inputs
580 `(("pkg-config" ,pkg-config)
581 ("python" ,python-wrapper)))
582 (inputs
583 `(("libffi" ,libffi)))
584 (home-page "https://micropython.org/")
585 (synopsis "Python implementation for microcontrollers and constrained systems")
586 (description "MicroPython is a lean and efficient implementation of the
587 Python 3 programming language that includes a small subset of the Python
588 standard library and is optimised to run on microcontrollers and in constrained
589 environments. MicroPython is packed full of advanced features such as an
590 interactive prompt, arbitrary precision integers, closures, list comprehension,
591 generators, exception handling and more. Still it is compact enough to fit and
592 run within just 256k of code space and 16k of RAM. MicroPython aims to be as
593 compatible with normal Python as possible to allow you to transfer code with
594 ease from the desktop to a microcontroller or embedded system.")
595 (license license:expat)))