[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
48/49: gnu: Python: Compile bytecode in all outputs.
From: |
guix-commits |
Subject: |
48/49: gnu: Python: Compile bytecode in all outputs. |
Date: |
Fri, 23 Jul 2021 11:33:15 -0400 (EDT) |
mbakke pushed a commit to branch core-updates
in repository guix.
commit 79c28121306ee26856414724b1efe0ed65318085
Author: Marius Bakke <marius@gnu.org>
AuthorDate: Thu Jul 22 00:33:31 2021 +0200
gnu: Python: Compile bytecode in all outputs.
* gnu/packages/python.scm (python-2.7)[arguments]: Ensure the post-install
phases run in order. Move rebuild-bytecode last and run it on every output.
* gnu/packages/python.scm (python-3.9)[arguments]: Run the rebuild-bytecode
phase on every output.
---
gnu/packages/python.scm | 95 ++++++++++++++++++++++++++-----------------------
1 file changed, 51 insertions(+), 44 deletions(-)
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 8a8fe2b..cee8613 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -310,31 +310,7 @@
'("email/test" "ctypes/test" "unittest/test"
"tkinter/test"
"sqlite3/test" "bsddb/test" "lib-tk/test"
"lib2to3/tests"
"json/tests" "distutils/tests"))))))))
- (add-after 'remove-tests 'rebuild-bytecode
- (lambda* (#:key outputs #:allow-other-keys)
- (let ((out (assoc-ref outputs "out")))
- ;; Disable hash randomization to ensure the generated .pycs
- ;; are reproducible.
- (setenv "PYTHONHASHSEED" "0")
- (for-each
- (lambda (opt)
- (format #t "Compiling with optimization level: ~a\n"
- (if (null? opt) "none" (car opt)))
- (apply invoke
- `(,,(if (%current-target-system)
- "python2"
- '(string-append out "/bin/python"))
- ,@opt
- "-m" "compileall"
- "-f" ; force rebuild
- ;; Don't build lib2to3, because it contains Python
3 code.
- "-x" "lib2to3/.*"
- ,out)))
- ;; Python 2 has a single file extension (.pyo) for the chosen
- ;; level of optimization, so it doesn't make sense to byte
- ;; compile with more than one level.
- (list '() '("-OO"))))))
- (add-after 'install 'move-tk-inter
+ (add-after 'remove-tests 'move-tk-inter
(lambda* (#:key outputs #:allow-other-keys)
;; When Tkinter support is built move it to a separate output so
;; that the main output doesn't contain a reference to Tcl/Tk.
@@ -354,7 +330,7 @@
"/site-packages")))
(install-file tkinter.so target)
(delete-file tkinter.so))))))))
- (add-after 'install 'move-idle
+ (add-after 'move-tk-inter 'move-idle
(lambda* (#:key outputs #:allow-other-keys)
;; when idle is built, move it to a separate output to save some
;; space (5MB)
@@ -375,6 +351,33 @@
"/site-packages")))
(mkdir-p (dirname target))
(rename-file idlelib target))))))))
+ (add-after 'move-idle 'rebuild-bytecode
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((out (assoc-ref outputs "out")))
+ ;; Disable hash randomization to ensure the generated .pycs
+ ;; are reproducible.
+ (setenv "PYTHONHASHSEED" "0")
+ (for-each
+ (lambda (output)
+ (for-each (lambda (opt)
+ (format #t "Compiling with optimization level:
~a\n"
+ (if (null? opt) "none" (car opt)))
+ (apply invoke
+ `(,,(if (%current-target-system)
+ "python2"
+ '(string-append out
"/bin/python"))
+ ,@opt
+ "-m" "compileall"
+ "-f" ; force rebuild
+ ;; Don't build lib2to3, because it
contains
+ ;; Python 3 code.
+ "-x" "lib2to3/.*"
+ ,output)))
+ ;; Python 2 has a single file extension (.pyo) for
the
+ ;; chosen level of optimization, so it doesn't make
+ ;; sense to byte compile with more than one level.
+ (list '() '("-OO"))))
+ (map cdr outputs)))))
(add-after 'install 'install-sitecustomize.py
,(customize-site version)))))
(inputs
@@ -534,25 +537,29 @@ data types.")
;; are reproducible.
(setenv "PYTHONHASHSEED" "0")
- ;; XXX: Delete existing auto-generated pycs beforehand because
- ;; the -f argument does not necessarily overwrite all files,
- ;; leading to indeterministic results.
- (for-each (lambda (pyc)
- (delete-file pyc))
- (find-files out "\\.pyc$"))
+ (for-each (lambda (output)
+ ;; XXX: Delete existing pycs generated by the
build
+ ;; system beforehand because the -f argument does
+ ;; not necessarily overwrite all files, leading to
+ ;; indeterministic results.
+ (for-each (lambda (pyc)
+ (delete-file pyc))
+ (find-files output "\\.pyc$"))
- (apply invoke
- `(,,(if (%current-target-system)
- "python3"
- '(string-append out
- "/bin/python3"))
- "-m" "compileall"
- "-o" "0" "-o" "1" "-o" "2"
- "-f" ; force rebuild
- "--invalidation-mode=unchecked-hash"
- ;; Don't build lib2to3, because it's Python 2 code.
- "-x" "lib2to3/.*"
- ,out)))))
+ (apply invoke
+ `(,,(if (%current-target-system)
+ "python3"
+ '(string-append out
+ "/bin/python3"))
+ "-m" "compileall"
+ "-o" "0" "-o" "1" "-o" "2"
+ "-f" ; force rebuild
+ "--invalidation-mode=unchecked-hash"
+ ;; Don't build lib2to3, because it's
+ ;; Python 2 code.
+ "-x" "lib2to3/.*"
+ ,output)))
+ (map cdr outputs)))))
(replace 'install-sitecustomize.py
,(customize-site version))))))
(native-inputs
- 32/49: gnu: pango: Update to 1.48.7., (continued)
- 32/49: gnu: pango: Update to 1.48.7., guix-commits, 2021/07/23
- 35/49: gnu: sqlite: Update to 3.36.0., guix-commits, 2021/07/23
- 36/49: gnu: libtiff: Update to 4.3.0., guix-commits, 2021/07/23
- 37/49: gnu: libxml2: Update to 2.9.12., guix-commits, 2021/07/23
- 41/49: gnu: perl-test-needs: Update to 0.002009., guix-commits, 2021/07/23
- 42/49: gnu: graphviz: Turn arguments into a gexp., guix-commits, 2021/07/23
- 46/49: gnu: Python: Fix bytecode compilation., guix-commits, 2021/07/23
- 47/49: gnu: Python: Delete existing compiled files before compiling bytecode., guix-commits, 2021/07/23
- 49/49: gnu: Python: Disable indeterministic optimizations., guix-commits, 2021/07/23
- 45/49: gnu: Python: Do not embed timestamps in wheel files., guix-commits, 2021/07/23
- 48/49: gnu: Python: Compile bytecode in all outputs.,
guix-commits <=
- 40/49: gnu: libcap: Update to 2.51., guix-commits, 2021/07/23
- 43/49: gnu: graphviz: Don't hard code Guile version., guix-commits, 2021/07/23
- 39/49: gnu: libksba: Update to 1.6.0., guix-commits, 2021/07/23
- 44/49: gnu: graphviz: Update to 2.48.0., guix-commits, 2021/07/23