python.scm 24 KB

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