summaryrefslogtreecommitdiff
path: root/gnu/packages/python.scm
diff options
context:
space:
mode:
authorJanneke Nieuwenhuizen <janneke@gnu.org>2024-12-31 20:05:35 +0100
committerAndreas Enge <andreas@enge.fr>2025-07-18 20:17:19 +0200
commit83e3aa22a8db2c4e97d6823bf90e5542f4df04de (patch)
tree3b55b51b94de0508a9e3c5d6a231a98d590491e7 /gnu/packages/python.scm
parent398d64f8298a5572195319cd384c5412efbb336c (diff)
gnu: python: Use G-Expressions.
* gnu/packages/python.scm (python-2.7)[arguments]: Use G-Expressions. (python-3.10): Likewise, update accordingly. (python-3.12): Likewise, update accordingly. (python-debug): Likewise, update accordingly. Change-Id: Iacb6f94fc6fb8ab70932321bc516a230c1c1003b
Diffstat (limited to 'gnu/packages/python.scm')
-rw-r--r--gnu/packages/python.scm1358
1 files changed, 684 insertions, 674 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index dccd3cdd0e5..3b1d91ed4c5 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -56,7 +56,7 @@
56;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com> 56;;; Copyright © 2018 Luther Thompson <lutheroto@gmail.com>
57;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org> 57;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
58;;; Copyright © 2019, 2024 Tanguy Le Carrour <tanguy@bioneland.org> 58;;; Copyright © 2019, 2024 Tanguy Le Carrour <tanguy@bioneland.org>
59;;; Copyright © 2020, 2023 Janneke Nieuwenhuizen <janneke@gnu.org> 59;;; Copyright © 2020, 2023, 2025 Janneke Nieuwenhuizen <janneke@gnu.org>
60;;; Copyright © 2020, 2021 Greg Hogan <code@greghogan.com> 60;;; Copyright © 2020, 2021 Greg Hogan <code@greghogan.com>
61;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com> 61;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
62;;; Copyright © 2022 jgart <jgart@dismail.de> 62;;; Copyright © 2022 jgart <jgart@dismail.de>
@@ -180,247 +180,250 @@
180 "idle")) ;programming environment; weighs 5MB 180 "idle")) ;programming environment; weighs 5MB
181 (build-system gnu-build-system) 181 (build-system gnu-build-system)
182 (arguments 182 (arguments
183 `(#:test-target "test" 183 (list
184 #:configure-flags 184 #:test-target "test"
185 (list "--enable-shared" ;allow embedding 185 #:configure-flags
186 "--with-system-expat" ;for XML support 186 #~(list "--enable-shared" ;allow embedding
187 "--with-system-ffi" ;build ctypes 187 "--with-system-expat" ;for XML support
188 "--with-ensurepip=install" ;install pip and setuptools 188 "--with-system-ffi" ;build ctypes
189 "--with-computed-gotos" ;main interpreter loop optimization 189 "--with-ensurepip=install" ;install pip and setuptools
190 "--enable-unicode=ucs4" 190 "--with-computed-gotos" ;main interpreter loop optimization
191 "--enable-unicode=ucs4"
191 192
192 ;; FIXME: These flags makes Python significantly faster, but 193 ;; FIXME: These flags makes Python significantly faster, but
193 ;; leads to non-reproducible binaries. 194 ;; leads to non-reproducible binaries.
194 ;; "--with-lto" ;increase size by 20MB, but 15% speedup 195 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
195 ;; "--enable-optimizations" 196 ;; "--enable-optimizations"
196 197
197 ;; Prevent the installed _sysconfigdata.py from retaining a reference 198 ;; Prevent the installed _sysconfigdata.py from retaining a reference
198 ;; to coreutils. 199 ;; to coreutils.
199 "INSTALL=install -c" 200 "INSTALL=install -c"
200 "MKDIR_P=mkdir -p" 201 "MKDIR_P=mkdir -p"
201 202
202 ;; Disable runtime check failing if cross-compiling, see: 203 ;; Disable runtime check failing if cross-compiling, see:
203 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html 204 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
204 ,@(if (%current-target-system) 205 #$@(if (%current-target-system)
205 '("ac_cv_buggy_getaddrinfo=no" 206 #~("ac_cv_buggy_getaddrinfo=no"
206 "ac_cv_file__dev_ptmx=no" 207 "ac_cv_file__dev_ptmx=no"
207 "ac_cv_file__dev_ptc=no") 208 "ac_cv_file__dev_ptc=no")
208 '()) 209 #~())
209 ;; -fno-semantic-interposition reinstates some optimizations by gcc 210 ;; -fno-semantic-interposition reinstates some optimizations by gcc
210 ;; leading to around 15% speedup. This is the default starting from 211 ;; leading to around 15% speedup. This is the default starting from
211 ;; python 3.10. 212 ;; python 3.10.
212 "CFLAGS=-fno-semantic-interposition" 213 "CFLAGS=-fno-semantic-interposition"
213 (string-append "LDFLAGS=-Wl,-rpath=" 214 (string-append "LDFLAGS=-Wl,-rpath="
214 (assoc-ref %outputs "out") "/lib" 215 (assoc-ref %outputs "out") "/lib"
215 " -fno-semantic-interposition") 216 " -fno-semantic-interposition")
216 ;; Add a reference to libxcrypt in LIBS so that the sysconfigdata 217 ;; Add a reference to libxcrypt in LIBS so that the sysconfigdata
217 ;; file records it and propagates it to programs linking against 218 ;; file records it and propagates it to programs linking against
218 ;; Python. 219 ;; Python.
219 (let ((libxcrypt 220 (let ((libxcrypt
220 (false-if-exception 221 (false-if-exception
221 (dirname 222 (dirname
222 (search-input-file %build-inputs 223 (search-input-file %build-inputs
223 "lib/libcrypt.so.1"))))) 224 "lib/libcrypt.so.1")))))
224 (string-append 225 (string-append
225 "LIBS=" 226 "LIBS="
226 (if libxcrypt 227 (if libxcrypt
227 (string-append "-L" libxcrypt) 228 (string-append "-L" libxcrypt)
228 "")))) 229 ""))))
229 ;; With no -j argument tests use all available cpus, so provide one. 230 ;; With no -j argument tests use all available cpus, so provide one.
230 #:make-flags 231 #:make-flags
231 (list (string-append 232 #~(list (string-append
232 (format #f "TESTOPTS=-j~d" (parallel-job-count)) 233 (format #f "TESTOPTS=-j~d" (parallel-job-count))
233 ;; Exclude the following tests as they fail 234 ;; Exclude the following tests as they fail
234 ;; non-deterministically with "error: [Errno 104] Connection 235 ;; non-deterministically with "error: [Errno 104] Connection
235 ;; reset by peer." Python 3 seems unaffected. A potential fix, 236 ;; reset by peer." Python 3 seems unaffected. A potential fix,
236 ;; yet to be backported to Python 2, is available at: 237 ;; yet to be backported to Python 2, is available at:
237 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918. 238 ;; https://github.com/python/cpython/commit/529525fb5a8fd9b96ab4021311a598c77588b918.
238 " --exclude test_urllib2_localnet test_httplib")) 239 " --exclude test_urllib2_localnet test_httplib"))
239 240
240 #:modules ((ice-9 ftw) (ice-9 match) 241 #:modules '((ice-9 ftw)
241 (guix build utils) (guix build gnu-build-system)) 242 (ice-9 match)
242 #:phases 243 (guix build utils)
243 (modify-phases %standard-phases 244 (guix build gnu-build-system))
244 (add-before 245 #:phases
245 'configure 'patch-lib-shells 246 #~(modify-phases %standard-phases
246 (lambda _ 247 (add-before
247 ;; This variable is used in setup.py to enable cross compilation 248 'configure 'patch-lib-shells
248 ;; specific switches. As it is not set properly by configure 249 (lambda _
249 ;; script, set it manually. 250 ;; This variable is used in setup.py to enable cross compilation
250 ,@(if (%current-target-system) 251 ;; specific switches. As it is not set properly by configure
251 '((setenv "_PYTHON_HOST_PLATFORM" "")) 252 ;; script, set it manually.
252 '()) 253 #$@(if (%current-target-system)
253 ;; Filter for existing files, since some may not exist in all 254 #~((setenv "_PYTHON_HOST_PLATFORM" ""))
254 ;; versions of python that are built with this recipe. 255 #~())
255 (substitute* (filter file-exists? 256 ;; Filter for existing files, since some may not exist in all
256 '("Lib/subprocess.py" 257 ;; versions of python that are built with this recipe.
257 "Lib/popen2.py" 258 (substitute* (filter file-exists?
258 "Lib/distutils/tests/test_spawn.py" 259 '("Lib/subprocess.py"
259 "Lib/test/support/__init__.py" 260 "Lib/popen2.py"
260 "Lib/test/test_subprocess.py")) 261 "Lib/distutils/tests/test_spawn.py"
261 (("/bin/sh") (which "sh"))))) 262 "Lib/test/support/__init__.py"
262 ,@(if (system-hurd?) 263 "Lib/test/test_subprocess.py"))
263 `((add-before 'build 'patch-regen-for-hurd 264 (("/bin/sh") (which "sh")))))
264 (lambda* (#:key inputs #:allow-other-keys) 265 #$@(if (system-hurd?)
265 (let ((libc (assoc-ref inputs "libc"))) 266 #~((add-before 'build 'patch-regen-for-hurd
266 (substitute* "Lib/plat-generic/regen" 267 (lambda* (#:key inputs #:allow-other-keys)
267 (("/usr/include/") (string-append libc "/include/"))))))) 268 (let ((libc (assoc-ref inputs "libc")))
268 '()) 269 (substitute* "Lib/plat-generic/regen"
269 (add-before 'configure 'do-not-record-configure-flags 270 (("/usr/include/") (string-append libc "/include/")))))))
270 (lambda* (#:key configure-flags #:allow-other-keys) 271 #~())
271 ;; Remove configure flags from the installed '_sysconfigdata.py' 272 (add-before 'configure 'do-not-record-configure-flags
272 ;; and 'Makefile' so we don't end up keeping references to the 273 (lambda* (#:key configure-flags #:allow-other-keys)
273 ;; build tools. 274 ;; Remove configure flags from the installed '_sysconfigdata.py'
274 ;; 275 ;; and 'Makefile' so we don't end up keeping references to the
275 ;; Preserve at least '--with-system-ffi' since otherwise the 276 ;; build tools.
276 ;; thing tries to build libffi, fails, and we end up with a 277 ;;
277 ;; Python that lacks ctypes. 278 ;; Preserve at least '--with-system-ffi' since otherwise the
278 (substitute* "configure" 279 ;; thing tries to build libffi, fails, and we end up with a
279 (("^CONFIG_ARGS=.*$") 280 ;; Python that lacks ctypes.
280 (format #f "CONFIG_ARGS='~a'\n" 281 (substitute* "configure"
281 (if (member "--with-system-ffi" configure-flags) 282 (("^CONFIG_ARGS=.*$")
282 "--with-system-ffi" 283 (format #f "CONFIG_ARGS='~a'\n"
283 "")))))) 284 (if (member "--with-system-ffi" configure-flags)
284 (add-before 'check 'pre-check 285 "--with-system-ffi"
285 (lambda _ 286 ""))))))
286 ;; 'Lib/test/test_site.py' needs a valid $HOME 287 (add-before 'check 'pre-check
287 (setenv "HOME" (getcwd)))) 288 (lambda _
288 (add-after 'unpack 'set-source-file-times-to-1980 289 ;; 'Lib/test/test_site.py' needs a valid $HOME
289 ;; XXX One of the tests uses a ZIP library to pack up some of the 290 (setenv "HOME" (getcwd))))
290 ;; source tree, and fails with "ZIP does not support timestamps 291 (add-after 'unpack 'set-source-file-times-to-1980
291 ;; before 1980". Work around this by setting the file times in the 292 ;; XXX One of the tests uses a ZIP library to pack up some of the
292 ;; source tree to sometime in early 1980. 293 ;; source tree, and fails with "ZIP does not support timestamps
293 (lambda _ 294 ;; before 1980". Work around this by setting the file times in the
294 (let ((circa-1980 (* 10 366 24 60 60))) 295 ;; source tree to sometime in early 1980.
295 (ftw "." (lambda (file stat flag) 296 (lambda _
296 (utime file circa-1980 circa-1980) 297 (let ((circa-1980 (* 10 366 24 60 60)))
297 #t))))) 298 (ftw "." (lambda (file stat flag)
298 (add-after 'install 'remove-tests 299 (utime file circa-1980 circa-1980)
299 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.* 300 #t)))))
300 ;; because these files are used by some libraries out there. 301 (add-after 'install 'remove-tests
301 (lambda* (#:key outputs #:allow-other-keys) 302 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
302 (let ((out (assoc-ref outputs "out"))) 303 ;; because these files are used by some libraries out there.
303 (match (scandir (string-append out "/lib") 304 (lambda* (#:key outputs #:allow-other-keys)
304 (lambda (name) 305 (let ((out (assoc-ref outputs "out")))
305 (string-prefix? "python" name))) 306 (match (scandir (string-append out "/lib")
306 ((pythonX.Y) 307 (lambda (name)
307 (let ((testdir (string-append out "/lib/" pythonX.Y 308 (string-prefix? "python" name)))
308 "/test"))) 309 ((pythonX.Y)
309 (with-directory-excursion testdir 310 (let ((testdir (string-append out "/lib/" pythonX.Y
310 (for-each delete-file-recursively 311 "/test")))
311 (scandir testdir 312 (with-directory-excursion testdir
312 (match-lambda 313 (for-each delete-file-recursively
313 ((or "." "..") #f) 314 (scandir testdir
314 ("support" #f) 315 (match-lambda
315 (file 316 ((or "." "..") #f)
316 (not 317 ("support" #f)
317 (string-prefix? "test_support." 318 (file
318 file)))))) 319 (not
319 (call-with-output-file "__init__.py" (const #t)))) 320 (string-prefix? "test_support."
320 (let ((libdir (string-append out "/lib/" pythonX.Y))) 321 file))))))
321 (for-each 322 (call-with-output-file "__init__.py" (const #t))))
322 (lambda (directory) 323 (let ((libdir (string-append out "/lib/" pythonX.Y)))
323 (let ((dir (string-append libdir "/" directory))) 324 (for-each
324 (when (file-exists? dir) 325 (lambda (directory)
325 (delete-file-recursively dir)))) 326 (let ((dir (string-append libdir "/" directory)))
326 '("email/test" "ctypes/test" "unittest/test" "tkinter/test" 327 (when (file-exists? dir)
327 "sqlite3/test" "bsddb/test" "lib-tk/test" "json/tests" 328 (delete-file-recursively dir))))
328 "distutils/tests")))))))) 329 '("email/test" "ctypes/test" "unittest/test" "tkinter/test"
329 (add-after 'install 'add-libxcrypt-reference-pkgconfig 330 "sqlite3/test" "bsddb/test" "lib-tk/test" "json/tests"
330 (lambda* (#:key inputs outputs #:allow-other-keys) 331 "distutils/tests"))))))))
331 (define out (assoc-ref outputs "out")) 332 (add-after 'install 'add-libxcrypt-reference-pkgconfig
332 (define libxcrypt 333 (lambda* (#:key inputs outputs #:allow-other-keys)
333 (false-if-exception 334 (define out (assoc-ref outputs "out"))
334 (dirname (search-input-file inputs "lib/libcrypt.so.1")))) 335 (define libxcrypt
335 (when libxcrypt 336 (false-if-exception
336 (substitute* 337 (dirname (search-input-file inputs "lib/libcrypt.so.1"))))
337 (find-files (string-append out "/lib/pkgconfig") 338 (when libxcrypt
338 ".*\\.pc") 339 (substitute*
339 (("-lcrypt") 340 (find-files (string-append out "/lib/pkgconfig")
340 (string-append "-L" libxcrypt " -lcrypt")))))) 341 ".*\\.pc")
341 (add-after 'remove-tests 'move-tk-inter 342 (("-lcrypt")
342 (lambda* (#:key outputs #:allow-other-keys) 343 (string-append "-L" libxcrypt " -lcrypt"))))))
343 ;; When Tkinter support is built move it to a separate output so 344 (add-after 'remove-tests 'move-tk-inter
344 ;; that the main output doesn't contain a reference to Tcl/Tk. 345 (lambda* (#:key outputs #:allow-other-keys)
345 (let ((out (assoc-ref outputs "out")) 346 ;; When Tkinter support is built move it to a separate output so
346 (tk (assoc-ref outputs "tk"))) 347 ;; that the main output doesn't contain a reference to Tcl/Tk.
347 (when tk 348 (let ((out (assoc-ref outputs "out"))
348 (match (find-files out "tkinter.*\\.so") 349 (tk (assoc-ref outputs "tk")))
349 ((tkinter.so) 350 (when tk
350 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we 351 (match (find-files out "tkinter.*\\.so")
351 ;; want it under TK/lib/pythonX.Y/site-packages. 352 ((tkinter.so)
352 (let* ((len (string-length out)) 353 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
353 (target (string-append 354 ;; want it under TK/lib/pythonX.Y/site-packages.
354 tk "/" 355 (let* ((len (string-length out))
355 (string-drop 356 (target (string-append
356 (dirname (dirname tkinter.so)) 357 tk "/"
357 len) 358 (string-drop
358 "/site-packages"))) 359 (dirname (dirname tkinter.so))
359 (install-file tkinter.so target) 360 len)
360 (delete-file tkinter.so)))))))) 361 "/site-packages")))
361 (add-after 'move-tk-inter 'move-idle 362 (install-file tkinter.so target)
362 (lambda* (#:key outputs #:allow-other-keys) 363 (delete-file tkinter.so))))))))
363 ;; when idle is built, move it to a separate output to save some 364 (add-after 'move-tk-inter 'move-idle
364 ;; space (5MB) 365 (lambda* (#:key outputs #:allow-other-keys)
365 (let ((out (assoc-ref outputs "out")) 366 ;; when idle is built, move it to a separate output to save some
366 (idle (assoc-ref outputs "idle"))) 367 ;; space (5MB)
367 (when idle 368 (let ((out (assoc-ref outputs "out"))
368 (for-each 369 (idle (assoc-ref outputs "idle")))
369 (lambda (file) 370 (when idle
370 (let ((target (string-append idle "/bin/" (basename file)))) 371 (for-each
371 (install-file file (dirname target)) 372 (lambda (file)
372 (delete-file file))) 373 (let ((target (string-append idle "/bin/" (basename file))))
373 (find-files (string-append out "/bin") "^idle")) 374 (install-file file (dirname target))
374 (match (find-files out "^idlelib$" #:directories? #t) 375 (delete-file file)))
375 ((idlelib) 376 (find-files (string-append out "/bin") "^idle"))
376 (let* ((len (string-length out)) 377 (match (find-files out "^idlelib$" #:directories? #t)
377 (target (string-append idle "/" 378 ((idlelib)
378 (string-drop idlelib len) 379 (let* ((len (string-length out))
379 "/site-packages"))) 380 (target (string-append idle "/"
380 (mkdir-p (dirname target)) 381 (string-drop idlelib len)
381 (rename-file idlelib target)))))))) 382 "/site-packages")))
382 (add-after 'move-idle 'rebuild-bytecode 383 (mkdir-p (dirname target))
383 (lambda* (#:key outputs #:allow-other-keys) 384 (rename-file idlelib target))))))))
384 (let ((out (assoc-ref outputs "out"))) 385 (add-after 'move-idle 'rebuild-bytecode
385 ;; Disable hash randomization to ensure the generated .pycs 386 (lambda* (#:key outputs #:allow-other-keys)
386 ;; are reproducible. 387 (let ((out (assoc-ref outputs "out")))
387 (setenv "PYTHONHASHSEED" "0") 388 ;; Disable hash randomization to ensure the generated .pycs
388 (for-each 389 ;; are reproducible.
389 (lambda (output) 390 (setenv "PYTHONHASHSEED" "0")
390 (for-each (lambda (opt) 391 (for-each
391 (format #t "Compiling with optimization level: ~a\n" 392 (lambda (output)
392 (if (null? opt) "none" (car opt))) 393 (for-each (lambda (opt)
393 (apply invoke 394 (format #t "Compiling with optimization level: ~a\n"
394 `(,,(if (%current-target-system) 395 (if (null? opt) "none" (car opt)))
395 "python2" 396 (apply invoke
396 '(string-append out "/bin/python")) 397 `(,#$(if (%current-target-system)
397 ,@opt 398 "python2"
398 "-m" "compileall" 399 #~(string-append out "/bin/python"))
399 "-f" ; force rebuild 400 ,@opt
400 ;; Don't build lib2to3, because it contains 401 "-m" "compileall"
401 ;; Python 3 code. 402 "-f" ; force rebuild
402 "-x" "lib2to3/.*" 403 ;; Don't build lib2to3, because it contains
403 ,output))) 404 ;; Python 3 code.
404 ;; Python 2 has a single file extension (.pyo) for the 405 "-x" "lib2to3/.*"
405 ;; chosen level of optimization, so it doesn't make 406 ,output)))
406 ;; sense to byte compile with more than one level. 407 ;; Python 2 has a single file extension (.pyo) for the
407 (list '() '("-OO")))) 408 ;; chosen level of optimization, so it doesn't make
408 (map cdr outputs))))) 409 ;; sense to byte compile with more than one level.
409 (add-after 'install 'install-sitecustomize.py 410 (list '() '("-OO"))))
410 ,(customize-site version))))) 411 (map cdr outputs)))))
412 (add-after 'install 'install-sitecustomize.py
413 #$(customize-site version)))))
411 (inputs 414 (inputs
412 (list bzip2 415 (list bzip2
413 expat 416 expat
414 gdbm 417 gdbm
415 libffi ; for ctypes 418 libffi ; for ctypes
416 libxcrypt ; crypto module slated for removal in 3.13, re-enable 419 libxcrypt ; crypto module slated for removal in 3.13, re-enable
417 ; python tests of libxcrypt when that happens 420 ; python tests of libxcrypt when that happens
418 sqlite ; for sqlite extension 421 sqlite ; for sqlite extension
419 openssl-1.1 422 openssl-1.1
420 readline 423 readline
421 zlib 424 zlib
422 tcl 425 tcl
423 tk)) ; for tkinter 426 tk)) ; for tkinter
424 (native-inputs 427 (native-inputs
425 `(("pkg-config" ,pkg-config) 428 `(("pkg-config" ,pkg-config)
426 ("sitecustomize.py" ,(local-file (search-auxiliary-file 429 ("sitecustomize.py" ,(local-file (search-auxiliary-file
@@ -481,95 +484,97 @@ data types.")
481 (arguments 484 (arguments
482 (substitute-keyword-arguments (package-arguments python-2) 485 (substitute-keyword-arguments (package-arguments python-2)
483 ((#:configure-flags flags) 486 ((#:configure-flags flags)
484 `(append ,flags '("--without-static-libpython"))) 487 #~(append #$flags
488 ;; XXX Use quote to avoid world rebuild at this time
489 '("--without-static-libpython")))
485 ((#:make-flags _) 490 ((#:make-flags _)
486 `(list (string-append 491 #~(list (string-append
487 (format #f "TESTOPTS=-j~d" (parallel-job-count)) 492 (format #f "TESTOPTS=-j~d" (parallel-job-count))
488 ;; test_mmap fails on low-memory systems 493 ;; test_mmap fails on low-memory systems
489 " --exclude test_mmap test_socket" 494 " --exclude test_mmap test_socket"
490 ,@(if (system-hurd?) 495 #$@(if (system-hurd?)
491 '(" test_posix" ;multiple errors 496 #~(" test_posix" ;multiple errors
492 " test_time" 497 " test_time"
493 " test_pty" 498 " test_pty"
494 " test_shutil" 499 " test_shutil"
495 " test_tempfile" ;chflags: invalid argument: 500 " test_tempfile" ;chflags: invalid argument:
496 ; tbv14c9t/dir0/dir0/dir0/test0.txt 501 ; tbv14c9t/dir0/dir0/dir0/test0.txt
497 " test_asyncio" ;runs over 10min 502 " test_asyncio" ;runs over 10min
498 " test_os" ;stty: 'standard input': 503 " test_os" ;stty: 'standard input':
499 ; Inappropriate ioctl for device 504 ; Inappropriate ioctl for device
500 " test_openpty" ;No such file or directory 505 " test_openpty" ;No such file or directory
501 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds)) 506 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
502 ; 32752 != 4 507 ; 32752 != 4
503 " test_compileall" ;multiple errors 508 " test_compileall" ;multiple errors
504 " test_poll" ;list index out of range 509 " test_poll" ;list index out of range
505 " test_subprocess" ;runs over 10min 510 " test_subprocess" ;runs over 10min
506 " test_asyncore" ;multiple errors 511 " test_asyncore" ;multiple errors
507 " test_threadsignals" 512 " test_threadsignals"
508 " test_eintr" ;Process return code is -14 513 " test_eintr" ;Process return code is -14
509 " test_io" ;multiple errors 514 " test_io" ;multiple errors
510 " test_logging" 515 " test_logging"
511 " test_signal" 516 " test_signal"
512 " test_threading" ;runs over 10min 517 " test_threading" ;runs over 10min
513 " test_flags" ;ERROR 518 " test_flags" ;ERROR
514 " test_bidirectional_pty" 519 " test_bidirectional_pty"
515 " test_create_unix_connection" 520 " test_create_unix_connection"
516 " test_unix_sock_client_ops" 521 " test_unix_sock_client_ops"
517 " test_open_unix_connection" 522 " test_open_unix_connection"
518 " test_open_unix_connection_error" 523 " test_open_unix_connection_error"
519 " test_read_pty_output" 524 " test_read_pty_output"
520 " test_write_pty" 525 " test_write_pty"
521 " test_concurrent_futures" ;freeze 526 " test_concurrent_futures" ;freeze
522 " test_venv" ;freeze 527 " test_venv" ;freeze
523 " test_multiprocessing_forkserver" ;runs over 10min 528 " test_multiprocessing_forkserver" ;runs over 10min
524 " test_multiprocessing_spawn" ;runs over 10min 529 " test_multiprocessing_spawn" ;runs over 10min
525 " test_builtin" 530 " test_builtin"
526 " test_capi" 531 " test_capi"
527 " test_dbm_ndbm" 532 " test_dbm_ndbm"
528 " test_exceptions" 533 " test_exceptions"
529 " test_faulthandler" 534 " test_faulthandler"
530 " test_getopt" 535 " test_getopt"
531 " test_importlib" 536 " test_importlib"
532 " test_json" 537 " test_json"
533 " test_multiprocessing_fork" 538 " test_multiprocessing_fork"
534 " test_multiprocessing_main_handling" 539 " test_multiprocessing_main_handling"
535 " test_pdb " 540 " test_pdb "
536 " test_regrtest" 541 " test_regrtest"
537 " test_sqlite") 542 " test_sqlite")
538 '())))) 543 #~()))))
539 ((#:phases phases) 544 ((#:phases phases)
540 `(modify-phases ,phases 545 #~(modify-phases #$phases
541 ,@(if (system-hurd?) 546 #$@(if (system-hurd?)
542 `((delete 'patch-regen-for-hurd) ;regen was removed after 3.5.9 547 #~((delete 'patch-regen-for-hurd) ;regen was removed after 3.5.9
543 (add-after 'unpack 'disable-multi-processing 548 (add-after 'unpack 'disable-multi-processing
544 (lambda _ 549 (lambda _
545 (substitute* "Makefile.pre.in" 550 (substitute* "Makefile.pre.in"
546 (("-j0") "-j1"))))) 551 (("-j0") "-j1")))))
547 '()) 552 #~())
548 (add-after 'unpack 'remove-vendored-wheel-content 553 (add-after 'unpack 'remove-vendored-wheel-content
549 (lambda _ 554 (lambda _
550 ;; Delete .exe from embedded .whl (zip) files 555 ;; Delete .exe from embedded .whl (zip) files
551 (for-each 556 (for-each
552 (lambda (whl) 557 (lambda (whl)
553 (let ((dir "whl-content") 558 (let ((dir "whl-content")
554 (circa-1980 (* 10 366 24 60 60))) 559 (circa-1980 (* 10 366 24 60 60)))
555 (mkdir-p dir) 560 (mkdir-p dir)
556 (with-directory-excursion dir 561 (with-directory-excursion dir
557 (let ((whl (string-append "../" whl))) 562 (let ((whl (string-append "../" whl)))
558 (invoke "unzip" whl) 563 (invoke "unzip" whl)
559 (for-each delete-file 564 (for-each delete-file
560 (find-files "." "\\.exe$")) 565 (find-files "." "\\.exe$"))
561 (delete-file whl) 566 (delete-file whl)
562 567
563 ;; Search for cacert.pem, delete it, and rewrite the 568 ;; Search for cacert.pem, delete it, and rewrite the
564 ;; file which directs python to look for it. 569 ;; file which directs python to look for it.
565 (let ((cacert (find-files "." "cacert\\.pem"))) 570 (let ((cacert (find-files "." "cacert\\.pem")))
566 (unless (null? cacert) 571 (unless (null? cacert)
567 (let ((certifi (dirname (car cacert)))) 572 (let ((certifi (dirname (car cacert))))
568 (delete-file (string-append certifi "/cacert.pem")) 573 (delete-file (string-append certifi "/cacert.pem"))
569 (delete-file (string-append certifi "/core.py")) 574 (delete-file (string-append certifi "/core.py"))
570 (with-output-to-file (string-append certifi "/core.py") 575 (with-output-to-file (string-append certifi "/core.py")
571 (lambda _ 576 (lambda _
572 (display "\"\"\" 577 (display "\"\"\"
573certifi.py 578certifi.py
574~~~~~~~~~~ 579~~~~~~~~~~
575This file is a Guix-specific version of core.py. 580This file is a Guix-specific version of core.py.
@@ -593,54 +598,54 @@ def contents() -> str:
593 with open(where(), \"r\", encoding=\"ascii\") as data: 598 with open(where(), \"r\", encoding=\"ascii\") as data:
594 return data.read()")))))) 599 return data.read()"))))))
595 600
596 ;; Reset timestamps to prevent them from ending 601 ;; Reset timestamps to prevent them from ending
597 ;; up in the Zip archive. 602 ;; up in the Zip archive.
598 (ftw "." (lambda (file stat flag) 603 (ftw "." (lambda (file stat flag)
599 (utime file circa-1980 circa-1980) 604 (utime file circa-1980 circa-1980)
600 #t)) 605 #t))
601 (apply invoke "zip" "-X" whl 606 (apply invoke "zip" "-X" whl
602 (find-files "." #:directories? #t)))) 607 (find-files "." #:directories? #t))))
603 (delete-file-recursively dir))) 608 (delete-file-recursively dir)))
604 (find-files "Lib/ensurepip" "\\.whl$")))) 609 (find-files "Lib/ensurepip" "\\.whl$"))))
605 (add-before 'check 'set-TZDIR 610 (add-before 'check 'set-TZDIR
606 (lambda* (#:key inputs native-inputs #:allow-other-keys) 611 (lambda* (#:key inputs native-inputs #:allow-other-keys)
607 ;; test_email requires the Olson time zone database. 612 ;; test_email requires the Olson time zone database.
608 (setenv "TZDIR" 613 (setenv "TZDIR"
609 (string-append (assoc-ref 614 (string-append (assoc-ref
610 (or native-inputs inputs) "tzdata") 615 (or native-inputs inputs) "tzdata")
611 "/share/zoneinfo")))) 616 "/share/zoneinfo"))))
612 (replace 'rebuild-bytecode 617 (replace 'rebuild-bytecode
613 (lambda* (#:key outputs #:allow-other-keys) 618 (lambda* (#:key outputs #:allow-other-keys)
614 (let ((out (assoc-ref outputs "out"))) 619 (let ((out (assoc-ref outputs "out")))
615 ;; Disable hash randomization to ensure the generated .pycs 620 ;; Disable hash randomization to ensure the generated .pycs
616 ;; are reproducible. 621 ;; are reproducible.
617 (setenv "PYTHONHASHSEED" "0") 622 (setenv "PYTHONHASHSEED" "0")
618 623
619 (for-each (lambda (output) 624 (for-each (lambda (output)
620 ;; XXX: Delete existing pycs generated by the build 625 ;; XXX: Delete existing pycs generated by the build
621 ;; system beforehand because the -f argument does 626 ;; system beforehand because the -f argument does
622 ;; not necessarily overwrite all files, leading to 627 ;; not necessarily overwrite all files, leading to
623 ;; indeterministic results. 628 ;; indeterministic results.
624 (for-each (lambda (pyc) 629 (for-each (lambda (pyc)
625 (delete-file pyc)) 630 (delete-file pyc))
626 (find-files output "\\.pyc$")) 631 (find-files output "\\.pyc$"))
627 632
628 (apply invoke 633 (apply invoke
629 `(,,(if (%current-target-system) 634 `(,#$(if (%current-target-system)
630 "python3" 635 "python3"
631 '(string-append out 636 #~(string-append out
632 "/bin/python3")) 637 "/bin/python3"))
633 "-m" "compileall" 638 "-m" "compileall"
634 "-o" "0" "-o" "1" "-o" "2" 639 "-o" "0" "-o" "1" "-o" "2"
635 "-f" ; force rebuild 640 "-f" ; force rebuild
636 "--invalidation-mode=unchecked-hash" 641 "--invalidation-mode=unchecked-hash"
637 ;; Don't build lib2to3, because it's 642 ;; Don't build lib2to3, because it's
638 ;; Python 2 code. 643 ;; Python 2 code.
639 "-x" "lib2to3/.*" 644 "-x" "lib2to3/.*"
640 ,output))) 645 ,output)))
641 (map cdr outputs))))) 646 (map cdr outputs)))))
642 (replace 'install-sitecustomize.py 647 (replace 'install-sitecustomize.py
643 ,(customize-site version)))))) 648 #$(customize-site version))))))
644 (inputs 649 (inputs
645 (modify-inputs (package-inputs python-2.7) 650 (modify-inputs (package-inputs python-2.7)
646 (replace "openssl" openssl))) 651 (replace "openssl" openssl)))
@@ -1092,337 +1097,342 @@ def contents() -> str:
1092 ;; Delete windows binaries 1097 ;; Delete windows binaries
1093 (for-each delete-file 1098 (for-each delete-file
1094 (find-files "Lib/distutils/command" "\\.exe$")))))) 1099 (find-files "Lib/distutils/command" "\\.exe$"))))))
1095 (outputs '("out" "tk" ;tkinter; adds 50 MiB to the closure 1100 (outputs '("out" "tk" ;tkinter; adds 50 MiB to the closure
1096 "idle")) ;programming environment; weighs 5MB 1101 "idle")) ;programming environment; weighs 5MB
1097 (build-system gnu-build-system) 1102 (build-system gnu-build-system)
1098 (arguments 1103 (arguments
1099 `(#:test-target "test" 1104 (list
1100 #:configure-flags (list "--enable-shared" ;allow embedding 1105 #:test-target "test"
1101 "--with-system-expat" ;for XML support 1106 #:configure-flags
1102 "--with-system-ffi" ;build ctypes 1107 #~(list "--enable-shared" ;allow embedding
1103 "--with-ensurepip=install" ;install pip and setuptools 1108 "--with-system-expat" ;for XML support
1104 "--with-computed-gotos" ;main interpreter loop optimization 1109 "--with-system-ffi" ;build ctypes
1105 "--enable-unicode=ucs4" 1110 "--with-ensurepip=install" ;install pip and setuptools
1106 "--without-static-libpython" 1111 "--with-computed-gotos" ;main interpreter loop optimization
1107 "--enable-loadable-sqlite-extensions" 1112 "--enable-unicode=ucs4"
1113 "--without-static-libpython"
1114 "--enable-loadable-sqlite-extensions"
1108 1115
1109 ;; FIXME: These flags makes Python significantly faster, 1116 ;; FIXME: These flags makes Python significantly faster,
1110 ;; but leads to non-reproducible binaries. 1117 ;; but leads to non-reproducible binaries.
1111 ;; "--with-lto" ;increase size by 20MB, but 15% speedup 1118 ;; "--with-lto" ;increase size by 20MB, but 15% speedup
1112 ;; "--enable-optimizations" 1119 ;; "--enable-optimizations"
1113 1120
1114 ;; Prevent the installed _sysconfigdata.py from retaining 1121 ;; Prevent the installed _sysconfigdata.py from retaining
1115 ;; a reference to coreutils. 1122 ;; a reference to coreutils.
1116 "INSTALL=install -c" 1123 "INSTALL=install -c"
1117 "MKDIR_P=mkdir -p" 1124 "MKDIR_P=mkdir -p"
1118 1125
1119 ;; Disable runtime check failing if cross-compiling, see: 1126 ;; Disable runtime check failing if cross-compiling, see:
1120 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html 1127 ;; https://lists.yoctoproject.org/pipermail/poky/2013-June/008997.html
1121 ,@(if (%current-target-system) 1128 #$@(if (%current-target-system)
1122 '("ac_cv_buggy_getaddrinfo=no" 1129 #~("ac_cv_buggy_getaddrinfo=no"
1123 "ac_cv_file__dev_ptmx=no" 1130 "ac_cv_file__dev_ptmx=no"
1124 "ac_cv_file__dev_ptc=no") 1131 "ac_cv_file__dev_ptc=no")
1125 '()) 1132 #~())
1126 ;; -fno-semantic-interposition reinstates some 1133 ;; -fno-semantic-interposition reinstates some
1127 ;; optimizations by gcc leading to around 15% speedup. 1134 ;; optimizations by gcc leading to around 15% speedup.
1128 ;; This is the default starting from python 3.10. 1135 ;; This is the default starting from python 3.10.
1129 "CFLAGS=-fno-semantic-interposition" 1136 "CFLAGS=-fno-semantic-interposition"
1130 (string-append "LDFLAGS=-Wl,-rpath=" 1137 (string-append "LDFLAGS=-Wl,-rpath="
1131 (assoc-ref %outputs "out") 1138 (assoc-ref %outputs "out")
1132 "/lib" 1139 "/lib"
1133 " -fno-semantic-interposition")) 1140 " -fno-semantic-interposition"))
1134 ;; With no -j argument tests use all available cpus, so provide one. 1141 ;; With no -j argument tests use all available cpus, so provide one.
1135 #:make-flags (list (string-append (format #f "TESTOPTS=-j~d" 1142 #:make-flags
1136 (parallel-job-count)) 1143 #~(list (string-append (format #f "TESTOPTS=-j~d"
1137 ;; those tests fail on low-memory systems 1144 (parallel-job-count))
1138 " --exclude" 1145 ;; those tests fail on low-memory systems
1139 " test_mmap" 1146 " --exclude"
1140 " test_socket" 1147 " test_mmap"
1141 " test_threading" 1148 " test_socket"
1142 " test_asyncio" 1149 " test_threading"
1143 " test_shutdown" 1150 " test_asyncio"
1144 ,@(if (system-hurd?) 1151 " test_shutdown"
1145 '(" test_posix" ;multiple errors 1152 #$@(if (system-hurd?)
1146 " test_time" 1153 #~(" test_posix" ;multiple errors
1147 " test_pty" 1154 " test_time"
1148 " test_shutil" 1155 " test_pty"
1149 " test_tempfile" ;chflags: invalid argument: 1156 " test_shutil"
1150 ;; tbv14c9t/dir0/dir0/dir0/test0.txt 1157 " test_tempfile" ;chflags: invalid argument:
1151 " test_os" ;stty: 'standard input': 1158 ;; tbv14c9t/dir0/dir0/dir0/test0.txt
1152 ;; Inappropriate ioctl for device 1159 " test_os" ;stty: 'standard input':
1153 " test_openpty" ;No such file or directory 1160 ;; Inappropriate ioctl for device
1154 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds)) 1161 " test_openpty" ;No such file or directory
1155 ;; 32752 != 4 1162 " test_selectors" ;assertEqual(NUM_FDS // 2, len(fds))
1156 " test_compileall" ;multiple errors 1163 ;; 32752 != 4
1157 " test_poll" ;list index out of range 1164 " test_compileall" ;multiple errors
1158 " test_subprocess" ;runs over 10min 1165 " test_poll" ;list index out of range
1159 " test_asyncore" ;multiple errors 1166 " test_subprocess" ;runs over 10min
1160 " test_threadsignals" 1167 " test_asyncore" ;multiple errors
1161 " test_eintr" ;Process return code is -14 1168 " test_threadsignals"
1162 " test_io" ;multiple errors 1169 " test_eintr" ;Process return code is -14
1163 " test_logging" 1170 " test_io" ;multiple errors
1164 " test_signal" 1171 " test_logging"
1165 " test_flags" ;ERROR 1172 " test_signal"
1166 " test_bidirectional_pty" 1173 " test_flags" ;ERROR
1167 " test_create_unix_connection" 1174 " test_bidirectional_pty"
1168 " test_unix_sock_client_ops" 1175 " test_create_unix_connection"
1169 " test_open_unix_connection" 1176 " test_unix_sock_client_ops"
1170 " test_open_unix_connection_error" 1177 " test_open_unix_connection"
1171 " test_read_pty_output" 1178 " test_open_unix_connection_error"
1172 " test_write_pty" 1179 " test_read_pty_output"
1173 " test_concurrent_futures" ;freeze 1180 " test_write_pty"
1174 " test_venv" ;freeze 1181 " test_concurrent_futures" ;freeze
1175 " test_multiprocessing_forkserver" ;runs over 10min 1182 " test_venv" ;freeze
1176 " test_multiprocessing_spawn" ;runs over 10min 1183 " test_multiprocessing_forkserver" ;runs over 10min
1177 " test_builtin" 1184 " test_multiprocessing_spawn" ;runs over 10min
1178 " test_capi" 1185 " test_builtin"
1179 " test_dbm_ndbm" 1186 " test_capi"
1180 " test_exceptions" 1187 " test_dbm_ndbm"
1181 " test_faulthandler" 1188 " test_exceptions"
1182 " test_getopt" 1189 " test_faulthandler"
1183 " test_importlib" 1190 " test_getopt"
1184 " test_json" 1191 " test_importlib"
1185 " test_multiprocessing_fork" 1192 " test_json"
1186 " test_multiprocessing_main_handling" 1193 " test_multiprocessing_fork"
1187 " test_pdb " 1194 " test_multiprocessing_main_handling"
1188 " test_regrtest" 1195 " test_pdb "
1189 " test_sqlite") 1196 " test_regrtest"
1190 '()))) 1197 " test_sqlite")
1198 #~())))
1191 1199
1192 #:modules ((ice-9 ftw) 1200 #:modules '((ice-9 ftw)
1193 (ice-9 match) 1201 (ice-9 match)
1194 (guix build utils) 1202 (guix build utils)
1195 (guix build gnu-build-system)) 1203 (guix build gnu-build-system))
1196 1204
1197 #:phases (modify-phases %standard-phases 1205 #:phases
1198 ,@(if (system-hurd?) 1206 #~(modify-phases %standard-phases
1199 `((add-after 'unpack 1207 #$@(if (system-hurd?)
1200 'disable-multi-processing 1208 #~((add-after 'unpack
1201 (lambda _ 1209 'disable-multi-processing
1202 (substitute* "Makefile.pre.in" 1210 (lambda _
1203 (("-j0") 1211 (substitute* "Makefile.pre.in"
1204 "-j1"))))) 1212 (("-j0")
1205 '()) 1213 "-j1")))))
1206 (add-before 'configure 'patch-lib-shells 1214 #~())
1207 (lambda _ 1215 (add-before 'configure 'patch-lib-shells
1208 ;; This variable is used in setup.py to enable cross compilation 1216 (lambda _
1209 ;; specific switches. As it is not set properly by configure 1217 ;; This variable is used in setup.py to enable cross compilation
1210 ;; script, set it manually. 1218 ;; specific switches. As it is not set properly by configure
1211 ,@(if (%current-target-system) 1219 ;; script, set it manually.
1212 '((setenv "_PYTHON_HOST_PLATFORM" "")) 1220 #$@(if (%current-target-system)
1213 '()) 1221 #~((setenv "_PYTHON_HOST_PLATFORM" ""))
1214 ;; Filter for existing files, since some may not exist in all 1222 #~())
1215 ;; versions of python that are built with this recipe. 1223 ;; Filter for existing files, since some may not exist in all
1216 (substitute* (filter file-exists? 1224 ;; versions of python that are built with this recipe.
1217 '("Lib/subprocess.py" 1225 (substitute* (filter file-exists?
1218 "Lib/popen2.py" 1226 '("Lib/subprocess.py"
1219 "Lib/distutils/tests/test_spawn.py" 1227 "Lib/popen2.py"
1220 "Lib/test/support/__init__.py" 1228 "Lib/distutils/tests/test_spawn.py"
1221 "Lib/test/test_subprocess.py")) 1229 "Lib/test/support/__init__.py"
1222 (("/bin/sh") 1230 "Lib/test/test_subprocess.py"))
1223 (which "sh"))))) 1231 (("/bin/sh")
1224 (add-before 'configure 'do-not-record-configure-flags 1232 (which "sh")))))
1225 (lambda* (#:key configure-flags #:allow-other-keys) 1233 (add-before 'configure 'do-not-record-configure-flags
1226 ;; Remove configure flags from the installed '_sysconfigdata.py' 1234 (lambda* (#:key configure-flags #:allow-other-keys)
1227 ;; and 'Makefile' so we don't end up keeping references to the 1235 ;; Remove configure flags from the installed '_sysconfigdata.py'
1228 ;; build tools. 1236 ;; and 'Makefile' so we don't end up keeping references to the
1229 ;; 1237 ;; build tools.
1230 ;; Preserve at least '--with-system-ffi' since otherwise the 1238 ;;
1231 ;; thing tries to build libffi, fails, and we end up with a 1239 ;; Preserve at least '--with-system-ffi' since otherwise the
1232 ;; Python that lacks ctypes. 1240 ;; thing tries to build libffi, fails, and we end up with a
1233 (substitute* "configure" 1241 ;; Python that lacks ctypes.
1234 (("^CONFIG_ARGS=.*$") 1242 (substitute* "configure"
1235 (format #f "CONFIG_ARGS='~a'\n" 1243 (("^CONFIG_ARGS=.*$")
1236 (if (member "--with-system-ffi" 1244 (format #f "CONFIG_ARGS='~a'\n"
1237 configure-flags) 1245 (if (member "--with-system-ffi"
1238 "--with-system-ffi" "")))))) 1246 configure-flags)
1239 (add-before 'check 'pre-check 1247 "--with-system-ffi" ""))))))
1240 (lambda _ 1248 (add-before 'check 'pre-check
1241 ;; 'Lib/test/test_site.py' needs a valid $HOME 1249 (lambda _
1242 (setenv "HOME" 1250 ;; 'Lib/test/test_site.py' needs a valid $HOME
1243 (getcwd)))) 1251 (setenv "HOME"
1244 (add-after 'unpack 'set-source-file-times-to-1980 1252 (getcwd))))
1245 ;; XXX One of the tests uses a ZIP library to pack up some of the 1253 (add-after 'unpack 'set-source-file-times-to-1980
1246 ;; source tree, and fails with "ZIP does not support timestamps 1254 ;; XXX One of the tests uses a ZIP library to pack up some of the
1247 ;; before 1980". Work around this by setting the file times in the 1255 ;; source tree, and fails with "ZIP does not support timestamps
1248 ;; source tree to sometime in early 1980. 1256 ;; before 1980". Work around this by setting the file times in the
1249 (lambda _ 1257 ;; source tree to sometime in early 1980.
1250 (let ((circa-1980 (* 10 366 24 60 60))) 1258 (lambda _
1251 (ftw "." 1259 (let ((circa-1980 (* 10 366 24 60 60)))
1252 (lambda (file stat flag) 1260 (ftw "."
1253 (utime file circa-1980 circa-1980) #t))))) 1261 (lambda (file stat flag)
1254 (add-after 'unpack 'remove-windows-binaries 1262 (utime file circa-1980 circa-1980) #t)))))
1255 (lambda _ 1263 (add-after 'unpack 'remove-windows-binaries
1256 ;; Delete .exe from embedded .whl (zip) files 1264 (lambda _
1257 (for-each (lambda (whl) 1265 ;; Delete .exe from embedded .whl (zip) files
1258 (let ((dir "whl-content") 1266 (for-each (lambda (whl)
1259 (circa-1980 (* 10 366 24 60 60))) 1267 (let ((dir "whl-content")
1260 (mkdir-p dir) 1268 (circa-1980 (* 10 366 24 60 60)))
1261 (with-directory-excursion dir 1269 (mkdir-p dir)
1262 (let ((whl (string-append "../" whl))) 1270 (with-directory-excursion dir
1263 (invoke "unzip" whl) 1271 (let ((whl (string-append "../" whl)))
1264 (for-each delete-file 1272 (invoke "unzip" whl)
1265 (find-files "." "\\.exe$")) 1273 (for-each delete-file
1266 (delete-file whl) 1274 (find-files "." "\\.exe$"))
1267 ;; Reset timestamps to prevent them from ending 1275 (delete-file whl)
1268 ;; up in the Zip archive. 1276 ;; Reset timestamps to prevent them from ending
1269 (ftw "." 1277 ;; up in the Zip archive.
1270 (lambda (file stat flag) 1278 (ftw "."
1271 (utime file circa-1980 1279 (lambda (file stat flag)
1272 circa-1980) #t)) 1280 (utime file circa-1980
1273 (apply invoke "zip" "-X" whl 1281 circa-1980) #t))
1274 (find-files "." 1282 (apply invoke "zip" "-X" whl
1275 #:directories? #t)))) 1283 (find-files "."
1276 (delete-file-recursively dir))) 1284 #:directories? #t))))
1277 (find-files "Lib/ensurepip" "\\.whl$")))) 1285 (delete-file-recursively dir)))
1278 (add-after 'install 'remove-tests 1286 (find-files "Lib/ensurepip" "\\.whl$"))))
1279 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.* 1287 (add-after 'install 'remove-tests
1280 ;; because these files are used by some libraries out there. 1288 ;; Remove 25 MiB of unneeded unit tests. Keep test_support.*
1281 (lambda* (#:key outputs #:allow-other-keys) 1289 ;; because these files are used by some libraries out there.
1282 (let ((out (assoc-ref outputs "out"))) 1290 (lambda* (#:key outputs #:allow-other-keys)
1283 (match (scandir (string-append out "/lib") 1291 (let ((out (assoc-ref outputs "out")))
1284 (lambda (name) 1292 (match (scandir (string-append out "/lib")
1285 (string-prefix? "python" name))) 1293 (lambda (name)
1286 ((pythonX.Y) 1294 (string-prefix? "python" name)))
1287 (let ((testdir (string-append out "/lib/" pythonX.Y 1295 ((pythonX.Y)
1288 "/test"))) 1296 (let ((testdir (string-append out "/lib/" pythonX.Y
1289 (with-directory-excursion testdir 1297 "/test")))
1290 (for-each delete-file-recursively 1298 (with-directory-excursion testdir
1291 (scandir testdir 1299 (for-each delete-file-recursively
1292 (match-lambda 1300 (scandir testdir
1293 ((or "." "..") 1301 (match-lambda
1294 #f) 1302 ((or "." "..")
1295 ("support" #f) 1303 #f)
1296 (file (not (string-prefix? 1304 ("support" #f)
1297 "test_support." 1305 (file (not (string-prefix?
1298 file)))))) 1306 "test_support."
1299 (call-with-output-file "__init__.py" 1307 file))))))
1300 (const #t)))) 1308 (call-with-output-file "__init__.py"
1301 (let ((libdir (string-append out "/lib/" pythonX.Y))) 1309 (const #t))))
1302 (for-each (lambda (directory) 1310 (let ((libdir (string-append out "/lib/" pythonX.Y)))
1303 (let ((dir (string-append libdir "/" 1311 (for-each (lambda (directory)
1304 directory))) 1312 (let ((dir (string-append libdir "/"
1305 (when (file-exists? dir) 1313 directory)))
1306 (delete-file-recursively dir)))) 1314 (when (file-exists? dir)
1307 '("email/test" "ctypes/test" 1315 (delete-file-recursively dir))))
1308 "unittest/test" 1316 '("email/test" "ctypes/test"
1309 "tkinter/test" 1317 "unittest/test"
1310 "sqlite3/test" 1318 "tkinter/test"
1311 "bsddb/test" 1319 "sqlite3/test"
1312 "lib-tk/test" 1320 "bsddb/test"
1313 "json/tests" 1321 "lib-tk/test"
1314 "distutils/tests")))))))) 1322 "json/tests"
1315 (add-after 'remove-tests 'move-tk-inter 1323 "distutils/tests"))))))))
1316 (lambda* (#:key outputs inputs #:allow-other-keys) 1324 (add-after 'remove-tests 'move-tk-inter
1317 ;; When Tkinter support is built move it to a separate output so 1325 (lambda* (#:key outputs inputs #:allow-other-keys)
1318 ;; that the main output doesn't contain a reference to Tcl/Tk. 1326 ;; When Tkinter support is built move it to a separate output so
1319 (let ((out (assoc-ref outputs "out")) 1327 ;; that the main output doesn't contain a reference to Tcl/Tk.
1320 (tk (assoc-ref outputs "tk"))) 1328 (let ((out (assoc-ref outputs "out"))
1321 (when tk 1329 (tk (assoc-ref outputs "tk")))
1322 (match (find-files out "tkinter.*\\.so") 1330 (when tk
1323 ((tkinter.so) 1331 (match (find-files out "tkinter.*\\.so")
1324 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we 1332 ((tkinter.so)
1325 ;; want it under TK/lib/pythonX.Y/site-packages. 1333 ;; The .so is in OUT/lib/pythonX.Y/lib-dynload, but we
1326 (let* ((len (string-length out)) 1334 ;; want it under TK/lib/pythonX.Y/site-packages.
1327 (target (string-append tk "/" 1335 (let* ((len (string-length out))
1328 (string-drop (dirname 1336 (target (string-append tk "/"
1329 (dirname 1337 (string-drop (dirname
1330 tkinter.so)) 1338 (dirname
1331 len) 1339 tkinter.so))
1332 "/site-packages"))) 1340 len)
1333 (install-file tkinter.so target) 1341 "/site-packages")))
1334 (delete-file tkinter.so)))) 1342 (install-file tkinter.so target)
1335 ;; Remove explicit store path references. 1343 (delete-file tkinter.so))))
1336 (let ((tcl (assoc-ref inputs "tcl")) 1344 ;; Remove explicit store path references.
1337 (tk (assoc-ref inputs "tk"))) 1345 (let ((tcl (assoc-ref inputs "tcl"))
1338 (substitute* (find-files (string-append out "/lib") 1346 (tk (assoc-ref inputs "tk")))
1339 "^(_sysconfigdata_.*\\.py|Makefile)$") 1347 (substitute* (find-files (string-append out "/lib")
1340 (((string-append "-L" tk "/lib")) 1348 "^(_sysconfigdata_.*\\.py|Makefile)$")
1341 "") 1349 (((string-append "-L" tk "/lib"))
1342 (((string-append "-L" tcl "/lib")) 1350 "")
1343 ""))))))) 1351 (((string-append "-L" tcl "/lib"))
1344 (add-after 'move-tk-inter 'move-idle 1352 "")))))))
1345 (lambda* (#:key outputs #:allow-other-keys) 1353 (add-after 'move-tk-inter 'move-idle
1346 ;; when idle is built, move it to a separate output to save some 1354 (lambda* (#:key outputs #:allow-other-keys)
1347 ;; space (5MB) 1355 ;; when idle is built, move it to a separate output to save some
1348 (let ((out (assoc-ref outputs "out")) 1356 ;; space (5MB)
1349 (idle (assoc-ref outputs "idle"))) 1357 (let ((out (assoc-ref outputs "out"))
1350 (when idle 1358 (idle (assoc-ref outputs "idle")))
1351 (for-each (lambda (file) 1359 (when idle
1352 (let ((target (string-append idle 1360 (for-each (lambda (file)
1353 "/bin/" 1361 (let ((target (string-append idle
1354 (basename 1362 "/bin/"
1355 file)))) 1363 (basename
1356 (install-file file 1364 file))))
1357 (dirname target)) 1365 (install-file file
1358 (delete-file file))) 1366 (dirname target))
1359 (find-files (string-append out "/bin") 1367 (delete-file file)))
1360 "^idle")) 1368 (find-files (string-append out "/bin")
1361 (match (find-files out "^idlelib$" 1369 "^idle"))
1362 #:directories? #t) 1370 (match (find-files out "^idlelib$"
1363 ((idlelib) 1371 #:directories? #t)
1364 (let* ((len (string-length out)) 1372 ((idlelib)
1365 (target (string-append idle "/" 1373 (let* ((len (string-length out))
1366 (string-drop 1374 (target (string-append idle "/"
1367 idlelib len) 1375 (string-drop
1368 "/site-packages"))) 1376 idlelib len)
1369 (mkdir-p (dirname target)) 1377 "/site-packages")))
1370 (rename-file idlelib target)))))))) 1378 (mkdir-p (dirname target))
1371 (add-after 'move-idle 'rebuild-bytecode 1379 (rename-file idlelib target))))))))
1372 (lambda* (#:key outputs #:allow-other-keys) 1380 (add-after 'move-idle 'rebuild-bytecode
1373 (let ((out (assoc-ref outputs "out"))) 1381 (lambda* (#:key outputs #:allow-other-keys)
1374 ;; Disable hash randomization to ensure the generated .pycs 1382 (let ((out (assoc-ref outputs "out")))
1375 ;; are reproducible. 1383 ;; Disable hash randomization to ensure the generated .pycs
1376 (setenv "PYTHONHASHSEED" "0") 1384 ;; are reproducible.
1385 (setenv "PYTHONHASHSEED" "0")
1377 1386
1378 (for-each (lambda (output) 1387 (for-each (lambda (output)
1379 ;; XXX: Delete existing pycs generated by the build 1388 ;; XXX: Delete existing pycs generated by the build
1380 ;; system beforehand because the -f argument does 1389 ;; system beforehand because the -f argument does
1381 ;; not necessarily overwrite all files, leading to 1390 ;; not necessarily overwrite all files, leading to
1382 ;; indeterministic results. 1391 ;; indeterministic results.
1383 (for-each (lambda (pyc) 1392 (for-each (lambda (pyc)
1384 (delete-file pyc)) 1393 (delete-file pyc))
1385 (find-files output "\\.pyc$")) 1394 (find-files output "\\.pyc$"))
1386 1395
1387 (apply invoke 1396 (apply invoke
1388 `(,,(if (%current-target-system) 1397 `(,#$(if (%current-target-system)
1389 "python3" 1398 "python3"
1390 '(string-append out 1399 #~(string-append
1391 "/bin/python3")) "-m" 1400 out
1392 "compileall" 1401 "/bin/python3")) "-m"
1393 "-o" 1402 "compileall"
1394 "0" 1403 "-o"
1395 "-o" 1404 "0"
1396 "1" 1405 "-o"
1397 "-o" 1406 "1"
1398 "2" 1407 "-o"
1399 "-f" ;force rebuild 1408 "2"
1400 "--invalidation-mode=unchecked-hash" 1409 "-f" ;force rebuild
1401 ;; Don't build lib2to3, because it's 1410 "--invalidation-mode=unchecked-hash"
1402 ;; Python 2 code. 1411 ;; Don't build lib2to3, because it's
1403 "-x" 1412 ;; Python 2 code.
1404 "lib2to3/.*" 1413 "-x"
1405 ,output))) 1414 "lib2to3/.*"
1406 (map cdr outputs))))) 1415 ,output)))
1407 (add-before 'check 'set-TZDIR 1416 (map cdr outputs)))))
1408 (lambda* (#:key inputs native-inputs #:allow-other-keys) 1417 (add-before 'check 'set-TZDIR
1409 ;; test_email requires the Olson time zone database. 1418 (lambda* (#:key inputs native-inputs #:allow-other-keys)
1410 (setenv "TZDIR" 1419 ;; test_email requires the Olson time zone database.
1411 (string-append (assoc-ref (or native-inputs 1420 (setenv "TZDIR"
1412 inputs) "tzdata") 1421 (string-append (assoc-ref (or native-inputs
1413 "/share/zoneinfo")))) 1422 inputs) "tzdata")
1414 (add-after 'install 'install-sitecustomize.py 1423 "/share/zoneinfo"))))
1415 ,(customize-site version))))) 1424 (add-after 'install 'install-sitecustomize.py
1425 #$(customize-site version)))))
1416 (inputs (list bzip2 1426 (inputs (list bzip2
1417 expat 1427 expat
1418 gdbm 1428 gdbm
1419 libffi ;for ctypes 1429 libffi ;for ctypes
1420 sqlite ;for sqlite extension 1430 sqlite ;for sqlite extension
1421 openssl 1431 openssl
1422 readline 1432 readline
1423 zlib 1433 zlib
1424 tcl 1434 tcl
1425 tk)) ;for tkinter 1435 tk)) ;for tkinter
1426 (native-inputs `(("tzdata" ,tzdata-for-tests) 1436 (native-inputs `(("tzdata" ,tzdata-for-tests)
1427 ("unzip" ,unzip) 1437 ("unzip" ,unzip)
1428 ("zip" ,(@ (gnu packages compression) zip)) 1438 ("zip" ,(@ (gnu packages compression) zip))