mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-20 05:37:34 -05:00
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.
This commit is contained in:
parent
65c5efd14e
commit
79c2812130
1 changed files with 51 additions and 44 deletions
|
@ -310,31 +310,7 @@ (define-public python-2.7
|
||||||
'("email/test" "ctypes/test" "unittest/test" "tkinter/test"
|
'("email/test" "ctypes/test" "unittest/test" "tkinter/test"
|
||||||
"sqlite3/test" "bsddb/test" "lib-tk/test" "lib2to3/tests"
|
"sqlite3/test" "bsddb/test" "lib-tk/test" "lib2to3/tests"
|
||||||
"json/tests" "distutils/tests"))))))))
|
"json/tests" "distutils/tests"))))))))
|
||||||
(add-after 'remove-tests 'rebuild-bytecode
|
(add-after 'remove-tests 'move-tk-inter
|
||||||
(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
|
|
||||||
(lambda* (#:key outputs #:allow-other-keys)
|
(lambda* (#:key outputs #:allow-other-keys)
|
||||||
;; When Tkinter support is built move it to a separate output so
|
;; When Tkinter support is built move it to a separate output so
|
||||||
;; that the main output doesn't contain a reference to Tcl/Tk.
|
;; that the main output doesn't contain a reference to Tcl/Tk.
|
||||||
|
@ -354,7 +330,7 @@ (define-public python-2.7
|
||||||
"/site-packages")))
|
"/site-packages")))
|
||||||
(install-file tkinter.so target)
|
(install-file tkinter.so target)
|
||||||
(delete-file tkinter.so))))))))
|
(delete-file tkinter.so))))))))
|
||||||
(add-after 'install 'move-idle
|
(add-after 'move-tk-inter 'move-idle
|
||||||
(lambda* (#:key outputs #:allow-other-keys)
|
(lambda* (#:key outputs #:allow-other-keys)
|
||||||
;; when idle is built, move it to a separate output to save some
|
;; when idle is built, move it to a separate output to save some
|
||||||
;; space (5MB)
|
;; space (5MB)
|
||||||
|
@ -375,6 +351,33 @@ (define-public python-2.7
|
||||||
"/site-packages")))
|
"/site-packages")))
|
||||||
(mkdir-p (dirname target))
|
(mkdir-p (dirname target))
|
||||||
(rename-file idlelib 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
|
(add-after 'install 'install-sitecustomize.py
|
||||||
,(customize-site version)))))
|
,(customize-site version)))))
|
||||||
(inputs
|
(inputs
|
||||||
|
@ -534,25 +537,29 @@ (define-public python-3.9
|
||||||
;; are reproducible.
|
;; are reproducible.
|
||||||
(setenv "PYTHONHASHSEED" "0")
|
(setenv "PYTHONHASHSEED" "0")
|
||||||
|
|
||||||
;; XXX: Delete existing auto-generated pycs beforehand because
|
(for-each (lambda (output)
|
||||||
;; the -f argument does not necessarily overwrite all files,
|
;; XXX: Delete existing pycs generated by the build
|
||||||
;; leading to indeterministic results.
|
;; system beforehand because the -f argument does
|
||||||
(for-each (lambda (pyc)
|
;; not necessarily overwrite all files, leading to
|
||||||
(delete-file pyc))
|
;; indeterministic results.
|
||||||
(find-files out "\\.pyc$"))
|
(for-each (lambda (pyc)
|
||||||
|
(delete-file pyc))
|
||||||
|
(find-files output "\\.pyc$"))
|
||||||
|
|
||||||
(apply invoke
|
(apply invoke
|
||||||
`(,,(if (%current-target-system)
|
`(,,(if (%current-target-system)
|
||||||
"python3"
|
"python3"
|
||||||
'(string-append out
|
'(string-append out
|
||||||
"/bin/python3"))
|
"/bin/python3"))
|
||||||
"-m" "compileall"
|
"-m" "compileall"
|
||||||
"-o" "0" "-o" "1" "-o" "2"
|
"-o" "0" "-o" "1" "-o" "2"
|
||||||
"-f" ; force rebuild
|
"-f" ; force rebuild
|
||||||
"--invalidation-mode=unchecked-hash"
|
"--invalidation-mode=unchecked-hash"
|
||||||
;; Don't build lib2to3, because it's Python 2 code.
|
;; Don't build lib2to3, because it's
|
||||||
"-x" "lib2to3/.*"
|
;; Python 2 code.
|
||||||
,out)))))
|
"-x" "lib2to3/.*"
|
||||||
|
,output)))
|
||||||
|
(map cdr outputs)))))
|
||||||
(replace 'install-sitecustomize.py
|
(replace 'install-sitecustomize.py
|
||||||
,(customize-site version))))))
|
,(customize-site version))))))
|
||||||
(native-inputs
|
(native-inputs
|
||||||
|
|
Loading…
Reference in a new issue