gnu: deutex: Update to 5.2.1.
[jackhill/guix/guix.git] / gnu / packages / python.scm
CommitLineData
a01b6da7
NK
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
a5e3d59b 3;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
8e451885 4;;; Copyright © 2013, 2014, 2015, 2016 Andreas Enge <andreas@enge.fr>
e99f4211 5;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
32922190 6;;; Copyright © 2014, 2017, 2019 Eric Bavier <bavier@member.fsf.org>
da6ce3f1 7;;; Copyright © 2014, 2015 Federico Beffa <beffa@fbengineering.ch>
e99f4211 8;;; Copyright © 2015 Omar Radwan <toxemicsquire4@gmail.com>
d95a56c6 9;;; Copyright © 2015 Pierre-Antoine Rault <par@rigelk.eu>
9fb5771a 10;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
0bdc1671 11;;; Copyright © 2015, 2016 Christopher Allan Webber <cwebber@dustycloud.org>
345f0611 12;;; Copyright © 2015 Eric Dvorsak <eric@dvorsak.fr>
2b2f2fc1 13;;; Copyright © 2015, 2016 David Thompson <davet@gnu.org>
7637de23 14;;; Copyright © 2015, 2016, 2017 Leo Famulari <leo@famulari.name>
04fb4516 15;;; Copyright © 2015, 2017 Ben Woodcroft <donttrustben@gmail.com>
b9893908 16;;; Copyright © 2015, 2016 Erik Edrosa <erik.edrosa@gmail.com>
46930b7e 17;;; Copyright © 2015, 2016, 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
b89e3c77 18;;; Copyright © 2015, 2017 Kyle Meyer <kyle@kyleam.com>
daeeea71 19;;; Copyright © 2015, 2016 Chris Marusich <cmmarusich@gmail.com>
b31fbea5 20;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
88bb4197 21;;; Copyright © 2016 Lukas Gradl <lgradl@openmailbox.org>
34581f68 22;;; Copyright © 2016, 2018 Hartmut Goebel <h.goebel@crazy-compilers.com>
0de78c95 23;;; Copyright © 2016 Daniel Pimentel <d4n1@d4n1.org>
9250b0f3 24;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
bb3b4b4e 25;;; Copyright © 2016, 2017 Troy Sankey <sankeytms@gmail.com>
47956fa0 26;;; Copyright © 2016, 2017 ng0 <ng0@n0.is>
6eb7af2a 27;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
3f641af0 28;;; Copyright © 2016 David Craven <david@craven.ch>
d1659c0f 29;;; Copyright © 2016, 2017, 2018, 2019 Marius Bakke <mbakke@fastmail.com>
ca0e62bf 30;;; Copyright © 2016, 2017 Stefan Reichör <stefan@xsteve.at>
b04a52a6 31;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
e65acb31 32;;; Copyright © 2016, 2017 Alex Vong <alexvong1995@gmail.com>
fbec83b8 33;;; Copyright © 2016, 2017, 2018 Arun Isaac <arunisaac@systemreboot.net>
ff349415 34;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
9e8401a5 35;;; Copyright © 2016, 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr>
ec074213 36;;; Copyright © 2016, 2017 Thomas Danckaert <post@thomasdanckaert.be>
916aafa4 37;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
1a917fc9 38;;; Copyright © 2017 Frederick M. Muriithi <fredmanglis@gmail.com>
09b9cf73 39;;; Copyright © 2017, 2018 Adriano Peluso <catonano@gmail.com>
16fe516e 40;;; Copyright © 2017 Ben Sturmfels <ben@sturm.com.au>
b5a9f49b 41;;; Copyright © 2017, 2018 Mathieu Othacehe <m.othacehe@gmail.com>
3015d455 42;;; Copyright © 2017 José Miguel Sánchez García <jmi2k@openmailbox.org>
fa3f5f47 43;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
44e4a621 44;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net>
f817b4d9 45;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
3fee0039 46;;; Copyright © 2017 Muriithi Frederick Muriuki <fredmanglis@gmail.com>
dcfa0acd 47;;; Copyright © 2017 Brendan Tildesley <mail@brendan.scot>
956ba99c 48;;; Copyright © 2018 Ethan R. Jones <ethanrjones97@gmail.com
6055e88c 49;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
385e8614 50;;; Copyright © 2018 Vijayalakshmi Vedantham <vijimay12@gmail.com>
95f3b626 51;;; Copyright © 2018 Mathieu Lirzin <mthl@gnu.org>
c2b2f0c8 52;;; Copyright © 2018 Adam Massmann <massmannak@gmail.com>
15ed90b9 53;;; Copyright © 2016, 2018 Tomáš Čech <sleep_walker@gnu.org>
bbc8c36f 54;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
c0888cef 55;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
0dc57238 56;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
e337061b 57;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
16d21251 58;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
9f23f6bc 59;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
af6a9fc2 60;;; Copyright © 2019 Tanguy Le Carrour <tanguy@bioneland.org>
c2b2f0c8 61;;;
a01b6da7
NK
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
1ffa7090 77(define-module (gnu packages python)
3f641af0 78 #:use-module ((guix licenses) #:prefix license:)
3fdc99da 79 #:use-module (gnu packages)
680bc34d 80 #:use-module (gnu packages base)
3969ca54 81 #:use-module (gnu packages bash)
1ffa7090 82 #:use-module (gnu packages compression)
255d1bbe 83 #:use-module (gnu packages dbm)
b10ab723 84 #:use-module (gnu packages libffi)
b10ab723 85 #:use-module (gnu packages pkg-config)
4ed20663 86 #:use-module (gnu packages readline)
cd0322a3 87 #:use-module (gnu packages sqlite)
afa181ff 88 #:use-module (gnu packages tcl)
44d10b1f 89 #:use-module (gnu packages tls)
d1659c0f 90 #:use-module (gnu packages xml)
a01b6da7
NK
91 #:use-module (guix packages)
92 #:use-module (guix download)
11bb85a1 93 #:use-module (guix utils)
acc26ff1 94 #:use-module (guix build-system gnu)
44d10b1f 95 #:use-module (guix build-system trivial))
a01b6da7 96
45848023 97(define-public python-2.7
a01b6da7 98 (package
a7714d42 99 (name "python2")
ed709ee9 100 (version "2.7.16")
a01b6da7
NK
101 (source
102 (origin
103 (method url-fetch)
9b43a0ff 104 (uri (string-append "https://www.python.org/ftp/python/"
a01b6da7
NK
105 version "/Python-" version ".tar.xz"))
106 (sha256
107 (base32
ed709ee9 108 "1mqfcqp5y8r0bfyr7ppl74n0lig45p9mc4b8adlcpvj74rhfy8pj"))
c3052d6b
ML
109 (patches (search-patches "python-2.7-search-paths.patch"
110 "python-2-deterministic-build-info.patch"
15e57f57 111 "python-2.7-site-prefixes.patch"
dc5cec21 112 "python-2.7-source-date-epoch.patch"
ed709ee9 113 "python-2.7-adjust-tests.patch"))
10a42aa2 114 (modules '((guix build utils)))
10a42aa2
EF
115 (snippet
116 '(begin
d1659c0f
MB
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.
10a42aa2
EF
128 (for-each delete-file
129 '("Lib/test/test_compileall.py"
f0499100 130 "Lib/test/test_ctypes.py" ; fails on mips64el
10a42aa2
EF
131 "Lib/test/test_distutils.py"
132 "Lib/test/test_import.py"
133 "Lib/test/test_shutil.py"
134 "Lib/test/test_socket.py"
1bb163b0 135 "Lib/test/test_subprocess.py"))
10a42aa2 136 #t))))
02f0c3b2
LC
137 (outputs '("out"
138 "tk")) ;tkinter; adds 50 MiB to the closure
a01b6da7 139 (build-system gnu-build-system)
3fdc99da 140 (arguments
d6614607 141 `(#:test-target "test"
3fdc99da 142 #:configure-flags
6a20289d 143 (list "--enable-shared" ;allow embedding
d1659c0f 144 "--with-system-expat" ;for XML support
6a20289d 145 "--with-system-ffi" ;build ctypes
aaf75c89 146 "--with-ensurepip=install" ;install pip and setuptools
a282d7ff 147 "--enable-unicode=ucs4"
fcb54937
MB
148
149 ;; Prevent the installed _sysconfigdata.py from retaining a reference
150 ;; to coreutils.
151 "INSTALL=install -c"
152 "MKDIR_P=mkdir -p"
153
6a20289d
LC
154 (string-append "LDFLAGS=-Wl,-rpath="
155 (assoc-ref %outputs "out") "/lib"))
5b01b603
EB
156 ;; With no -j argument tests use all available cpus, so provide one.
157 #:make-flags
e337061b
MC
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"))
fd982732 166
d2cc9c7c
LC
167 #:modules ((ice-9 ftw) (ice-9 match)
168 (guix build utils) (guix build gnu-build-system))
fd982732 169 #:phases
46472ecd
MW
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"
b18226c3 180 "Lib/test/support/__init__.py"
46472ecd
MW
181 "Lib/test/test_subprocess.py"))
182 (("/bin/sh") (which "sh")))
183 #t))
5b4e2791
LC
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))
46472ecd
MW
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))
02f0c3b2 217 #t)))
9ffe61b0
LC
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)
d453b0e1 234 ("support" #f)
9ffe61b0
LC
235 (file
236 (not
237 (string-prefix? "test_support."
238 file))))))
239 (call-with-output-file "__init__.py" (const #t))
240 #t)))))))
d41f6394
RW
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)))
02f0c3b2
LC
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))))))
a01b6da7 284 (inputs
3fdc99da 285 `(("bzip2" ,bzip2)
d1659c0f 286 ("expat" ,expat)
3fdc99da 287 ("gdbm" ,gdbm)
b10ab723 288 ("libffi" ,libffi) ; for ctypes
b88e1b0a 289 ("sqlite" ,sqlite) ; for sqlite extension
a01b6da7 290 ("openssl" ,openssl)
3fdc99da 291 ("readline" ,readline)
afa181ff
LC
292 ("zlib" ,zlib)
293 ("tcl" ,tcl)
294 ("tk" ,tk))) ; for tkinter
b10ab723
CR
295 (native-inputs
296 `(("pkg-config" ,pkg-config)))
9be8d7c8
LC
297 (native-search-paths
298 (list (search-path-specification
299 (variable "PYTHONPATH")
af070955 300 (files '("lib/python2.7/site-packages")))))
f0499100 301 (home-page "https://www.python.org")
afa181ff 302 (synopsis "High-level, dynamically-typed programming language")
a01b6da7
NK
303 (description
304 "Python is a remarkably powerful dynamic programming language that
305is used in a wide variety of application domains. Some of its key
306distinguishing features include: clear, readable syntax; strong
307introspection capabilities; intuitive object orientation; natural
308expression of procedural code; full modularity, supporting hierarchical
309packages; exception-based error handling; and very high level dynamic
310data types.")
cb13618b 311 (properties '((cpe-name . "python")))
3f641af0 312 (license license:psfl)))
acc26ff1 313
45848023
HG
314;; Current 2.x version.
315(define-public python-2 python-2.7)
316
b63f6c01
LC
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
a1454169 326(define-public python-3.7
b24d1cfc 327 (package (inherit python-2)
b4d0cf40 328 (name "python")
680bc34d 329 (version "3.7.4")
717003e3
LC
330 (source (origin
331 (method url-fetch)
332 (uri (string-append "https://www.python.org/ftp/python/"
333 version "/Python-" version ".tar.xz"))
fc1adab1 334 (patches (search-patches
b18226c3 335 "python-3-fix-tests.patch"
fc1adab1
AK
336 "python-3-deterministic-build-info.patch"
337 "python-3-search-paths.patch"))
717003e3
LC
338 (sha256
339 (base32
680bc34d 340 "0gxiv5617zd7dnqm5k9r4q2188lk327nf9jznwq9j6b8p0s92ygv"))
d1659c0f 341 (modules '((guix build utils)))
fd615918 342 (snippet
e46e9573 343 '(begin
d1659c0f
MB
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"))
e46e9573 349 #t))))
9b7e389d
RW
350 (arguments
351 (substitute-keyword-arguments (package-arguments python-2)
e337061b 352 ((#:make-flags _)
a5e9413c
MC
353 `(list (string-append
354 (format #f "TESTOPTS=-j~d" (parallel-job-count))
680bc34d
MB
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 '()))))
9b7e389d 365 ((#:phases phases)
a1454169 366 `(modify-phases ,phases
680bc34d
MB
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))
a1454169
MB
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))
d41f6394 380 (replace 'rebuild-bytecode
9b7e389d 381 (lambda* (#:key outputs #:allow-other-keys)
9b7e389d 382 (let ((out (assoc-ref outputs "out")))
a422e247
MB
383 ;; Disable hash randomization to ensure the generated .pycs
384 ;; are reproducible.
385 (setenv "PYTHONHASHSEED" "0")
9b7e389d
RW
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.
a422e247 397 "-x" "lib2to3/.*"
9b7e389d
RW
398 ,file)))
399 (find-files out "\\.py$")))
b4291db2
MW
400 (list '() '("-O") '("-OO")))
401 #t)))))))
680bc34d
MB
402 (native-inputs
403 `(("tzdata" ,tzdata-for-tests)
404 ,@(package-native-inputs python-2)))
1aebc0cb
AE
405 (native-search-paths
406 (list (search-path-specification
407 (variable "PYTHONPATH")
0e05d01e
SB
408 (files (list (string-append "lib/python"
409 (version-major+minor version)
410 "/site-packages"))))))))
f26a77ff 411
af6a9fc2
TLC
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
45848023 437;; Current 3.x version.
a1454169 438(define-public python-3 python-3.7)
45848023
HG
439
440;; Current major version.
441(define-public python python-3)
442
95288fcc
LC
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
a55ebe2e 447 (package/inherit python-2
23c0d40e 448 (name "python2-minimal")
02f0c3b2 449 (outputs '("out"))
5927a843
LC
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
d1659c0f
MB
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)
5927a843 457 ("zlib" ,zlib)))))
95288fcc
LC
458
459(define-public python-minimal
90aeaee8 460 (package/inherit python
95288fcc 461 (name "python-minimal")
02f0c3b2 462 (outputs '("out"))
95288fcc 463
d0b73960 464 ;; Build fails due to missing ctypes without libffi.
95288fcc 465 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
d1659c0f
MB
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)
d0b73960 470 ("openssl" ,openssl)
95288fcc
LC
471 ("zlib" ,zlib)))))
472
9c3f2c2e 473(define-public python-debug
90aeaee8 474 (package/inherit python
9c3f2c2e
LC
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},
488for more information.")))
489
64cb064c
LC
490(define* (wrap-python3 python
491 #:optional
492 (name (string-append (package-name python) "-wrapper")))
90aeaee8 493 (package/inherit python
95288fcc 494 (name name)
898238b9
AE
495 (source #f)
496 (build-system trivial-build-system)
02f0c3b2 497 (outputs '("out"))
3969ca54 498 (inputs `(("bash" ,bash)))
3c0f2329 499 (propagated-inputs `(("python" ,python)))
898238b9
AE
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)))
3969ca54
SB
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)))))))
0d56e3e1
LC
526 (synopsis "Wrapper for the Python 3 commands")
527 (description
528 "This package provides wrappers for the commands of Python@tie{}3.x such
529that they can be invoked under their usual name---e.g., @command{python}
530instead of @command{python3}.")))
531
95288fcc
LC
532(define-public python-wrapper (wrap-python3 python))
533(define-public python-minimal-wrapper (wrap-python3 python-minimal))
20801f9d
EF
534
535(define-public micropython
536 (package
537 (name "micropython")
28ac7335 538 (version "1.11")
20801f9d
EF
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
28ac7335 547 "0px3xhw16rl0l7qifq7jw1gq92wzlnhd17dmszv9m2c3wbzs9p9f"))
20801f9d
EF
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
28ac7335 561 (add-before 'build 'prepare-build
20801f9d
EF
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
587Python 3 programming language that includes a small subset of the Python
588standard library and is optimised to run on microcontrollers and in constrained
589environments. MicroPython is packed full of advanced features such as an
590interactive prompt, arbitrary precision integers, closures, list comprehension,
591generators, exception handling and more. Still it is compact enough to fit and
592run within just 256k of code space and 16k of RAM. MicroPython aims to be as
593compatible with normal Python as possible to allow you to transfer code with
594ease from the desktop to a microcontroller or embedded system.")
595 (license license:expat)))