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