guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/04: build-system/python: Do not embed timestamps in the .pyc byte cod


From: guix-commits
Subject: 01/04: build-system/python: Do not embed timestamps in the .pyc byte code files.
Date: Mon, 19 Oct 2020 15:42:14 -0400 (EDT)

apteryx pushed a commit to branch core-updates
in repository guix.

commit c94a2864d4fbe11d86a94849c995f983b088ad58
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Sun Oct 18 01:31:31 2020 -0400

    build-system/python: Do not embed timestamps in the .pyc byte code files.
    
    Fixes <https://issues.guix.gnu.org/22129>.
    
    A previously worked around problem where running the test suite after byte
    compiling the sources in commit 6bbb37a545912c6bb2513ee08587ee4fe39cc330 
could
    be broken by adding built sources to the PYTHONPATH, as is done for
    python-matplotlib and many others.  This seems to be caused by the 
timestamps
    embedded in the sources (mtime), that can somehow change when running the
    tests, or by picking up the different installed source files mtimes when 
their
    location is added to the PYTHONPATH.
    
    Since Python 3.7.0, it is possible to produce .pyc byte code files that do 
not
    embed any timestamp, which solves the problem in a definitive way.  This 
patch
    makes use of this new feature.
    
    * guix/build/python-build-system.scm (install): Add '--no-compile' parameter
    to setup.py, and instead invoke the 'compileall' module with the
    "--invalidation-mode=unchecked-hash" option to byte compile the source 
files.
    (%standard-phases): Revert the workaround that moved the check phase after 
the
    install phase, as it is no longer necessary.  Update comment.
    
    Reported-by: Mark H Weaver <mhw@netris.org>
---
 guix/build/python-build-system.scm | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/guix/build/python-build-system.scm 
b/guix/build/python-build-system.scm
index 62e7a7b..a790c49 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2019, 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -178,18 +179,31 @@ when running checks after installing the package."
                            (if old-path (string-append ":" old-path) "")))
     #t))
 
-(define* (install #:key outputs (configure-flags '()) use-setuptools?
+(define* (install #:key inputs outputs (configure-flags '()) use-setuptools?
                   #:allow-other-keys)
   "Install a given Python package."
   (let* ((out (python-output outputs))
-         (params (append (list (string-append "--prefix=" out))
+         (python (assoc-ref inputs "python"))
+         (major-minor (map string->number
+                           (take (string-split (python-version python) #\.) 
2)))
+         (<3.7? (match major-minor
+                   ((major minor)
+                    (or (< major 3) (and (= major 3) (< minor 7))))))
+         (params (append (list (string-append "--prefix=" out)
+                               "--no-compile")
                          (if use-setuptools?
                              ;; distutils does not accept these flags
                              (list "--single-version-externally-managed"
-                                    "--root=/")
+                                   "--root=/")
                              '())
                          configure-flags)))
     (call-setuppy "install" params use-setuptools?)
+    ;; Rather than produce potentially non-reproducible .pyc files on Pythons
+    ;; older than 3.7, whose 'compileall' module lacks the
+    ;; '--invalidation-mode' option, do not generate any.
+    (unless <3.7?
+      (invoke "python" "-m" "compileall" "--invalidation-mode=unchecked-hash"
+              out))
     #t))
 
 (define* (wrap #:key inputs outputs #:allow-other-keys)
@@ -250,10 +264,8 @@ installed with setuptools."
 
 (define %standard-phases
   ;; The build phase only builds C extensions and copies the Python sources,
-  ;; while the install phase byte-compiles and copies them to the prefix
-  ;; directory.  The tests are run after the install phase because otherwise
-  ;; the cached .pyc generated during the tests execution seem to interfere
-  ;; with the byte compilation of the install phase.
+  ;; while the install phase copies then byte-compiles the sources to the
+  ;; prefix directory.
   (modify-phases gnu:%standard-phases
     (add-after 'unpack 'ensure-no-mtimes-pre-1980 ensure-no-mtimes-pre-1980)
     (add-after 'ensure-no-mtimes-pre-1980 'enable-bytecode-determinism
@@ -261,9 +273,8 @@ installed with setuptools."
     (delete 'bootstrap)
     (delete 'configure)                 ;not needed
     (replace 'build build)
-    (delete 'check)                     ;moved after the install phase
+    (replace 'check check)
     (replace 'install install)
-    (add-after 'install 'check check)
     (add-after 'install 'wrap wrap)
     (add-before 'strip 'rename-pth-file rename-pth-file)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]