Commit | Line | Data |
---|---|---|
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> |
4dcb135e | 6 | ;;; Copyright © 2014, 2017 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> |
fcaab9c0 | 29 | ;;; Copyright © 2016, 2017, 2018 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> |
7e846d07 | 57 | ;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
16d21251 | 58 | ;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com> |
9f23f6bc | 59 | ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org> |
c2b2f0c8 | 60 | ;;; |
a01b6da7 NK |
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 | ||
1ffa7090 | 76 | (define-module (gnu packages python) |
3f641af0 | 77 | #:use-module ((guix licenses) #:prefix license:) |
3fdc99da | 78 | #:use-module (gnu packages) |
3969ca54 | 79 | #:use-module (gnu packages bash) |
1ffa7090 | 80 | #:use-module (gnu packages compression) |
255d1bbe | 81 | #:use-module (gnu packages dbm) |
b10ab723 | 82 | #:use-module (gnu packages libffi) |
b10ab723 | 83 | #:use-module (gnu packages pkg-config) |
4ed20663 | 84 | #:use-module (gnu packages readline) |
cd0322a3 | 85 | #:use-module (gnu packages sqlite) |
afa181ff | 86 | #:use-module (gnu packages tcl) |
44d10b1f | 87 | #:use-module (gnu packages tls) |
a01b6da7 NK |
88 | #:use-module (guix packages) |
89 | #:use-module (guix download) | |
11bb85a1 | 90 | #:use-module (guix utils) |
acc26ff1 | 91 | #:use-module (guix build-system gnu) |
44d10b1f | 92 | #:use-module (guix build-system trivial)) |
a01b6da7 | 93 | |
45848023 | 94 | (define-public python-2.7 |
a01b6da7 | 95 | (package |
a7714d42 | 96 | (name "python2") |
a551ba9b | 97 | (version "2.7.15") |
a55ebe2e | 98 | (replacement python-2/fixed) |
a01b6da7 NK |
99 | (source |
100 | (origin | |
101 | (method url-fetch) | |
9b43a0ff | 102 | (uri (string-append "https://www.python.org/ftp/python/" |
a01b6da7 NK |
103 | version "/Python-" version ".tar.xz")) |
104 | (sha256 | |
105 | (base32 | |
a551ba9b | 106 | "0x2mvz9dp11wj7p5ccvmk9s0hzjk2fa1m462p395l4r6bfnb3n92")) |
c3052d6b ML |
107 | (patches (search-patches "python-2.7-search-paths.patch" |
108 | "python-2-deterministic-build-info.patch" | |
15e57f57 | 109 | "python-2.7-site-prefixes.patch" |
dc5cec21 | 110 | "python-2.7-source-date-epoch.patch" |
603a6492 | 111 | "python-2.7-adjust-tests.patch")) |
10a42aa2 EF |
112 | (modules '((guix build utils))) |
113 | ;; suboptimal to delete failing tests here, but if we delete them in the | |
114 | ;; arguments then we need to make sure to strip out that phase when it | |
115 | ;; gets inherited by python and python-minimal. | |
116 | (snippet | |
117 | '(begin | |
118 | (for-each delete-file | |
119 | '("Lib/test/test_compileall.py" | |
f0499100 | 120 | "Lib/test/test_ctypes.py" ; fails on mips64el |
10a42aa2 EF |
121 | "Lib/test/test_distutils.py" |
122 | "Lib/test/test_import.py" | |
123 | "Lib/test/test_shutil.py" | |
124 | "Lib/test/test_socket.py" | |
1bb163b0 | 125 | "Lib/test/test_subprocess.py")) |
10a42aa2 | 126 | #t)))) |
02f0c3b2 LC |
127 | (outputs '("out" |
128 | "tk")) ;tkinter; adds 50 MiB to the closure | |
a01b6da7 | 129 | (build-system gnu-build-system) |
3fdc99da | 130 | (arguments |
d6614607 | 131 | `(#:test-target "test" |
3fdc99da | 132 | #:configure-flags |
6a20289d LC |
133 | (list "--enable-shared" ;allow embedding |
134 | "--with-system-ffi" ;build ctypes | |
aaf75c89 | 135 | "--with-ensurepip=install" ;install pip and setuptools |
a282d7ff | 136 | "--enable-unicode=ucs4" |
6a20289d LC |
137 | (string-append "LDFLAGS=-Wl,-rpath=" |
138 | (assoc-ref %outputs "out") "/lib")) | |
fd982732 | 139 | |
d2cc9c7c LC |
140 | #:modules ((ice-9 ftw) (ice-9 match) |
141 | (guix build utils) (guix build gnu-build-system)) | |
fd982732 | 142 | #:phases |
46472ecd MW |
143 | (modify-phases %standard-phases |
144 | (add-before | |
145 | 'configure 'patch-lib-shells | |
146 | (lambda _ | |
147 | ;; Filter for existing files, since some may not exist in all | |
148 | ;; versions of python that are built with this recipe. | |
149 | (substitute* (filter file-exists? | |
150 | '("Lib/subprocess.py" | |
151 | "Lib/popen2.py" | |
152 | "Lib/distutils/tests/test_spawn.py" | |
b18226c3 | 153 | "Lib/test/support/__init__.py" |
46472ecd MW |
154 | "Lib/test/test_subprocess.py")) |
155 | (("/bin/sh") (which "sh"))) | |
156 | #t)) | |
5b4e2791 LC |
157 | (add-before 'configure 'do-not-record-configure-flags |
158 | (lambda* (#:key configure-flags #:allow-other-keys) | |
159 | ;; Remove configure flags from the installed '_sysconfigdata.py' | |
160 | ;; and 'Makefile' so we don't end up keeping references to the | |
161 | ;; build tools. | |
162 | ;; | |
163 | ;; Preserve at least '--with-system-ffi' since otherwise the | |
164 | ;; thing tries to build libffi, fails, and we end up with a | |
165 | ;; Python that lacks ctypes. | |
166 | (substitute* "configure" | |
167 | (("^CONFIG_ARGS=.*$") | |
168 | (format #f "CONFIG_ARGS='~a'\n" | |
169 | (if (member "--with-system-ffi" configure-flags) | |
170 | "--with-system-ffi" | |
171 | "")))) | |
172 | #t)) | |
46472ecd MW |
173 | (add-before |
174 | 'check 'pre-check | |
175 | (lambda _ | |
176 | ;; 'Lib/test/test_site.py' needs a valid $HOME | |
177 | (setenv "HOME" (getcwd)) | |
178 | #t)) | |
179 | (add-after | |
180 | 'unpack 'set-source-file-times-to-1980 | |
181 | ;; XXX One of the tests uses a ZIP library to pack up some of the | |
182 | ;; source tree, and fails with "ZIP does not support timestamps | |
183 | ;; before 1980". Work around this by setting the file times in the | |
184 | ;; source tree to sometime in early 1980. | |
185 | (lambda _ | |
186 | (let ((circa-1980 (* 10 366 24 60 60))) | |
187 | (ftw "." (lambda (file stat flag) | |
188 | (utime file circa-1980 circa-1980) | |
189 | #t)) | |
02f0c3b2 | 190 | #t))) |
9ffe61b0 LC |
191 | (add-after 'install 'remove-tests |
192 | ;; Remove 25 MiB of unneeded unit tests. Keep test_support.* | |
193 | ;; because these files are used by some libraries out there. | |
194 | (lambda* (#:key outputs #:allow-other-keys) | |
195 | (let ((out (assoc-ref outputs "out"))) | |
196 | (match (scandir (string-append out "/lib") | |
197 | (lambda (name) | |
198 | (string-prefix? "python" name))) | |
199 | ((pythonX.Y) | |
200 | (let ((testdir (string-append out "/lib/" pythonX.Y | |
201 | "/test"))) | |
202 | (with-directory-excursion testdir | |
203 | (for-each delete-file-recursively | |
204 | (scandir testdir | |
205 | (match-lambda | |
206 | ((or "." "..") #f) | |
207 | (file | |
208 | (not | |
799d4bac MB |
209 | ;; FIXME: Add the 'support' directory |
210 | ;; in the next rebuild cycle, since it | |
211 | ;; moved in 2.7.14. See also | |
212 | ;; python2-futures below. | |
9ffe61b0 LC |
213 | (string-prefix? "test_support." |
214 | file)))))) | |
215 | (call-with-output-file "__init__.py" (const #t)) | |
216 | #t))))))) | |
02f0c3b2 LC |
217 | (add-after 'install 'move-tk-inter |
218 | (lambda* (#:key outputs #:allow-other-keys) | |
219 | ;; When Tkinter support is built move it to a separate output so | |
220 | ;; that the main output doesn't contain a reference to Tcl/Tk. | |
221 | (let ((out (assoc-ref outputs "out")) | |
222 | (tk (assoc-ref outputs "tk"))) | |
223 | (when tk | |
224 | (match (find-files out "tkinter.*\\.so") | |
225 | ((tkinter.so) | |
226 | ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we | |
227 | ;; want it under TK/lib/pythonX.Y/site-packages. | |
228 | (let* ((len (string-length out)) | |
229 | (target (string-append | |
230 | tk "/" | |
231 | (string-drop | |
232 | (dirname (dirname tkinter.so)) | |
233 | len) | |
234 | "/site-packages"))) | |
235 | (install-file tkinter.so target) | |
236 | (delete-file tkinter.so))))) | |
237 | #t)))))) | |
a01b6da7 | 238 | (inputs |
3fdc99da CR |
239 | `(("bzip2" ,bzip2) |
240 | ("gdbm" ,gdbm) | |
b10ab723 | 241 | ("libffi" ,libffi) ; for ctypes |
b88e1b0a | 242 | ("sqlite" ,sqlite) ; for sqlite extension |
a01b6da7 | 243 | ("openssl" ,openssl) |
3fdc99da | 244 | ("readline" ,readline) |
afa181ff LC |
245 | ("zlib" ,zlib) |
246 | ("tcl" ,tcl) | |
247 | ("tk" ,tk))) ; for tkinter | |
b10ab723 CR |
248 | (native-inputs |
249 | `(("pkg-config" ,pkg-config))) | |
9be8d7c8 LC |
250 | (native-search-paths |
251 | (list (search-path-specification | |
252 | (variable "PYTHONPATH") | |
af070955 | 253 | (files '("lib/python2.7/site-packages"))))) |
f0499100 | 254 | (home-page "https://www.python.org") |
afa181ff | 255 | (synopsis "High-level, dynamically-typed programming language") |
a01b6da7 NK |
256 | (description |
257 | "Python is a remarkably powerful dynamic programming language that | |
258 | is used in a wide variety of application domains. Some of its key | |
259 | distinguishing features include: clear, readable syntax; strong | |
260 | introspection capabilities; intuitive object orientation; natural | |
261 | expression of procedural code; full modularity, supporting hierarchical | |
262 | packages; exception-based error handling; and very high level dynamic | |
263 | data types.") | |
cb13618b | 264 | (properties '((cpe-name . "python"))) |
3f641af0 | 265 | (license license:psfl))) |
acc26ff1 | 266 | |
45848023 HG |
267 | ;; Current 2.x version. |
268 | (define-public python-2 python-2.7) | |
269 | ||
a55ebe2e MB |
270 | (define python-2/fixed |
271 | (package | |
272 | (inherit python-2) | |
273 | (source (origin | |
274 | (inherit (package-source python-2)) | |
275 | (patches (append | |
276 | (origin-patches (package-source python-2)) | |
16f14f63 | 277 | (search-patches "python2-CVE-2018-14647.patch" |
a55ebe2e MB |
278 | "python2-CVE-2018-1000802.patch"))))))) |
279 | ||
b63f6c01 LC |
280 | (define-public python2-called-python |
281 | ;; Both 2.x and 3.x used to be called "python". In commit | |
282 | ;; a7714d42de2c3082f3609d1e63c83d703fb39cf9 (March 2018), we renamed the | |
283 | ;; Python 2.x package to "python2". | |
284 | (package | |
285 | (inherit python-2) | |
286 | (name "python") | |
287 | (properties `((superseded . ,python-2))))) | |
288 | ||
a1454169 | 289 | (define-public python-3.7 |
b24d1cfc | 290 | (package (inherit python-2) |
b4d0cf40 | 291 | (name "python") |
a1454169 | 292 | (version "3.7.0") |
90aeaee8 | 293 | (replacement python-3/fixed) |
717003e3 LC |
294 | (source (origin |
295 | (method url-fetch) | |
296 | (uri (string-append "https://www.python.org/ftp/python/" | |
297 | version "/Python-" version ".tar.xz")) | |
fc1adab1 AK |
298 | (patches (search-patches |
299 | "python-fix-tests.patch" | |
b18226c3 | 300 | "python-3-fix-tests.patch" |
fc1adab1 AK |
301 | "python-3-deterministic-build-info.patch" |
302 | "python-3-search-paths.patch")) | |
717003e3 LC |
303 | (patch-flags '("-p0")) |
304 | (sha256 | |
305 | (base32 | |
a1454169 | 306 | "0j9mic5c9lbd2b20wka7hily7szz740wy9ilfrczxap63rnrk0h3")) |
fd615918 | 307 | (snippet |
e46e9573 EF |
308 | '(begin |
309 | (for-each delete-file | |
589aca1c MB |
310 | '(;; This test may hang and eventually run out of |
311 | ;; memory on some systems: | |
312 | ;; <https://bugs.python.org/issue34587> | |
313 | "Lib/test/test_socket.py" | |
314 | ||
315 | ;; These tests fail on AArch64. | |
316 | "Lib/ctypes/test/test_win32.py" | |
317 | "Lib/test/test_fcntl.py" | |
318 | "Lib/test/test_posix.py")) | |
e46e9573 | 319 | #t)))) |
9b7e389d RW |
320 | (arguments |
321 | (substitute-keyword-arguments (package-arguments python-2) | |
9b7e389d | 322 | ((#:phases phases) |
a1454169 MB |
323 | `(modify-phases ,phases |
324 | ;; Unset SOURCE_DATE_EPOCH while running the test-suite and set it | |
325 | ;; again afterwards. See <https://bugs.python.org/issue34022>. | |
326 | (add-before 'check 'unset-SOURCE_DATE_EPOCH | |
327 | (lambda _ (unsetenv "SOURCE_DATE_EPOCH") #t)) | |
328 | (add-after 'check 'reset-SOURCE_DATE_EPOCH | |
329 | (lambda _ (setenv "SOURCE_DATE_EPOCH" "1") #t)) | |
330 | ;; FIXME: Without this phase we have close to 400 files that | |
9b7e389d | 331 | ;; differ across different builds of this package. With this phase |
a1454169 | 332 | ;; there are 44 files left that differ. |
81d96707 | 333 | (add-after 'remove-tests 'rebuild-bytecode |
9b7e389d | 334 | (lambda* (#:key outputs #:allow-other-keys) |
9b7e389d | 335 | (let ((out (assoc-ref outputs "out"))) |
a422e247 MB |
336 | ;; Disable hash randomization to ensure the generated .pycs |
337 | ;; are reproducible. | |
338 | (setenv "PYTHONHASHSEED" "0") | |
9b7e389d RW |
339 | (for-each |
340 | (lambda (opt) | |
341 | (format #t "Compiling with optimization level: ~a\n" | |
342 | (if (null? opt) "none" (car opt))) | |
343 | (for-each (lambda (file) | |
344 | (apply invoke | |
345 | `(,(string-append out "/bin/python3") | |
346 | ,@opt | |
347 | "-m" "compileall" | |
348 | "-f" ; force rebuild | |
349 | ;; Don't build lib2to3, because it's Python 2 code. | |
a422e247 | 350 | "-x" "lib2to3/.*" |
9b7e389d RW |
351 | ,file))) |
352 | (find-files out "\\.py$"))) | |
b4291db2 MW |
353 | (list '() '("-O") '("-OO"))) |
354 | #t))))))) | |
1aebc0cb AE |
355 | (native-search-paths |
356 | (list (search-path-specification | |
357 | (variable "PYTHONPATH") | |
0e05d01e SB |
358 | (files (list (string-append "lib/python" |
359 | (version-major+minor version) | |
360 | "/site-packages")))))))) | |
f26a77ff | 361 | |
45848023 | 362 | ;; Current 3.x version. |
a1454169 | 363 | (define-public python-3 python-3.7) |
45848023 | 364 | |
90aeaee8 MB |
365 | (define python-3/fixed |
366 | (package | |
367 | (inherit python-3) | |
368 | (source (origin | |
369 | (inherit (package-source python-3)) | |
370 | (patches (append (origin-patches (package-source python-3)) | |
16f14f63 | 371 | (search-patches "python-CVE-2018-14647.patch"))))))) |
90aeaee8 | 372 | |
45848023 HG |
373 | ;; Current major version. |
374 | (define-public python python-3) | |
375 | ||
95288fcc LC |
376 | ;; Minimal variants of Python, mostly used to break the cycle between Tk and |
377 | ;; Python (Tk -> libxcb -> Python.) | |
378 | ||
379 | (define-public python2-minimal | |
a55ebe2e | 380 | (package/inherit python-2 |
23c0d40e | 381 | (name "python2-minimal") |
02f0c3b2 | 382 | (outputs '("out")) |
5927a843 LC |
383 | |
384 | ;; Keep zlib, which is used by 'pip' (via the 'zipimport' module), which | |
385 | ;; is invoked upon 'make install'. 'pip' also expects 'ctypes' and thus | |
386 | ;; libffi. | |
387 | (inputs `(("libffi" ,libffi) | |
388 | ("zlib" ,zlib))))) | |
95288fcc LC |
389 | |
390 | (define-public python-minimal | |
90aeaee8 | 391 | (package/inherit python |
95288fcc | 392 | (name "python-minimal") |
02f0c3b2 | 393 | (outputs '("out")) |
95288fcc | 394 | |
d0b73960 | 395 | ;; Build fails due to missing ctypes without libffi. |
95288fcc LC |
396 | ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib; |
397 | ;; zlib is required by 'zipimport', used by pip. | |
d0b73960 CAW |
398 | (inputs `(("libffi" ,libffi) |
399 | ("openssl" ,openssl) | |
95288fcc LC |
400 | ("zlib" ,zlib))))) |
401 | ||
9c3f2c2e | 402 | (define-public python-debug |
90aeaee8 | 403 | (package/inherit python |
9c3f2c2e LC |
404 | (name "python-debug") |
405 | (outputs '("out" "debug")) | |
406 | (build-system gnu-build-system) | |
407 | (arguments | |
408 | (substitute-keyword-arguments (package-arguments python) | |
409 | ((#:configure-flags flags '()) | |
410 | `(cons "--with-pydebug" ,flags)))) | |
411 | (synopsis | |
412 | "High-level, dynamically-typed programming language (for debugging)") | |
413 | (description | |
414 | "This variant of Python provides an interpreter built with | |
415 | @code{--with-pydebug} to help develop and debug extensions. See | |
416 | @url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html}, | |
417 | for more information."))) | |
418 | ||
64cb064c LC |
419 | (define* (wrap-python3 python |
420 | #:optional | |
421 | (name (string-append (package-name python) "-wrapper"))) | |
90aeaee8 | 422 | (package/inherit python |
95288fcc | 423 | (name name) |
898238b9 AE |
424 | (source #f) |
425 | (build-system trivial-build-system) | |
02f0c3b2 | 426 | (outputs '("out")) |
3969ca54 | 427 | (inputs `(("bash" ,bash))) |
3c0f2329 | 428 | (propagated-inputs `(("python" ,python))) |
898238b9 AE |
429 | (arguments |
430 | `(#:modules ((guix build utils)) | |
431 | #:builder | |
432 | (begin | |
433 | (use-modules (guix build utils)) | |
434 | (let ((bin (string-append (assoc-ref %outputs "out") "/bin")) | |
435 | (python (string-append (assoc-ref %build-inputs "python") "/bin/"))) | |
436 | (mkdir-p bin) | |
437 | (for-each | |
438 | (lambda (old new) | |
439 | (symlink (string-append python old) | |
440 | (string-append bin "/" new))) | |
3969ca54 SB |
441 | `("python3" ,"pydoc3" ,"idle3" ,"pip3") |
442 | `("python" ,"pydoc" ,"idle" ,"pip")) | |
443 | ;; python-config outputs search paths based upon its location, | |
444 | ;; use a bash wrapper to avoid changing its outputs. | |
445 | (let ((bash (string-append (assoc-ref %build-inputs "bash") | |
446 | "/bin/bash")) | |
447 | (old (string-append python "python3-config")) | |
448 | (new (string-append bin "/python-config"))) | |
449 | (with-output-to-file new | |
450 | (lambda () | |
451 | (format #t "#!~a~%" bash) | |
452 | (format #t "exec \"~a\" \"$@\"~%" old) | |
453 | (chmod new #o755) | |
454 | #t))))))) | |
0d56e3e1 LC |
455 | (synopsis "Wrapper for the Python 3 commands") |
456 | (description | |
457 | "This package provides wrappers for the commands of Python@tie{}3.x such | |
458 | that they can be invoked under their usual name---e.g., @command{python} | |
459 | instead of @command{python3}."))) | |
460 | ||
95288fcc LC |
461 | (define-public python-wrapper (wrap-python3 python)) |
462 | (define-public python-minimal-wrapper (wrap-python3 python-minimal)) | |
20801f9d EF |
463 | |
464 | (define-public micropython | |
465 | (package | |
466 | (name "micropython") | |
467 | (version "1.10") | |
468 | (source | |
469 | (origin | |
470 | (method url-fetch) | |
471 | (uri (string-append "https://github.com/micropython/micropython/" | |
472 | "releases/download/v" version | |
473 | "/micropython-" version ".tar.gz")) | |
474 | (sha256 | |
475 | (base32 | |
476 | "1g1zjip3rkx6bp16qi1bag72wivnbh56fcsl3nffanrx4j5f4z90")) | |
477 | (modules '((guix build utils))) | |
478 | (snippet | |
479 | '(begin | |
480 | (delete-file-recursively "ports/cc3200/FreeRTOS") | |
481 | (with-directory-excursion "lib" | |
482 | ;; TODO: Unbundle axtls and berkley-db-1.xx | |
483 | (for-each delete-file-recursively | |
484 | '("libffi" "lwip" "stm32lib" "nrfx"))) | |
485 | #t)))) | |
486 | (build-system gnu-build-system) | |
487 | (arguments | |
488 | `(#:phases | |
489 | (modify-phases %standard-phases | |
490 | (add-before 'build 'preprare-build | |
491 | (lambda _ | |
492 | (chdir "ports/unix") | |
493 | ;; see: https://github.com/micropython/micropython/pull/4246 | |
494 | (substitute* "Makefile" | |
495 | (("-Os") "-Os -ffp-contract=off")) | |
496 | #t)) | |
497 | (replace 'install-license-files | |
498 | ;; We don't build in the root directory so the file isn't found. | |
499 | (lambda* (#:key outputs #:allow-other-keys) | |
500 | (let* ((out (assoc-ref outputs "out")) | |
501 | (dest (string-append out "/share/doc/" ,name "-" ,version "/"))) | |
502 | (install-file "../../LICENSE" dest)) | |
503 | #t)) | |
504 | (delete 'configure)) ; no configure | |
505 | #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")) | |
506 | "V=1") | |
507 | #:test-target "test")) | |
508 | (native-inputs | |
509 | `(("pkg-config" ,pkg-config) | |
510 | ("python" ,python-wrapper))) | |
511 | (inputs | |
512 | `(("libffi" ,libffi))) | |
513 | (home-page "https://micropython.org/") | |
514 | (synopsis "Python implementation for microcontrollers and constrained systems") | |
515 | (description "MicroPython is a lean and efficient implementation of the | |
516 | Python 3 programming language that includes a small subset of the Python | |
517 | standard library and is optimised to run on microcontrollers and in constrained | |
518 | environments. MicroPython is packed full of advanced features such as an | |
519 | interactive prompt, arbitrary precision integers, closures, list comprehension, | |
520 | generators, exception handling and more. Still it is compact enough to fit and | |
521 | run within just 256k of code space and 16k of RAM. MicroPython aims to be as | |
522 | compatible with normal Python as possible to allow you to transfer code with | |
523 | ease from the desktop to a microcontroller or embedded system.") | |
524 | (license license:expat))) |