projects/guix·blob audio-team · refs

1510 lines · 72.3 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013 Nikita Karetnikov <[email protected]>
3;;; Copyright © 2013-2018, 2021, 2023, 2025 Ludovic Courtès <[email protected]>
4;;; Copyright © 2013, 2014, 2015, 2016 Andreas Enge <[email protected]>
5;;; Copyright © 2014, 2015 Mark H Weaver <[email protected]>
6;;; Copyright © 2014, 2017, 2019 Eric Bavier <[email protected]>
7;;; Copyright © 2014, 2015 Federico Beffa <[email protected]>
8;;; Copyright © 2015 Omar Radwan <[email protected]>
9;;; Copyright © 2015 Pierre-Antoine Rault <[email protected]>
10;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <[email protected]>
11;;; Copyright © 2015, 2016 Christine Lemmer-Webber <[email protected]>
12;;; Copyright © 2015 Eric Dvorsak <[email protected]>
13;;; Copyright © 2015, 2016 David Thompson <[email protected]>
14;;; Copyright © 2015, 2016, 2017, 2021 Leo Famulari <[email protected]>
15;;; Copyright © 2015, 2017 Ben Woodcroft <[email protected]>
16;;; Copyright © 2015, 2016 Erik Edrosa <[email protected]>
17;;; Copyright © 2015-2020, 2023 Efraim Flashner <[email protected]>
18;;; Copyright © 2015, 2017 Kyle Meyer <[email protected]>
19;;; Copyright © 2015, 2016 Chris Marusich <[email protected]>
20;;; Copyright © 2016 Danny Milosavljevic <[email protected]>
21;;; Copyright © 2016 Lukas Gradl <[email protected]>
22;;; Copyright © 2016, 2018, 2025 Hartmut Goebel <[email protected]>
23;;; Copyright © 2016 Daniel Pimentel <[email protected]>
24;;; Copyright © 2016 Sou Bunnbu <[email protected]>
25;;; Copyright © 2016, 2017 Troy Sankey <[email protected]>
26;;; Copyright © 2016, 2017 Nikita <[email protected]>
27;;; Copyright © 2016 Dylan Jeffers <sapientech@[email protected]>
28;;; Copyright © 2016 David Craven <[email protected]>
29;;; Copyright © 2016-2022 Marius Bakke <[email protected]>
30;;; Copyright © 2016, 2017 Stefan Reichör <[email protected]>
31;;; Copyright © 2016, 2017 Alex Vong <[email protected]>
32;;; Copyright © 2016, 2017, 2018 Arun Isaac <[email protected]>
33;;; Copyright © 2016–2018, 2021, 2022 Tobias Geerinckx-Rice <[email protected]>
34;;; Copyright © 2016, 2017, 2018, 2021 Julien Lepiller <[email protected]>
35;;; Copyright © 2016, 2017 Thomas Danckaert <[email protected]>
36;;; Copyright © 2017 Carlo Zancanaro <[email protected]>
37;;; Copyright © 2017 Frederick M. Muriithi <[email protected]>
38;;; Copyright © 2017, 2018 Adriano Peluso <[email protected]>
39;;; Copyright © 2017 Ben Sturmfels <[email protected]>
40;;; Copyright © 2017, 2018, 2019 Mathieu Othacehe <[email protected]>
41;;; Copyright © 2017 José Miguel Sánchez García <[email protected]>
42;;; Copyright © 2017 Roel Janssen <[email protected]>
43;;; Copyright © 2017, 2018 Kei Kebreau <[email protected]>
44;;; Copyright © 2017 Rutger Helling <[email protected]>
45;;; Copyright © 2017 Brendan Tildesley <[email protected]>
46;;; Copyright © 2018 Ethan R. Jones <[email protected]
47;;; Copyright © 2018 Fis Trivial <[email protected]>
48;;; Copyright © 2018 Vijayalakshmi Vedantham <[email protected]>
49;;; Copyright © 2018 Mathieu Lirzin <[email protected]>
50;;; Copyright © 2018 Adam Massmann <[email protected]>
51;;; Copyright © 2016, 2018 Tomáš Čech <[email protected]>
52;;; Copyright © 2018 Nicolas Goaziou <[email protected]>
53;;; Copyright © 2018 Oleg Pykhalov <[email protected]>
54;;; Copyright © 2018 Clément Lassieur <[email protected]>
55;;; Copyright © 2018, 2019, 2020, 2021, 2025 Maxim Cournoyer <[email protected]>
56;;; Copyright © 2018 Luther Thompson <[email protected]>
57;;; Copyright © 2018 Vagrant Cascadian <[email protected]>
58;;; Copyright © 2019, 2024 Tanguy Le Carrour <[email protected]>
59;;; Copyright © 2020, 2023, 2025 Janneke Nieuwenhuizen <[email protected]>
60;;; Copyright © 2020, 2021 Greg Hogan <[email protected]>
61;;; Copyright © 2022 Philip McGrath <[email protected]>
62;;; Copyright © 2022 jgart <[email protected]>
63;;; Copyright © 2021 Lars-Dominik Braun <[email protected]>
64;;; Copyright © 2025 Hugo Buddelmeijer <[email protected]>
65;;; Copyright © 2025 Sharlatan Hellseher <[email protected]>
66;;; Copyright © 2025-2026 Nicolas Graves <[email protected]>
67;;;
68;;; This file is part of GNU Guix.
69;;;
70;;; GNU Guix is free software; you can redistribute it and/or modify it
71;;; under the terms of the GNU General Public License as published by
72;;; the Free Software Foundation; either version 3 of the License, or (at
73;;; your option) any later version.
74;;;
75;;; GNU Guix is distributed in the hope that it will be useful, but
76;;; WITHOUT ANY WARRANTY; without even the implied warranty of
77;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78;;; GNU General Public License for more details.
79;;;
80;;; You should have received a copy of the GNU General Public License
81;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
82
83(define-module (gnu packages python)
84 #:use-module ((guix licenses) #:prefix license:)
85 #:use-module (gnu packages)
86 #:use-module (gnu packages base)
87 #:use-module (gnu packages bash)
88 #:use-module (gnu packages check)
89 #:use-module (gnu packages compression)
90 #:use-module (gnu packages crypto)
91 #:use-module (gnu packages dbm)
92 #:use-module (gnu packages libffi)
93 #:use-module (gnu packages pkg-config)
94 #:use-module (gnu packages python-build)
95 #:use-module (gnu packages readline)
96 #:use-module (gnu packages sqlite)
97 #:use-module (gnu packages tcl)
98 #:use-module (gnu packages tls)
99 #:use-module (gnu packages xml)
100 #:use-module (guix gexp)
101 #:use-module (guix git-download)
102 #:use-module (guix packages)
103 #:use-module (guix download)
104 #:use-module (guix search-paths)
105 #:use-module (guix utils)
106 #:use-module (guix build-system copy)
107 #:use-module (guix build-system gnu)
108 #:use-module (guix build-system trivial)
109 #:use-module (ice-9 optargs)
110 #:use-module (srfi srfi-1)
111 #:use-module (srfi srfi-26)
112
113 #:export (customize-site
114 guix-pythonpath-search-path))
115
116(define* (customize-site version)
117 "Generate a install-sitecustomize.py phase, using VERSION."
118 `(lambda* (#:key native-inputs inputs outputs #:allow-other-keys)
119 (let* ((out (assoc-ref outputs "out"))
120 (site-packages (string-append
121 out "/lib/python"
122 ,(version-major+minor version)
123 "/site-packages"))
124 (sitecustomize.py (assoc-ref (or native-inputs inputs)
125 "sitecustomize.py"))
126 (dest (string-append site-packages "/sitecustomize.py")))
127 (mkdir-p site-packages)
128 (copy-file sitecustomize.py dest)
129 ;; Set the correct permissions on the installed file, else the byte
130 ;; compilation phase fails with a permission denied error.
131 (chmod dest #o644))))
132
133(define (guix-pythonpath-search-path version)
134 "Generate a GUIX_PYTHONPATH search path specification, using VERSION."
135 (search-path-specification (variable "GUIX_PYTHONPATH")
136 (files (list (string-append
137 "lib/python"
138 (version-major+minor version)
139 "/site-packages")))))
140
141;; Modifying this is a world-rebuild! If possible, modify phases in python
142;; packages themselves.
143(define (common-python-phases-edits)
144 #~((add-before 'configure 'patch-lib-shells
145 (lambda _
146 ;; This variable is used in setup.py to enable cross compilation
147 ;; specific switches. As it is not set properly by configure
148 ;; script, set it manually.
149 #$@(if (%current-target-system)
150 #~((setenv "_PYTHON_HOST_PLATFORM" ""))
151 #~())
152 ;; Filter for existing files, since some may not exist in all
153 ;; versions of python that are built with this recipe.
154 (substitute* (filter file-exists?
155 '("Lib/subprocess.py"
156 "Lib/popen2.py"
157 "Lib/distutils/tests/test_spawn.py"
158 "Lib/test/support/__init__.py"
159 "Lib/test/test_subprocess.py"))
160 (("/bin/sh") (which "sh")))))
161 (add-before 'configure 'do-not-record-configure-flags
162 (lambda* (#:key configure-flags #:allow-other-keys)
163 ;; Remove configure flags from the installed '_sysconfigdata.py'
164 ;; and 'Makefile' so we don't end up keeping references to the
165 ;; build tools.
166 ;;
167 ;; Preserve at least '--with-system-ffi' since otherwise the
168 ;; thing tries to build libffi, fails, and we end up with a
169 ;; Python that lacks ctypes.
170 (substitute* "configure"
171 (("^CONFIG_ARGS=.*$")
172 (format #f "CONFIG_ARGS='~a'\n"
173 (if (member "--with-system-ffi" configure-flags)
174 "--with-system-ffi"
175 ""))))))
176 (add-before 'check 'pre-check
177 (lambda _
178 ;; 'Lib/test/test_site.py' needs a valid $HOME
179 (setenv "HOME" (getcwd))))
180 (add-after '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)))))
190 (add-after 'install 'add-libxcrypt-reference-pkgconfig
191 (lambda* (#:key inputs outputs #:allow-other-keys)
192 (define out (assoc-ref outputs "out"))
193 (define libxcrypt
194 (false-if-exception
195 (dirname (search-input-file inputs "lib/libcrypt.so.1"))))
196 (when libxcrypt
197 (substitute*
198 (find-files (string-append out "/lib/pkgconfig")
199 ".*\\.pc")
200 (("-lcrypt")
201 (string-append "-L" libxcrypt " -lcrypt"))))))
202 (add-after 'install 'remove-tests
203 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
204 ;; because these files are used by some libraries out there.
205 (lambda* (#:key outputs #:allow-other-keys)
206 (let ((out (assoc-ref outputs "out")))
207 (match (scandir (string-append out "/lib")
208 (lambda (name)
209 (string-prefix? "python" name)))
210 ((pythonX.Y)
211 (let ((testdir (string-append out "/lib/" pythonX.Y
212 "/test")))
213 (with-directory-excursion testdir
214 (for-each delete-file-recursively
215 (scandir testdir
216 (match-lambda
217 ((or "." "..") #f)
218 ("support" #f)
219 (file
220 (not
221 (string-prefix? "test_support."
222 file))))))
223 (call-with-output-file "__init__.py" (const #t))))
224 (let ((libdir (string-append out "/lib/" pythonX.Y)))
225 (for-each
226 (lambda (directory)
227 (let ((dir (string-append libdir "/" directory)))
228 (when (file-exists? dir)
229 (delete-file-recursively dir))))
230 '("email/test" "ctypes/test" "unittest/test" "tkinter/test"
231 "sqlite3/test" "bsddb/test" "lib-tk/test" "json/tests"
232 "distutils/tests"))))))))
233 (add-after 'remove-tests 'move-tk-inter
234 (lambda* (#:key outputs #:allow-other-keys)
235 ;; When Tkinter support is built move it to a separate output so
236 ;; that the main output doesn't contain a reference to Tcl/Tk.
237 (let ((out (assoc-ref outputs "out"))
238 (tk (assoc-ref outputs "tk")))
239 (when tk
240 (match (find-files out "tkinter.*\\.so")
241 ((tkinter.so)
242 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
243 ;; want it under TK/lib/pythonX.Y/site-packages.
244 (let* ((len (string-length out))
245 (target (string-append
246 tk "/"
247 (string-drop
248 (dirname (dirname tkinter.so))
249 len)
250 "/site-packages")))
251 (install-file tkinter.so target)
252 (delete-file tkinter.so))))))))
253 (add-after 'move-tk-inter 'move-idle
254 (lambda* (#:key outputs #:allow-other-keys)
255 ;; when idle is built, move it to a separate output to save some
256 ;; space (5MB)
257 (let ((out (assoc-ref outputs "out"))
258 (idle (assoc-ref outputs "idle")))
259 (when idle
260 (for-each
261 (lambda (file)
262 (let ((target (string-append idle "/bin/" (basename file))))
263 (install-file file (dirname target))
264 (delete-file file)))
265 (find-files (string-append out "/bin") "^idle"))
266 (match (find-files out "^idlelib$" #:directories? #t)
267 ((idlelib)
268 (let* ((len (string-length out))
269 (target (string-append idle "/"
270 (string-drop idlelib len)
271 "/site-packages")))
272 (mkdir-p (dirname target))
273 (rename-file idlelib target))))))))))
274
275;; Modifying this is a world-rebuild! If possible, modify phases in python
276;; packages themselves.
277(define (common-python3-phases-edits)
278 #~(#$@(common-python-phases-edits)
279 #$@(if (system-hurd?)
280 #~((add-after 'unpack 'disable-multi-processing
281 (lambda _
282 (substitute* "Makefile.pre.in"
283 (("-j0") "-j1")))))
284 #~())
285 (add-after 'unpack 'remove-windows-binaries
286 (lambda _
287 ;; Delete .exe from embedded .whl (zip) files
288 (for-each
289 (lambda (whl)
290 (let ((dir "whl-content")
291 (circa-1980 (* 10 366 24 60 60)))
292 (mkdir-p dir)
293 (with-directory-excursion dir
294 (let ((whl (string-append "../" whl)))
295 (invoke "unzip" whl)
296 (for-each delete-file (find-files "." "\\.exe$"))
297 (delete-file whl)
298 ;; Reset timestamps to prevent them from ending
299 ;; up in the Zip archive.
300 (ftw "." (lambda (file stat flag)
301 (utime file circa-1980 circa-1980)))
302 (apply invoke "zip" "-X" whl
303 (find-files "." #:directories? #t))))
304 (delete-file-recursively dir)))
305 (find-files "Lib/ensurepip" "\\.whl$"))))
306 (add-after 'move-tk-inter 'move-tk-inter:remove-explicit-store-path
307 (lambda* (#:key outputs inputs #:allow-other-keys)
308 ;; When Tkinter support is built move it to a separate output so
309 ;; that the main output doesn't contain a reference to Tcl/Tk.
310 (let ((out (assoc-ref outputs "out"))
311 (tk (assoc-ref outputs "tk")))
312 (when tk
313 ;; Remove explicit store path references.
314 (let ((tcl (assoc-ref inputs "tcl"))
315 (tk (assoc-ref inputs "tk")))
316 (substitute* (find-files (string-append out "/lib")
317 "^(_sysconfigdata_.*\\.py|Makefile)$")
318 (((string-append "-L" tk "/lib"))
319 "")
320 (((string-append "-L" tcl "/lib"))
321 "")))))))
322 (add-before 'check 'set-TZDIR
323 (lambda* (#:key inputs native-inputs #:allow-other-keys)
324 ;; test_email requires the Olson time zone database.
325 (setenv "TZDIR"
326 (string-append (assoc-ref (or native-inputs
327 inputs) "tzdata")
328 "/share/zoneinfo"))))
329 (add-after 'move-idle 'rebuild-bytecode
330 (lambda* (#:key outputs #:allow-other-keys)
331 ;; Disable hash randomization to ensure the generated .pycs
332 ;; are reproducible.
333 (setenv "PYTHONHASHSEED" "0")
334
335 (for-each (lambda (output)
336 ;; XXX: Delete existing pycs generated by the build
337 ;; system beforehand because the -f argument does
338 ;; not necessarily overwrite all files, leading to
339 ;; indeterministic results.
340 (for-each (lambda (pyc)
341 (delete-file pyc))
342 (find-files output "\\.pyc$"))
343
344 (apply invoke
345 #$(if (%current-target-system)
346 "python3"
347 #~(string-append #$output "/bin/python3"))
348 `("-m" "compileall"
349 "-o" "0"
350 "-o" "1"
351 "-o" "2"
352 "-f" ;force rebuild
353 "--invalidation-mode=unchecked-hash"
354 ;; Don't build lib2to3, because it's Python
355 ;; 2 code.
356 "-x" "lib2to3/.*"
357 ,output)))
358 (map cdr outputs))))))
359
360(define-public python-2.7
361 (package
362 (name "python2")
363 (version "2.7.18")
364 (source
365 (origin
366 (method url-fetch)
367 (uri (string-append "https://www.python.org/ftp/python/"
368 version "/Python-" version ".tar.xz"))
369 (sha256
370 (base32
371 "0hzgxl94hnflis0d6m4szjx0b52gah7wpmcg5g00q7am6xwhwb5n"))
372 (patches (search-patches "python-2.7-search-paths.patch"
373 "python-2-deterministic-build-info.patch"
374 "python-2.7-site-prefixes.patch"
375 "python-2.7-source-date-epoch.patch"
376 "python-2.7-adjust-tests.patch"
377 "python-cross-compile.patch"
378 "python-2.7-CVE-2021-3177.patch"
379 "python-2.7-expat-compat.patch"
380 "python-2.7-no-static-lib.patch"))
381 (modules '((guix build utils)))
382 (snippet
383 '(begin
384 ;; Ensure the bundled copies of these libraries are not used.
385 (for-each delete-file-recursively
386 '("Modules/_ctypes/libffi" "Modules/expat" "Modules/zlib"))
387
388 (substitute* "Modules/Setup.dist"
389 ;; Link Expat instead of embedding the bundled one.
390 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
391
392 ;; Suboptimal to delete failing tests here, but if we delete them in
393 ;; the arguments then we need to make sure to strip out that phase
394 ;; when it gets inherited by python and python-minimal.
395 (for-each delete-file
396 '("Lib/test/test_compileall.py"
397 "Lib/test/test_ctypes.py" ; fails on mips64el
398 "Lib/test/test_distutils.py"
399 "Lib/test/test_import.py"
400 "Lib/test/test_shutil.py"
401 "Lib/test/test_socket.py"
402 "Lib/test/test_subprocess.py"))))))
403 (outputs '("out"
404 "tk" ;tkinter; adds 50 MiB to the closure
405 "idle")) ;programming environment; weighs 5MB
406 (build-system gnu-build-system)
407 (arguments
408 (list
409 #:test-target "test"
410 #:configure-flags
411 #~(list ;; -fno-semantic-interposition reinstates some optimizations by gcc
412 ;; leading to around 15% speedup. This is the default starting from
413 ;; python 3.10.
414 ;; XXX FIXME: How to add "-Wno-error=implicit-function-declaration"
415 ;; *only* for *this* python-2 package? It's not needed for any
416 ;; package inheriting from us.
417 "CFLAGS=-Wno-error=incompatible-pointer-types -fno-semantic-interposition"
418 "--enable-shared" ;allow embedding
419 "--with-system-expat" ;for XML support
420 "--with-system-ffi" ;build ctypes
421 "--with-ensurepip=install" ;install pip and setuptools
422 "--with-computed-gotos" ;main interpreter loop optimization
423 "--enable-unicode=ucs4"
424
425 ;; FIXME: These flags makes Python significantly faster, but
426 ;; leads to non-reproducible binaries.
427 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
428 ;; "--enable-optimizations"
429
430 ;; Prevent the installed _sysconfigdata.py from retaining a reference
431 ;; to coreutils.
432 "INSTALL=install -c"
433 "MKDIR_P=mkdir -p"
434
435 ;; Disable runtime check failing if cross-compiling, see:
436 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
437 #$@(if (%current-target-system)
438 #~("ac_cv_buggy_getaddrinfo=no"
439 "ac_cv_file__dev_ptmx=no"
440 "ac_cv_file__dev_ptc=no")
441 #~())
442 (string-append "LDFLAGS=-Wl,-rpath="
443 (assoc-ref %outputs "out") "/lib"
444 " -fno-semantic-interposition")
445 ;; Add a reference to libxcrypt in LIBS so that the sysconfigdata
446 ;; file records it and propagates it to programs linking against
447 ;; Python.
448 (let ((libxcrypt
449 (false-if-exception
450 (dirname
451 (search-input-file %build-inputs
452 "lib/libcrypt.so.1")))))
453 (string-append
454 "LIBS="
455 (if libxcrypt
456 (string-append "-L" libxcrypt)
457 ""))))
458 ;; With no -j argument tests use all available cpus, so provide one.
459 #:make-flags
460 #~(list (string-append
461 (format #f "TESTOPTS=-j~d" (parallel-job-count))
462 ;; Exclude the following tests as they fail
463 ;; non-deterministically with "error: [Errno 104] Connection
464 ;; reset by peer." Python 3 seems unaffected. A potential fix,
465 ;; yet to be backported to Python 2, is available at:
466 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
467 " --exclude test_urllib2_localnet test_httplib"))
468
469 #:modules '((ice-9 ftw)
470 (ice-9 match)
471 (guix build utils)
472 (guix build gnu-build-system))
473 #:phases
474 #~(modify-phases %standard-phases
475 #$@(common-python-phases-edits)
476 #$@(if (system-hurd?)
477 #~((add-before 'build 'patch-regen-for-hurd
478 (lambda* (#:key inputs #:allow-other-keys)
479 (let ((libc (assoc-ref inputs "libc")))
480 (substitute* "Lib/plat-generic/regen"
481 (("/usr/include/") (string-append libc "/include/")))))))
482 #~())
483 (add-after 'move-idle 'rebuild-bytecode
484 (lambda* (#:key outputs #:allow-other-keys)
485 (let ((out (assoc-ref outputs "out")))
486 ;; Disable hash randomization to ensure the generated .pycs
487 ;; are reproducible.
488 (setenv "PYTHONHASHSEED" "0")
489 (for-each
490 (lambda (output)
491 (for-each (lambda (opt)
492 (format #t "Compiling with optimization level: ~a\n"
493 (if (null? opt) "none" (car opt)))
494 (apply invoke
495 `(,#$(if (%current-target-system)
496 "python2"
497 #~(string-append out "/bin/python"))
498 ,@opt
499 "-m" "compileall"
500 "-f" ; force rebuild
501 ;; Don't build lib2to3, because it contains
502 ;; Python 3 code.
503 "-x" "lib2to3/.*"
504 ,output)))
505 ;; Python 2 has a single file extension (.pyo) for the
506 ;; chosen level of optimization, so it doesn't make
507 ;; sense to byte compile with more than one level.
508 (list '() '("-OO"))))
509 (map cdr outputs)))))
510 (add-after 'install 'install-sitecustomize.py
511 #$(customize-site version)))))
512 (inputs
513 (list bzip2
514 expat
515 gdbm
516 libffi ; for ctypes
517 libxcrypt ; crypto module slated for removal in 3.13, re-enable
518 ; python tests of libxcrypt when that happens
519 sqlite ; for sqlite extension
520 openssl-1.1
521 readline
522 zlib
523 tcl
524 tk)) ; for tkinter
525 (native-inputs
526 `(("pkg-config" ,pkg-config)
527 ("sitecustomize.py" ,(local-file (search-auxiliary-file
528 "python/sitecustomize.py")))
529 ;; When cross-compiling, a native version of Python itself is needed.
530 ,@(if (%current-target-system)
531 `(("python2" ,this-package)
532 ("which" ,which))
533 '())))
534 (native-search-paths
535 (list (guix-pythonpath-search-path version)))
536 (home-page "https://www.python.org")
537 (synopsis "High-level, dynamically-typed programming language")
538 (description
539 "Python is a remarkably powerful dynamic programming language that
540is used in a wide variety of application domains. Some of its key
541distinguishing features include: clear, readable syntax; strong
542introspection capabilities; intuitive object orientation; natural
543expression of procedural code; full modularity, supporting hierarchical
544packages; exception-based error handling; and very high level dynamic
545data types.")
546 (properties '((cpe-name . "python")
547 (cpe-vendor . "python")
548 ;; CVE-2023-36632 is not a bug according to
549 ;; https://github.com/python/cpython/issues/103800
550 (lint-hidden-cve . ("CVE-2023-36632"))))
551 (license license:psfl)))
552
553;; Current 2.x version.
554(define-public python-2 python-2.7)
555
556(define-public python-3.10
557 (package
558 (inherit python-2)
559 (name "python")
560 (version "3.10.19")
561 (source (origin
562 (method url-fetch)
563 (uri (string-append "https://www.python.org/ftp/python/"
564 version "/Python-" version ".tar.xz"))
565 (patches (search-patches
566 "python-3-arm-alignment.patch"
567 "python-3-deterministic-build-info.patch"
568 "python-3-fix-tests.patch"
569 "python-3-hurd-configure.patch"
570 "python-3-reproducible-build.patch"
571 "python-3-search-paths.patch"))
572 (sha256
573 (base32
574 "0xn0jydg5fsz9fsni6a83l7sf6by2w7gg4fzswfxh092aybabx68"))
575 (modules '((guix build utils)))
576 (snippet
577 '(begin
578 ;; Delete the bundled copy of libexpat.
579 (delete-file-recursively "Modules/expat")
580 (substitute* "Modules/Setup"
581 ;; Link Expat instead of embedding the bundled one.
582 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
583 ;; Delete windows binaries
584 (for-each delete-file
585 (find-files "Lib/distutils/command" "\\.exe$"))))))
586 (build-system gnu-build-system)
587 (arguments
588 (list
589 #:test-target "test"
590 #:configure-flags
591 ;; Avoid inheriting phases, but configure-flags is fine, as
592 ;; it doesn't propagate to later python version.
593 (let-keywords (package-arguments python-2) #t
594 ((configure-flags #~(list)))
595 #~(append #$configure-flags
596 ;; XXX Use quote to avoid world rebuild at this time
597 '("--without-static-libpython")))
598 #:make-flags
599 #~(list (string-append
600 (format #f "TESTOPTS=-j~d" (parallel-job-count))
601 ;; test_mmap fails on low-memory systems
602 " --exclude test_mmap test_socket"
603 #$@(if (system-hurd?)
604 #~(" test_posix" ;multiple errors
605 " test_time"
606 " test_pty"
607 " test_shutil"
608 " test_tempfile" ;chflags: invalid argument:
609 ; tbv14c9t/dir0/dir0/dir0/test0.txt
610 " test_asyncio" ;runs over 10min
611 " test_os" ;stty: 'standard input':
612 ; Inappropriate ioctl for device
613 " test_openpty" ;No such file or directory
614 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
615 ; 32752 != 4
616 " test_compileall" ;multiple errors
617 " test_poll" ;list index out of range
618 " test_subprocess" ;runs over 10min
619 " test_asyncore" ;multiple errors
620 " test_threadsignals"
621 " test_eintr" ;Process return code is -14
622 " test_io" ;multiple errors
623 " test_logging"
624 " test_signal"
625 " test_threading" ;runs over 10min
626 " test_flags" ;ERROR
627 " test_bidirectional_pty"
628 " test_create_unix_connection"
629 " test_unix_sock_client_ops"
630 " test_open_unix_connection"
631 " test_open_unix_connection_error"
632 " test_read_pty_output"
633 " test_write_pty"
634 " test_concurrent_futures" ;freeze
635 " test_venv" ;freeze
636 " test_multiprocessing_forkserver" ;runs over 10min
637 " test_multiprocessing_spawn" ;runs over 10min
638 " test_builtin"
639 " test_capi"
640 " test_dbm_ndbm"
641 " test_exceptions"
642 " test_faulthandler"
643 " test_getopt"
644 " test_importlib"
645 " test_json"
646 " test_multiprocessing_fork"
647 " test_multiprocessing_main_handling"
648 " test_pdb "
649 " test_regrtest"
650 " test_sqlite")
651 #~())))
652 #:modules '((ice-9 ftw)
653 (ice-9 match)
654 (guix build utils)
655 (guix build gnu-build-system))
656 #:phases
657 #~(modify-phases %standard-phases
658 #$@(common-python3-phases-edits)
659 (replace 'remove-windows-binaries
660 (lambda _
661 ;; Delete .exe from embedded .whl (zip) files
662 (for-each
663 (lambda (whl)
664 (let ((dir "whl-content")
665 (circa-1980 (* 10 366 24 60 60)))
666 (mkdir-p dir)
667 (with-directory-excursion dir
668 (let ((whl (string-append "../" whl)))
669 (invoke "unzip" whl)
670 (for-each delete-file
671 (find-files "." "\\.exe$"))
672 (delete-file whl)
673
674 ;; Search for cacert.pem, delete it, and rewrite the
675 ;; file which directs python to look for it.
676 (let ((cacert (find-files "." "cacert\\.pem")))
677 (unless (null? cacert)
678 (let ((certifi (dirname (car cacert))))
679 (delete-file (string-append certifi "/cacert.pem"))
680 (delete-file (string-append certifi "/core.py"))
681 (with-output-to-file (string-append certifi "/core.py")
682 (lambda _
683 (display "\"\"\"
684certifi.py
685~~~~~~~~~~
686This file is a Guix-specific version of core.py.
687
688This module returns the installation location of SSL_CERT_FILE or
689/etc/ssl/certs/ca-certificates.crt, or its contents.
690\"\"\"
691import os
692
693_CA_CERTS = None
694
695try:
696 _CA_CERTS = os.environ [\"SSL_CERT_FILE\"]
697except:
698 _CA_CERTS = os.path.join(\"/etc\", \"ssl\", \"certs\", \"ca-certificates.crt\")
699
700def where() -> str:
701 return _CA_CERTS
702
703def contents() -> str:
704 with open(where(), \"r\", encoding=\"ascii\") as data:
705 return data.read()"))))))
706
707 ;; Reset timestamps to prevent them from ending
708 ;; up in the Zip archive.
709 (ftw "." (lambda (file stat flag)
710 (utime file circa-1980 circa-1980)
711 #t))
712 (apply invoke "zip" "-X" whl
713 (find-files "." #:directories? #t))))
714 (delete-file-recursively dir)))
715 (find-files "Lib/ensurepip" "\\.whl$"))))
716 (add-after 'install 'install-sitecustomize.py
717 #$(customize-site version)))))
718 (inputs
719 (modify-inputs (package-inputs python-2.7)
720 (replace "openssl" openssl)))
721 (native-inputs
722 (let ((inputs (modify-inputs native-inputs
723 (prepend tzdata-for-tests
724 unzip
725 (@ (gnu packages compression) zip)))))
726 (if (%current-target-system)
727 (modify-inputs inputs (prepend this-package))
728 inputs)))
729 (native-search-paths
730 (list (guix-pythonpath-search-path version)
731 ;; Used to locate tzdata by the zoneinfo module introduced in
732 ;; Python 3.9.
733 (search-path-specification
734 (variable "PYTHONTZPATH")
735 (files (list "share/zoneinfo")))))))
736
737(define-public python-3.11
738 (package
739 (inherit python-3.10)
740 (name "python")
741 (version "3.11.14")
742 (source (origin
743 (method url-fetch)
744 (uri (string-append "https://www.python.org/ftp/python/"
745 version "/Python-" version ".tar.xz"))
746 (patches (search-patches
747 "python-3-deterministic-build-info.patch"
748 "python-3.11-fix-tests.patch"
749 "python-3-hurd-configure.patch"
750 "python-3-search-paths.patch"))
751 (sha256
752 (base32
753 "0y4v42qm66nvizjxbnixh59283a54nki51jmbrgwkhc8bkndhgld"))
754 (modules '((guix build utils)))
755 (snippet
756 '(begin
757 ;; Delete the bundled copy of libexpat.
758 (delete-file-recursively "Modules/expat")
759 (substitute* "Modules/Setup"
760 ;; Link Expat instead of embedding the bundled one.
761 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
762 ;; Delete windows binaries
763 (for-each delete-file
764 (find-files "Lib/distutils/command" "\\.exe$"))))))
765 (arguments
766 (list
767 #:test-target "test"
768 #:configure-flags
769 #~(list "--enable-shared" ;allow embedding
770 "--with-system-expat" ;for XML support
771 "--with-system-ffi" ;build ctypes
772 "--with-ensurepip=install" ;install pip and setuptools
773 "--with-computed-gotos" ;main interpreter loop optimization
774 "--enable-unicode=ucs4"
775 "--without-static-libpython"
776 "--enable-loadable-sqlite-extensions"
777
778 ;; FIXME: These flags makes Python significantly faster,
779 ;; but leads to non-reproducible binaries.
780 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
781 ;; "--enable-optimizations"
782
783 ;; Prevent the installed _sysconfigdata.py from retaining
784 ;; a reference to coreutils.
785 "INSTALL=install -c"
786 "MKDIR_P=mkdir -p"
787
788 ;; Add a reference to libxcrypt in LIBS so that the
789 ;; sysconfigdata file records it and propagates it to programs
790 ;; linking against Python.
791 (let ((libxcrypt
792 (false-if-exception
793 (dirname
794 (search-input-file %build-inputs
795 "lib/libcrypt.so.1")))))
796 (string-append
797 "LIBS="
798 (if libxcrypt
799 (string-append "-L" libxcrypt)
800 "")))
801
802 ;; Disable runtime check failing if cross-compiling, see:
803 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
804 #$@(if (%current-target-system)
805 #~("ac_cv_buggy_getaddrinfo=no"
806 "ac_cv_file__dev_ptmx=no"
807 "ac_cv_file__dev_ptc=no"
808 (string-append "--with-build-python="
809 #+(this-package-native-input "python")
810 "/bin/python3"))
811 '())
812 ;; -fno-semantic-interposition reinstates some
813 ;; optimizations by gcc leading to around 15% speedup.
814 ;; This is the default starting from python 3.10.
815 "CFLAGS=-fno-semantic-interposition"
816 (string-append "LDFLAGS=-Wl,-rpath=" #$output "/lib"
817 " -fno-semantic-interposition"))
818 ;; With no -j argument tests use all available cpus, so provide one.
819 #:make-flags
820 `(list (string-append (format #f "TESTOPTS=-j~d"
821 (parallel-job-count))
822 ;; those tests fail on low-memory systems
823 " --exclude"
824 " test_mmap"
825 " test_socket"
826 " test_threading"
827 " test_asyncio"
828 " test_shutdown"
829 ,@(if (target-ppc32?)
830 '(" test_ssl")
831 '())
832 ,@(if (system-hurd?)
833 '(" test_posix" ;multiple errors
834 " test_time"
835 " test_pty"
836 " test_shutil"
837 " test_tempfile" ;chflags: invalid argument:
838 ;; tbv14c9t/dir0/dir0/dir0/test0.txt
839 " test_os" ;stty: 'standard input':
840 ;; Inappropriate ioctl for device
841 " test_openpty" ;No such file or directory
842 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
843 ;; 32752 != 4
844 " test_compileall" ;multiple errors
845 " test_poll" ;list index out of range
846 " test_subprocess" ;runs over 10min
847 " test_asyncore" ;multiple errors
848 " test_threadsignals"
849 " test_eintr" ;Process return code is -14
850 " test_io" ;multiple errors
851 " test_logging"
852 " test_signal"
853 " test_flags" ;ERROR
854 " test_bidirectional_pty"
855 " test_create_unix_connection"
856 " test_unix_sock_client_ops"
857 " test_open_unix_connection"
858 " test_open_unix_connection_error"
859 " test_read_pty_output"
860 " test_write_pty"
861 " test_concurrent_futures" ;freeze
862 " test_venv" ;freeze
863 " test_multiprocessing_forkserver" ;runs over 10min
864 " test_multiprocessing_spawn" ;runs over 10min
865 " test_glob" ;did not finish in 10h
866 " test_site" ;Invalid argument
867 " test_termios" ;os.openpty() Operation not permitted
868 " test_tty" ;os.openpty() Operation not permitted
869 " test_sqlite3" ;; sqlite3.OperationalError: database is locked
870 " test_tarfile" ;; ELOOP vs ENAMETOOLONG
871 " test_builtin"
872 " test_capi"
873 " test_dbm_ndbm"
874 " test_exceptions"
875 " test_faulthandler"
876 " test_getopt"
877 " test_importlib"
878 " test_json"
879 " test_multiprocessing_fork"
880 " test_multiprocessing_main_handling"
881 " test_pdb "
882 " test_regrtest"
883 " test_ssl" ;; Fails with openssl 3.5
884 " test_sqlite")
885 '())
886 ,@(if (system-hurd64?)
887 '(" test_largefile") ;; hangs
888 '())))
889
890 #:modules
891 '((ice-9 ftw)
892 (ice-9 match)
893 (guix build utils)
894 (guix build gnu-build-system))
895
896 #:phases
897 #~(modify-phases %standard-phases
898 #$@(common-python3-phases-edits)
899 (add-after 'install 'install-sitecustomize.py
900 #$(customize-site version)))))
901 (inputs (list bzip2
902 expat
903 gdbm
904 libffi ;for ctypes
905 libxcrypt ;crypto module slated for removal in 3.13
906 sqlite ;for sqlite extension
907 openssl
908 readline
909 zlib
910 tcl
911 tk)) ;for tkinter
912 (native-inputs `(("tzdata" ,tzdata-for-tests)
913 ("unzip" ,unzip)
914 ("zip" ,(@ (gnu packages compression) zip))
915 ("pkg-config" ,pkg-config)
916 ("sitecustomize.py" ,(local-file (search-auxiliary-file
917 "python/sitecustomize.py")))
918 ;; When cross-compiling, a native version of Python itself is needed.
919 ,@(if (%current-target-system)
920 `(("python" ,this-package)
921 ("which" ,which))
922 '())))
923 (native-search-paths
924 (list (guix-pythonpath-search-path version)
925 ;; Used to locate tzdata by the zoneinfo module introduced in
926 ;; Python 3.9.
927 (search-path-specification
928 (variable "PYTHONTZPATH")
929 (files (list "share/zoneinfo")))))))
930
931(define-public python-3.12
932 (package
933 (name "python")
934 (version "3.12.12")
935 (source
936 (origin
937 (method url-fetch)
938 (uri (string-append "https://www.python.org/ftp/python/" version
939 "/Python-" version ".tar.xz"))
940 (sha256
941 (base32 "1i2nqvnm2b7aakj2rf8qdfsk0nh55ly55gcbl6dw8a5h2hsa31gv"))
942 (patches (search-patches "python-3-deterministic-build-info.patch"
943 "python-3.12-fix-tests.patch"
944 "python-3-hurd-configure.patch"))
945 (modules '((guix build utils)))
946 (snippet '(begin
947 ;; Delete the bundled copy of libexpat.
948 (delete-file-recursively "Modules/expat")
949 (substitute* "Modules/Setup"
950 ;; Link Expat instead of embedding the bundled one.
951 (("^#pyexpat.*")
952 "pyexpat pyexpat.c -lexpat\n"))
953 ;; Delete windows binaries
954 (for-each delete-file
955 (find-files "Lib/distutils/command" "\\.exe$"))))))
956 (outputs '("out" "tk" ;tkinter; adds 50 MiB to the closure
957 "idle")) ;programming environment; weighs 5MB
958 (build-system gnu-build-system)
959 (arguments
960 (list
961 #:test-target "test"
962 #:configure-flags
963 #~(list "--enable-shared" ;allow embedding
964 "--with-system-expat" ;for XML support
965 "--with-system-ffi" ;build ctypes
966 "--with-ensurepip=install" ;install pip and setuptools
967 "--with-computed-gotos" ;main interpreter loop optimization
968 "--enable-unicode=ucs4"
969 "--without-static-libpython"
970 "--enable-loadable-sqlite-extensions"
971
972 ;; FIXME: These flags makes Python significantly faster,
973 ;; but leads to non-reproducible binaries.
974 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
975 ;; "--enable-optimizations"
976
977 ;; Prevent the installed _sysconfigdata.py from retaining
978 ;; a reference to coreutils.
979 "INSTALL=install -c"
980 "MKDIR_P=mkdir -p"
981
982 ;; Disable runtime check failing if cross-compiling, see:
983 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
984 #$@(if (%current-target-system)
985 #~("ac_cv_buggy_getaddrinfo=no"
986 "ac_cv_file__dev_ptmx=no"
987 "ac_cv_file__dev_ptc=no"
988 (string-append "--with-build-python="
989 #+(this-package-native-input "python")
990 "/bin/python3"))
991 #~())
992 ;; -fno-semantic-interposition reinstates some
993 ;; optimizations by gcc leading to around 15% speedup.
994 ;; This is the default starting from python 3.10.
995 "CFLAGS=-fno-semantic-interposition"
996 (string-append "LDFLAGS=-Wl,-rpath="
997 (assoc-ref %outputs "out")
998 "/lib"
999 " -fno-semantic-interposition"))
1000 ;; With no -j argument tests use all available cpus, so provide one.
1001 #:make-flags
1002 #~(list (string-append (format #f "TESTOPTS=-j~d"
1003 (parallel-job-count))
1004 ;; those tests fail on low-memory systems
1005 " --exclude"
1006 " test_mmap"
1007 " test_socket"
1008 " test_threading"
1009 " test_asyncio"
1010 " test_shutdown"
1011 #$@(if (target-ppc32?)
1012 #~(" test_ssl")
1013 #~())
1014 #$@(if (system-hurd?)
1015 #~(" test_posix" ;multiple errors
1016 " test_time"
1017 " test_pty"
1018 " test_shutil"
1019 " test_tempfile" ;chflags: invalid argument:
1020 ;; tbv14c9t/dir0/dir0/dir0/test0.txt
1021 " test_os" ;stty: 'standard input':
1022 ;; Inappropriate ioctl for device
1023 " test_openpty" ;No such file or directory
1024 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
1025 ;; 32752 != 4
1026 " test_compileall" ;multiple errors
1027 " test_poll" ;list index out of range
1028 " test_subprocess" ;runs over 10min
1029 " test_asyncore" ;multiple errors
1030 " test_threadsignals"
1031 " test_eintr" ;Process return code is -14
1032 " test_io" ;multiple errors
1033 " test_logging"
1034 " test_signal"
1035 " test_flags" ;ERROR
1036 " test_bidirectional_pty"
1037 " test_create_unix_connection"
1038 " test_unix_sock_client_ops"
1039 " test_open_unix_connection"
1040 " test_open_unix_connection_error"
1041 " test_read_pty_output"
1042 " test_write_pty"
1043 " test_concurrent_futures" ;freeze
1044 " test_venv" ;freeze
1045 " test_multiprocessing_forkserver" ;runs over 10min
1046 " test_multiprocessing_spawn" ;runs over 10min
1047 " test_glob" ;did not finish in 10h
1048 " test_site" ;Invalid argument
1049 " test_termios" ;os.openpty() Operation not permitted
1050 " test_tty" ;os.openpty() Operation not permitted
1051 " test_sqlite3" ;; sqlite3.OperationalError: database is locked
1052 " test_tarfile" ;; ELOOP vs ENAMETOOLONG
1053 " test_builtin"
1054 " test_capi"
1055 " test_dbm_ndbm"
1056 " test_exceptions"
1057 " test_faulthandler"
1058 " test_getopt"
1059 " test_importlib"
1060 " test_json"
1061 " test_multiprocessing_fork"
1062 " test_multiprocessing_main_handling"
1063 " test_pdb "
1064 " test_regrtest"
1065 " test_ssl" ;; Fails with openssl 3.5
1066 " test_sqlite")
1067 #~())
1068 #$@(if (system-hurd64?)
1069 #~(" test_largefile") ;; hangs
1070 #~())))
1071
1072 #:modules '((ice-9 ftw)
1073 (ice-9 match)
1074 (guix build utils)
1075 (guix build gnu-build-system))
1076
1077 #:phases
1078 #~(modify-phases %standard-phases
1079 #$@(common-python3-phases-edits)
1080 (add-after 'install 'install-sitecustomize.py
1081 #$(customize-site version)))))
1082 (inputs (list bzip2
1083 expat
1084 gdbm
1085 libffi ;for ctypes
1086 sqlite ;for sqlite extension
1087 openssl
1088 readline
1089 zlib
1090 tcl
1091 tk)) ;for tkinter
1092 (native-inputs `(("tzdata" ,tzdata-for-tests)
1093 ("unzip" ,unzip)
1094 ("zip" ,(@ (gnu packages compression) zip))
1095 ("pkg-config" ,pkg-config)
1096 ("sitecustomize.py" ,(local-file (search-auxiliary-file
1097 "python/sitecustomize.py")))
1098 ;; When cross-compiling, a native version of Python itself is needed.
1099 ,@(if (%current-target-system)
1100 `(("python" ,this-package)
1101 ("which" ,which))
1102 '())))
1103 (native-search-paths
1104 (list (guix-pythonpath-search-path version)
1105 ;; Used to locate tzdata by the zoneinfo module introduced in
1106 ;; Python 3.9.
1107 (search-path-specification
1108 (variable "PYTHONTZPATH")
1109 (files (list "share/zoneinfo")))))
1110 (home-page "https://www.python.org")
1111 (synopsis "High-level, dynamically-typed programming language")
1112 (description
1113 "Python is a remarkably powerful dynamic programming language that
1114is used in a wide variety of application domains. Some of its key
1115distinguishing features include: clear, readable syntax; strong
1116introspection capabilities; intuitive object orientation; natural
1117expression of procedural code; full modularity, supporting hierarchical
1118packages; exception-based error handling; and very high level dynamic
1119data types.")
1120 (properties '((cpe-name . "python")
1121 (cpe-vendor . "python")))
1122 (license license:psfl)))
1123
1124(define-public python-3.13
1125 (package
1126 (name "python-next")
1127 (version "3.13.13")
1128 (source
1129 (origin
1130 (method url-fetch)
1131 (uri (string-append "https://www.python.org/ftp/python/" version
1132 "/Python-" version ".tar.xz"))
1133 (sha256
1134 (base32 "0wcanwlkfy91hhpsgx9b1vbdyywm5s40rlbm9ykcqg3q07s1zf9a"))
1135 (patches (search-patches "python-3-deterministic-build-info.patch"
1136 "python-3.13-fix-tests.patch"
1137 "python-3-hurd-configure.patch"))
1138 (modules '((guix build utils)))
1139 (snippet '(begin
1140 ;; Delete the bundled copy of libexpat.
1141 (delete-file-recursively "Modules/expat")
1142 (substitute* "Modules/Setup"
1143 ;; Link Expat instead of embedding the bundled one.
1144 (("^#pyexpat.*")
1145 "pyexpat pyexpat.c -lexpat\n"))
1146 ;; Delete windows binaries
1147 (for-each delete-file
1148 (find-files "Lib/distutils/command" "\\.exe$"))))))
1149 (outputs '("out" "tk" ;tkinter; adds 50 MiB to the closure
1150 "idle")) ;programming environment; weighs 5MB
1151 (build-system gnu-build-system)
1152 (arguments
1153 (list
1154 #:test-target "test"
1155 #:configure-flags
1156 #~(list "--enable-shared" ;allow embedding
1157 "--with-system-expat" ;for XML support
1158 "--with-system-ffi" ;build ctypes
1159 "--with-ensurepip=install" ;install pip and setuptools
1160 "--with-computed-gotos" ;main interpreter loop optimization
1161 "--enable-unicode=ucs4"
1162 "--without-static-libpython"
1163 "--enable-loadable-sqlite-extensions"
1164
1165 ;; FIXME: These flags makes Python significantly faster,
1166 ;; but leads to non-reproducible binaries.
1167 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
1168 ;; "--enable-optimizations"
1169
1170 ;; Prevent the installed _sysconfigdata.py from retaining
1171 ;; a reference to coreutils.
1172 "INSTALL=install -c"
1173 "MKDIR_P=mkdir -p"
1174
1175 ;; Disable runtime check failing if cross-compiling, see:
1176 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
1177 #$@(if (%current-target-system)
1178 #~("ac_cv_buggy_getaddrinfo=no"
1179 "ac_cv_file__dev_ptmx=no"
1180 "ac_cv_file__dev_ptc=no"
1181 (string-append "--with-build-python="
1182 #+(this-package-native-input "python")
1183 "/bin/python3"))
1184 #~())
1185 ;; -fno-semantic-interposition reinstates some
1186 ;; optimizations by gcc leading to around 15% speedup.
1187 ;; This is the default starting from python 3.10.
1188 "CFLAGS=-fno-semantic-interposition"
1189 (string-append "LDFLAGS=-Wl,-rpath="
1190 (assoc-ref %outputs "out")
1191 "/lib"
1192 " -fno-semantic-interposition"))
1193 ;; With no -j argument tests use all available cpus, so provide one.
1194 #:make-flags
1195 #~(list (string-append (format #f "TESTOPTS=-j~d"
1196 (parallel-job-count))
1197 ;; those tests fail on low-memory systems
1198 " --exclude"
1199 " test_mmap"
1200 " test_socket"
1201 " test_threading"
1202 " test_asyncio"
1203 " test_shutdown"
1204 #$@(if (target-ppc32?)
1205 #~(" test_ssl")
1206 #~())
1207 #$@(if (system-hurd?)
1208 #~(" test_posix" ;multiple errors
1209 " test_time"
1210 " test_pty"
1211 " test_shutil"
1212 " test_tempfile" ;chflags: invalid argument:
1213 ;; tbv14c9t/dir0/dir0/dir0/test0.txt
1214 " test_os" ;stty: 'standard input':
1215 ;; Inappropriate ioctl for device
1216 " test_openpty" ;No such file or directory
1217 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
1218 ;; 32752 != 4
1219 " test_compileall" ;multiple errors
1220 " test_poll" ;list index out of range
1221 " test_subprocess" ;runs over 10min
1222 " test_asyncore" ;multiple errors
1223 " test_threadsignals"
1224 " test_eintr" ;Process return code is -14
1225 " test_io" ;multiple errors
1226 " test_logging"
1227 " test_signal"
1228 " test_flags" ;ERROR
1229 " test_bidirectional_pty"
1230 " test_create_unix_connection"
1231 " test_unix_sock_client_ops"
1232 " test_open_unix_connection"
1233 " test_open_unix_connection_error"
1234 " test_read_pty_output"
1235 " test_write_pty"
1236 " test_concurrent_futures" ;freeze
1237 " test_venv" ;freeze
1238 " test_multiprocessing_forkserver" ;runs over 10min
1239 " test_multiprocessing_spawn" ;runs over 10min
1240 " test_glob" ;did not finish in 10h
1241 " test_site" ;Invalid argument
1242 " test_termios" ;os.openpty() Operation not permitted
1243 " test_tty" ;os.openpty() Operation not permitted
1244 " test_sqlite3" ;; sqlite3.OperationalError: database is locked
1245 " test_tarfile" ;; ELOOP vs ENAMETOOLONG
1246 " test_builtin"
1247 " test_capi"
1248 " test_dbm_ndbm"
1249 " test_exceptions"
1250 " test_faulthandler"
1251 " test_getopt"
1252 " test_importlib"
1253 " test_json"
1254 " test_multiprocessing_fork"
1255 " test_multiprocessing_main_handling"
1256 " test_pdb "
1257 " test_regrtest"
1258 " test_ssl" ;; Fails with openssl 3.5
1259 " test_sqlite")
1260 #~())
1261 #$@(if (system-hurd64?)
1262 #~(" test_largefile") ;; hangs
1263 #~())))
1264
1265 #:modules '((ice-9 ftw)
1266 (ice-9 match)
1267 (guix build utils)
1268 (guix build gnu-build-system))
1269
1270 #:phases
1271 #~(modify-phases %standard-phases
1272 #$@(common-python3-phases-edits)
1273 (add-after 'install 'install-sitecustomize.py
1274 #$(customize-site version)))))
1275 (inputs (list bzip2
1276 expat
1277 gdbm
1278 libffi ;for ctypes
1279 sqlite ;for sqlite extension
1280 openssl
1281 readline
1282 zlib
1283 tcl
1284 tk)) ;for tkinter
1285 (native-inputs `(("tzdata" ,tzdata-for-tests)
1286 ("unzip" ,unzip)
1287 ("zip" ,(@ (gnu packages compression) zip))
1288 ("pkg-config" ,pkg-config)
1289 ("sitecustomize.py" ,(local-file (search-auxiliary-file
1290 "python/sitecustomize.py")))
1291 ;; When cross-compiling, a native version of Python itself is needed.
1292 ,@(if (%current-target-system)
1293 `(("python" ,this-package)
1294 ("which" ,which))
1295 '())))
1296 (native-search-paths
1297 (list (guix-pythonpath-search-path version)
1298 ;; Used to locate tzdata by the zoneinfo module introduced in
1299 ;; Python 3.9.
1300 (search-path-specification
1301 (variable "PYTHONTZPATH")
1302 (files (list "share/zoneinfo")))))
1303 (home-page "https://www.python.org")
1304 (synopsis "High-level, dynamically-typed programming language")
1305 (description
1306 "Python is a remarkably powerful dynamic programming language that
1307is used in a wide variety of application domains. Some of its key
1308distinguishing features include: clear, readable syntax; strong
1309introspection capabilities; intuitive object orientation; natural
1310expression of procedural code; full modularity, supporting hierarchical
1311packages; exception-based error handling; and very high level dynamic
1312data types.")
1313 (properties '((cpe-name . "python")
1314 (cpe-vendor . "python")))
1315 (license license:psfl)))
1316
1317;; Next 3.x version.
1318;; Make sure that the name of the package is altered as well to avoid
1319;; conflicts, see: <https://codeberg.org/guix/guix/issues/9255>.
1320(define-public python-next python-3.13)
1321
1322;; Current 3.x version.
1323(define-public python-3 python-3.12)
1324
1325;; Current major version.
1326(define-public python python-3)
1327
1328;; Minimal variant of Python, mostly used to break the cycle between Tk and
1329;; Python (Tk -> libxcb -> Python.)
1330
1331(define-public python-minimal
1332 (package/inherit python
1333 (name "python-minimal")
1334 (outputs '("out"))
1335
1336 ;; Build fails due to missing ctypes without libffi.
1337 ;; OpenSSL is a mandatory dependency of Python 3.x, for urllib;
1338 ;; zlib is required by 'zipimport', used by pip. Expat is needed
1339 ;; for XML support, which is generally expected to be available.
1340 (inputs (list expat libffi openssl zlib))))
1341
1342(define-public python-debug
1343 (package/inherit python
1344 (name "python-debug")
1345 (outputs '("out" "debug"))
1346 (build-system gnu-build-system)
1347 (arguments
1348 (substitute-keyword-arguments arguments
1349 ((#:configure-flags configure-flags)
1350 #~(append #$configure-flags
1351 (list "--with-pydebug")))))
1352 (synopsis "Python with the debug hooks enabled")
1353 (description
1354 "This variant of Python provides an interpreter built with
1355@code{--with-pydebug} to help develop and debug extensions. See
1356@url{https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug.html},
1357for more information.")))
1358
1359(define* (wrap-python3 python
1360 #:optional
1361 (name (string-append (package-name python) "-wrapper")))
1362 (package/inherit python
1363 (name name)
1364 (source #f)
1365 (build-system trivial-build-system)
1366 (outputs '("out"))
1367 (inputs `(("bash" ,bash)))
1368 (propagated-inputs `(("python" ,python)))
1369 (arguments
1370 (list #:modules '((guix build utils))
1371 #:builder
1372 #~(begin
1373 (use-modules (guix build utils))
1374 (let ((bin (string-append #$output "/bin"))
1375 (python (string-append
1376 ;; XXX: '%build-inputs' contains the native
1377 ;; Python when cross-compiling.
1378 #$(if (%current-target-system)
1379 (this-package-input "python")
1380 #~(assoc-ref %build-inputs "python"))
1381 "/bin/")))
1382 (mkdir-p bin)
1383 (for-each
1384 (lambda (old new)
1385 (symlink (string-append python old)
1386 (string-append bin "/" new)))
1387 `("python3" ,"pydoc3" ,"pip3")
1388 `("python" ,"pydoc" ,"pip"))
1389 ;; python-config outputs search paths based upon its location,
1390 ;; use a bash wrapper to avoid changing its outputs.
1391 (let ((bash (string-append (assoc-ref %build-inputs "bash")
1392 "/bin/bash"))
1393 (old (string-append python "python3-config"))
1394 (new (string-append bin "/python-config")))
1395 (with-output-to-file new
1396 (lambda ()
1397 (format #t "#!~a~%" bash)
1398 (format #t "exec \"~a\" \"$@\"~%" old)
1399 (chmod new #o755))))))))
1400 (synopsis "Wrapper for the Python 3 commands")
1401 (description
1402 "This package provides wrappers for the commands of Python@tie{}3.x such
1403that they can also be invoked under their usual names---e.g., @command{python}
1404instead of @command{python3} or @command{pip} instead of @command{pip3}.
1405
1406To function properly, this package should not be installed together with the
1407@code{python} package: this package uses the @code{python} package as a
1408propagated input, so installing this package already makes both the versioned
1409and the unversioned commands available.")))
1410
1411(define-public python-wrapper (wrap-python3 python))
1412(define-public python-minimal-wrapper (wrap-python3 python-minimal))
1413
1414;; The Python used in pyproject-build-system.
1415(define-public python-sans-pip
1416 (hidden-package
1417 (package/inherit python
1418 (arguments
1419 (substitute-keyword-arguments arguments
1420 ((#:configure-flags flags #~())
1421 #~(append '("--with-ensurepip=no")
1422 (delete "--with-ensurepip=install" #$flags))))))))
1423
1424(define-public python-sans-pip-wrapper
1425 (wrap-python3 python-sans-pip))
1426
1427(define-public pythoncapi-compat
1428 ;; No release nor tags: use the latest commit.
1429 (let ((commit "ab72af8b1a9adfccb3578eea8e9b6d5c6449f409")
1430 (revision "1"))
1431 (package
1432 (name "pythoncapi-compat")
1433 (version (git-version "0.0.0" revision commit))
1434 (source (origin
1435 (method git-fetch)
1436 (uri (git-reference
1437 (url "https://github.com/python/pythoncapi-compat")
1438 (commit commit)))
1439 (file-name (git-file-name name version))
1440 (sha256
1441 (base32
1442 "0dfzfs399ik10125kvs5s8rid93lm50wray8s7b8bv90a61zjxiv"))))
1443 (build-system copy-build-system)
1444 (arguments (list #:install-plan
1445 #~'(("pythoncapi_compat.h" "include/"))))
1446 (home-page "https://github.com/python/pythoncapi-compat")
1447 (synopsis "Python C API compatibility")
1448 (description "The pythoncapi-compat project can be used to write a C or
1449C++ extension supporting a wide range of Python versions with a single code
1450base, via the @file{pythoncapi_compat.h} header file.")
1451 (license license:bsd-0))))
1452
1453(define-public micropython
1454 (package
1455 (name "micropython")
1456 (version "1.28.0")
1457 (source
1458 (origin
1459 (method url-fetch)
1460 (uri (string-append "https://github.com/micropython/micropython/"
1461 "releases/download/v" version
1462 "/micropython-" version ".tar.xz"))
1463 (sha256
1464 (base32 "05d2gd3g8v3paxf4fin4cv5scgnc4yl0jdahpjs37nmqaybcahsf"))
1465 (modules '((guix build utils)))
1466 (snippet
1467 '(begin
1468 (delete-file-recursively "ports/cc3200/FreeRTOS")
1469 (with-directory-excursion "lib"
1470 ;; TODO: Unbundle axtls and berkley-db-1.xx
1471 (for-each delete-file-recursively
1472 '("libffi" "lwip" "stm32lib" "nrfx")))))))
1473 (build-system gnu-build-system)
1474 (arguments
1475 (list #:phases
1476 #~(modify-phases %standard-phases
1477 (add-before 'build 'build-mpy-cross
1478 (lambda* (#:key make-flags #:allow-other-keys)
1479 (with-directory-excursion "mpy-cross"
1480 (apply invoke "make" make-flags))))
1481 (add-after 'build-mpy-cross 'prepare-build
1482 (lambda _
1483 (chdir "ports/unix")
1484 ;; see: https://github.com/micropython/micropython/pull/4246
1485 (substitute* "Makefile"
1486 (("-Os") "-Os -ffp-contract=off"))))
1487 (add-before 'install-license-files 'chdir-back
1488 ;; We don't build in the root directory so the file isn't found.
1489 (lambda _
1490 (chdir "../..")))
1491 (delete 'configure)) ; no configure
1492 #:make-flags
1493 #~(list (string-append "PREFIX=" #$output)
1494 "V=1")
1495 #:test-target "test"))
1496 (native-inputs (list pkg-config python-wrapper))
1497 (inputs
1498 (list libffi))
1499 (home-page "https://micropython.org/")
1500 (synopsis "Python implementation for microcontrollers and constrained systems")
1501 (description "MicroPython is a lean and efficient implementation of the
1502Python 3 programming language that includes a small subset of the Python
1503standard library and is optimised to run on microcontrollers and in constrained
1504environments. MicroPython is packed full of advanced features such as an
1505interactive prompt, arbitrary precision integers, closures, list comprehension,
1506generators, exception handling and more. Still it is compact enough to fit and
1507run within just 256k of code space and 16k of RAM. MicroPython aims to be as
1508compatible with normal Python as possible to allow you to transfer code with
1509ease from the desktop to a microcontroller or embedded system.")
1510 (license license:expat)))