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