diff mbox series

[bug#63044,v2] gnu: python: Disable date checking in bdist_egg.py

Message ID 4c971471e09fa2a57ac26b701f8b8e224899b86e.1682433331.git.bjc@spork.org
State New
Headers show
Series [bug#63044,v2] gnu: python: Disable date checking in bdist_egg.py | expand

Commit Message

Brian Cully April 25, 2023, 2:35 p.m. UTC
This fixes errors when packing Python eggs, where ZipFile fails due to Guix
setting file timestamps to 0 epoch seconds, where ZipFile wants all files to
date from at least 1980.

* gnu/packages/python-build.scm (python-setuptools)
[disable-zipfile-date-check]:  new phase
* gnu/packages/python.scm (python-3.10) [disable-zipfile-date-check]: new
phase
---
 gnu/packages/python-build.scm | 16 +++++++++++++++-
 gnu/packages/python.scm       | 25 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

Comments

Brian Cully April 28, 2023, 1:59 p.m. UTC | #1
Scratch this last patch, since it requires updating python itself, which
requires a huge amount of rebuilding.

I'll send an updated patch which “only” requires an update to
‘python-setuptools’. Since we're looking at updating that anyway, it
seems ok to me.

The packages I've had problems building can be fixed by explicitly
adding ‘python-toolchain’ or ‘python-setuptools’ to their native-inputs,
which should probably be there anyway.

-bjc
diff mbox series

Patch

diff --git a/gnu/packages/python-build.scm b/gnu/packages/python-build.scm
index 70719c44d4..d9f6f5beff 100644
--- a/gnu/packages/python-build.scm
+++ b/gnu/packages/python-build.scm
@@ -299,7 +299,21 @@  (define-public python-setuptools
     (build-system python-build-system)
     ;; FIXME: Tests require pytest, which itself relies on setuptools.
     ;; One could bootstrap with an internal untested setuptools.
-    (arguments (list #:tests? #f))
+    (arguments
+     (list
+      #:tests? #f
+      #:phases
+      #~(modify-phases %standard-phases
+          ;; Disable the check which requires files to be dated from at least
+          ;; 1980.
+          ;;
+          ;; This phase is also in the base python package, as it includes its
+          ;; own setuptools.
+          (add-after 'unpack 'disable-zipfile-date-check
+            (lambda _
+              (substitute* "setuptools/command/bdist_egg.py"
+                (("zipfile.ZipFile\\(zip_filename, mode, compression=compression\\)")
+                 "zipfile.ZipFile(zip_filename, mode, compression=compression, strict_timestamps=False)")))))))
     (home-page "https://pypi.org/project/setuptools/")
     (synopsis "Library designed to facilitate packaging Python projects")
     (description "Setuptools is a fully-featured, stable library designed to
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index bfe8a68352..8e30fc127a 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -518,6 +518,31 @@  (define-public python-3.10
                                (find-files "." #:directories? #t))))
                     (delete-file-recursively dir)))
                 (find-files "Lib/ensurepip" "\\.whl$"))))
+           (add-after 'unpack 'disable-zipfile-date-check
+             (lambda _
+               ;; Disable pre-1980 check in setuptools, because Guix mostly
+               ;; sets timestamps to 0 epoch seconds when building.
+               ;;
+               ;; This phase is also included in the python-setuptools
+               ;; package.
+               (let ((dir "whl-content")
+                     (circa-1980 (* 10 366 24 60 60))
+                     (setuptools-whl "../Lib/ensurepip/_bundled/setuptools-63.2.0-py3-none-any.whl"))
+                 (mkdir-p dir)
+                 (with-directory-excursion dir
+                   (invoke "unzip" setuptools-whl)
+                   (substitute* "setuptools/command/bdist_egg.py"
+                     (("zipfile.ZipFile\\(zip_filename, mode, compression=compression\\)")
+                      "zipfile.ZipFile(zip_filename, mode, compression=compression, strict_timestamps=False)"))
+                   (delete-file setuptools-whl)
+                   ;; Reset timestamps to prevent them from ending
+                   ;; up in the Zip archive.
+                   (ftw "." (lambda (file stat flag)
+                              (utime file circa-1980 circa-1980)
+                              #t))
+                   (apply invoke "zip" "-X" setuptools-whl
+                               (find-files "." #:directories? #t)))
+                 (delete-file-recursively dir))))
            (add-before 'check 'set-TZDIR
              (lambda* (#:key inputs native-inputs #:allow-other-keys)
                ;; test_email requires the Olson time zone database.