unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Julien Lepiller <julien@lepiller.eu>
To: 47214@debbugs.gnu.org
Subject: [bug#47214] [core-updates] gnu: python: Remove unnecessary files
Date: Fri, 19 Mar 2021 00:08:30 +0100	[thread overview]
Message-ID: <20210319000830.23926447@tachikoma.lepiller.eu> (raw)
In-Reply-To: <20210317133933.5eb6d325@tachikoma.lepiller.eu>

[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]

Le Wed, 17 Mar 2021 13:41:02 +0100,
Julien Lepiller <julien@lepiller.eu> a écrit :

> Hi Guix!
> 
> this patch (going to core-updates) removes files from the output of
> python2 and python3, in an attempt to save some space. First, I
> noticed that python3 shipped windows binaries in its source
> distribution and installs them to the output, in
> lib/python3.8/distutils/command/*.exe,
> lib/python3.8/site-packages/*.exe and
> lib/python3.8/site-packages/pip/_vendor/distlib/*.exe. I remove them
> from the snippet, so they should not be installed anymore.
> 
> I also noticed that python installs files that were built during the
> test phase, so I remove them, but we need to check they are not
> actually needed. Other distros ship them in a separate package, so
> maybe we could have a separate test output if this is causing issues?
> 
> I haven't yet tested the patch, because it needs to rebuild part of
> the bootstrap chain. I'll report progress and update my patch
> depending on the results!

I discovered other .exe in python3, so this updated patch deletes them.
Since I modify the python from commencement.scm by changing a phase in
python-2.7, I decided to also change the definition there to remove the
offending files.

I managed to build up to python-3.9 without any issue, but haven't
tested building more than a handful of python packages.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-python-Remove-unnecessary-files.patch --]
[-- Type: text/x-patch, Size: 6312 bytes --]

From 0d2d9a32cbbf24eadf74271b2fb1304b7a72d281 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Wed, 17 Mar 2021 13:33:22 +0100
Subject: [PATCH 1/2] gnu: python: Remove unnecessary files.

* gnu/packages/python.scm (python2)[arguments]: Remove files built
during the test phase.
(python3)[arguments]: Also remove windows binaries shipped with the
sources.
---
 gnu/packages/commencement.scm |  9 ++++++++-
 gnu/packages/python.scm       | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index b2921a4a48..b2b9651444 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -10,6 +10,7 @@
 ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
 ;;; Copyright © 2020 Guy Fleury Iteriteka <gfleury@disroot.org>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -3098,7 +3099,12 @@ memoized as a function of '%current-system'."
                    (delete-file-recursively "Modules/expat")
                    (substitute* "Modules/Setup.dist"
                      ;; Link Expat instead of embedding the bundled one.
-                     (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n")))))))
+                     (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
+                   ;; Delete windows binaries
+                   (for-each delete-file
+                             (find-files "Lib/distutils/command" ".*.exe$"))
+                   (for-each delete-file
+                             (find-files "Lib/ensurepip" ".*.whl$")))))))
     (inputs
      `(,@(%boot0-inputs)
        ("expat" ,expat-sans-tests)))              ;remove OpenSSL, zlib, etc.
@@ -3129,6 +3135,7 @@ memoized as a function of '%current-system'."
                                          ('add-after unpack apply-alignment-patch _))
                                        `(modify-phases ,original-phases ,@changes))
                                       (_ phases)))
+               (delete 'remove-windows-binaries)
                (add-before 'configure 'disable-modules
                  (lambda _
                    (substitute* "setup.py"
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 49d43ab008..da9859b11a 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -31,7 +31,7 @@
 ;;; Copyright © 2016 Dylan Jeffers <sapientech@sapientech@openmailbox.org>
 ;;; Copyright © 2016, 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2016, 2017, 2018 Arun Isaac <arunisaac@systemreboot.net>
-;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2016, 2017, 2018, 2021 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2016, 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2016, 2017 Thomas Danckaert <post@thomasdanckaert.be>
 ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
@@ -294,7 +294,16 @@
                                             (not
                                              (string-prefix? "test_support."
                                                              file))))))
-                      (call-with-output-file "__init__.py" (const #t)))))))))
+                      (call-with-output-file "__init__.py" (const #t))))
+                  (let ((libdir (string-append out "/lib/" pythonX.Y)))
+                    (for-each
+                     (lambda (directory)
+                       (let ((dir (string-append libdir "/" directory)))
+                         (when (file-exists? dir)
+                           (delete-file-recursively dir))))
+                     '("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")))
@@ -424,6 +433,9 @@ data types.")
                   (substitute* "Modules/Setup"
                     ;; Link Expat instead of embedding the bundled one.
                     (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
+                  ;; Delete windows binaries
+                  (for-each delete-file
+                            (find-files "Lib/distutils/command" ".*.exe$"))
                   #t))))
     (arguments
      (substitute-keyword-arguments (package-arguments python-2)
@@ -469,6 +481,23 @@ data types.")
            ,@(if (hurd-system?)
                  `((delete 'patch-regen-for-hurd)) ;regen was removed after 3.5.9
                  '())
+           (add-after 'unpack 'remove-windows-binaries
+             (lambda _
+               ;; Delete .exe from embedded .whl (zip) files
+               (for-each
+                (lambda (whl)
+                  (let ((dir "whl-content"))
+                    (mkdir-p dir)
+                    (with-directory-excursion dir
+                      (let ((whl (string-append "../" whl)))
+                        (invoke "unzip" whl)
+                        (for-each delete-file
+                                  (find-files "." ".*.exe$"))
+                        (delete-file whl)
+                        (apply invoke "zip" "-X" whl
+                               (find-files "." ".*" #:directories? #t))))
+                    (delete-file-recursively dir)))
+                (find-files "Lib/ensurepip" ".*.whl$"))))
            (add-before 'check 'set-TZDIR
              (lambda* (#:key inputs native-inputs #:allow-other-keys)
                ;; test_email requires the Olson time zone database.
@@ -503,6 +532,8 @@ data types.")
              ,(customize-site version))))))
     (native-inputs
      `(("tzdata" ,tzdata-for-tests)
+       ("unzip" ,unzip)
+       ("zip" ,(@ (gnu packages compression) zip))
        ,@(if (%current-target-system)
              `(("python3" ,this-package))
              '())
-- 
2.30.0


  parent reply	other threads:[~2021-03-18 23:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 12:41 [bug#47214] [core-updates] gnu: python: Remove unnecessary files Julien Lepiller
2021-03-17 19:22 ` Efraim Flashner
2021-03-18 23:08 ` Julien Lepiller [this message]
2021-03-19 12:27   ` Ludovic Courtès
2021-06-03  1:56     ` Julien Lepiller
2021-06-03  9:46       ` Ludovic Courtès
2021-06-11  1:01         ` bug#47214: " Julien Lepiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210319000830.23926447@tachikoma.lepiller.eu \
    --to=julien@lepiller.eu \
    --cc=47214@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).