all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: iyzsong@member.fsf.org (宋文武)
To: Hartmut Goebel <h.goebel@crazy-compilers.com>
Cc: guix-devel@gnu.org
Subject: [PATCH] gnu: python: Honor 'GUIX_PYTHON_X_Y_SITE_PACKAGES'.
Date: Sat, 17 Mar 2018 19:18:13 +0800	[thread overview]
Message-ID: <874llfvtl6.fsf_-_@member.fsf.org> (raw)
In-Reply-To: <87lgerwk9s.fsf@member.fsf.org> ("宋文武"'s message of "Sat, 17 Mar 2018 09:41:51 +0800")

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


> I plan to implement option 1 by adding a "sitecustomize.py" (better
> than modify "site.py") into the python packages, and modify
> "search-path-specification" to use "GUIX_PYTHON_X_Y_SITE_PACKAGES".

Patch coming:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-python-2.7-python-3.6-Honor-GUIX_PYTHON_X_Y_SITE.patch --]
[-- Type: text/x-patch, Size: 4962 bytes --]

From d9c273c0ee8c5e87b12b37a325c649f8df808af3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <iyzsong@member.fsf.org>
Date: Sat, 17 Mar 2018 18:46:55 +0800
Subject: [PATCH] gnu: python-2.7, python-3.6: Honor
 'GUIX_PYTHON_X_Y_SITE_PACKAGES'.

This replace the use of 'PYTHONPATH' as search path specification, as
suggested by Hartmut Goebel <h.goebel@crazy-compilers.com>.  See
<https://lists.gnu.org/archive/html/guix-devel/2018-03/msg00178.html> for
details.

* gnu/packages/python.scm (python-guix-search-path-specification)
(python-guix-sitecustomize.py): New procedures.
(python-2.7, python-3.6):
[native-search-paths]: Use 'python-guix-search-path-specification'.
[arguments]: Add 'install-sitecustomize.py' phase.
---
 gnu/packages/python.scm | 67 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 58 insertions(+), 9 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 6639e6c9e..2ce8db710 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -136,6 +136,41 @@
   #:use-module (guix build-system trivial)
   #:use-module (srfi srfi-1))
 
+(define (python-guix-search-path-specification version)
+  "Return the search path specification for python VERSION."
+  (let* ((major.minor (version-major+minor version))
+         (variable    (string-append
+                       "GUIX_PYTHON_"
+                       (string-replace-substring major.minor "." "_")
+                       "_SITE_PACKAGES"))
+         (files       (list (string-append
+                             "lib/python" major.minor "/site-packages"))))
+    (search-path-specification
+     (variable variable)
+     (files files))))
+
+(define (python-guix-sitecustomize.py version)
+  "Return the content of @file{sitecustomize.py} for python VERSION."
+  (let* ((major.minor (version-major+minor version))
+         (variable    (string-append
+                       "GUIX_PYTHON_"
+                       (string-replace-substring major.minor "." "_")
+                       "_SITE_PACKAGES")))
+    (format #f "# Append module search paths for guix packages to sys.path.
+import os
+import site
+
+SITE_PACKAGES = os.environ.get('~a')
+
+if SITE_PACKAGES is None:
+    SITE_PACKAGES = []
+else:
+    SITE_PACKAGES = SITE_PACKAGES.split(os.pathsep)
+
+for i in SITE_PACKAGES:
+    site.addsitedir(i)
+" variable)))
+
 (define-public python-2.7
   (package
     (name "python2")
@@ -304,6 +339,16 @@
                                      "/site-packages")))
                        (install-file tkinter.so target)
                        (delete-file tkinter.so)))))
+                #t)))
+          (add-after 'install 'install-sitecustomize.py
+            (lambda* (#:keys outputs #:allow-other-keys)
+              (let* ((out (assoc-ref outputs "out"))
+                     (sitedir (car (find-files out "^site-packages$"
+                                               #:directories #t))))
+                (with-output-to-file
+                    (string-append sitedir "/sitecustomize.py")
+                  (lambda ()
+                    (display ,(python-guix-sitecustomize.py version))))
                 #t))))))
     (inputs
      `(("bzip2" ,bzip2)
@@ -318,9 +363,7 @@
     (native-inputs
      `(("pkg-config" ,pkg-config)))
     (native-search-paths
-     (list (search-path-specification
-            (variable "PYTHONPATH")
-            (files '("lib/python2.7/site-packages")))))
+     (list (python-guix-search-path-specification version)))
     (home-page "https://www.python.org")
     (synopsis "High-level, dynamically-typed programming language")
     (description
@@ -427,13 +470,19 @@ data types.")
                                          "-x" "(lib2to3|test/bad.*)"
                                          ,file)))
                               (find-files out "\\.py$")))
-                  (list '() '("-O") '("-OO"))))))))))
+                  (list '() '("-O") '("-OO"))))))
+           (replace 'install-sitecustomize.py
+             (lambda* (#:keys outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (sitedir (car (find-files out "^site-packages$"
+                                                #:directories #t))))
+                 (with-output-to-file
+                     (string-append sitedir "/sitecustomize.py")
+                   (lambda ()
+                     (display ,(python-guix-sitecustomize.py version))))
+                 #t)))))))
     (native-search-paths
-     (list (search-path-specification
-            (variable "PYTHONPATH")
-            (files (list (string-append "lib/python"
-                                        (version-major+minor version)
-                                        "/site-packages"))))))))
+     (list (python-guix-search-path-specification version)))))
 
 ;; Current 3.x version.
 (define-public python-3 python-3.6)
-- 
2.13.3


[-- Attachment #3: Type: text/plain, Size: 86 bytes --]


This targets 'core-updates' and will rebuild the world, I can't afford
to test it...

  parent reply	other threads:[~2018-03-17 11:18 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20 10:53 PYTHONPATH woes Ricardo Wurmus
2018-02-20 15:01 ` Pjotr Prins
2018-02-20 15:18   ` Andy Wingo
2018-02-20 16:40     ` Pjotr Prins
2018-02-20 15:30   ` Ricardo Wurmus
2018-02-21 21:58 ` Hartmut Goebel
2018-02-22 15:30   ` Ricardo Wurmus
2018-02-22 18:35     ` Hartmut Goebel
2018-02-22 20:42     ` Hartmut Goebel
2018-02-23  8:45       ` Vincent Legoll
2018-02-23 12:36     ` Hartmut Goebel
2018-02-23 16:59       ` Pjotr Prins
2018-02-23 19:36         ` Ricardo Wurmus
2018-02-23 23:54           ` Pjotr Prins
2018-02-24 10:44         ` Hartmut Goebel
2018-02-24 10:49           ` Hartmut Goebel
2018-02-27 11:43           ` PYTHONPATH issue analysis - part 1 (was: PYTHONPATH woes) Hartmut Goebel
2018-03-13 21:54             ` PYTHONPATH issue analysis - part 1 Hartmut Goebel
2018-02-27 11:49           ` PYTHONPATH issue analysis - part 2 (was: PYTHONPATH woes) Hartmut Goebel
2018-03-11 21:47           ` PYTHONPATH issue analysis - part 3 " Hartmut Goebel
2018-03-13 21:23             ` PYTHONPATH issue analysis - part 3 Ludovic Courtès
2018-03-13 21:44               ` Pjotr Prins
2018-03-13 22:02                 ` Hartmut Goebel
2018-03-14  7:49                   ` Pjotr Prins
2018-03-14  9:04                     ` Hartmut Goebel
2018-03-14 18:21                       ` Pjotr Prins
2018-03-15 19:48                     ` Hartmut Goebel
2018-03-13 21:47               ` Hartmut Goebel
2018-03-14  9:41                 ` Ludovic Courtès
2018-03-13 21:51               ` Hartmut Goebel
2018-03-14  0:10               ` Ricardo Wurmus
2018-03-15  9:09                 ` Ludovic Courtès
2018-03-15 19:30             ` PYTHONPATH issue explanation Hartmut Goebel
2018-03-17  1:41               ` 宋文武
2018-03-17 10:07                 ` Ricardo Wurmus
2018-03-17 22:46                   ` Hartmut Goebel
2018-03-17 22:53                   ` Hartmut Goebel
2018-03-17 11:18                 ` 宋文武 [this message]
2018-03-17 21:53                   ` [PATCH] gnu: python: Honor 'GUIX_PYTHON_X_Y_SITE_PACKAGES' Hartmut Goebel
2018-03-18  0:04                     ` 宋文武
2018-03-18  0:07                   ` 宋文武
2018-03-17 22:04                 ` PYTHONPATH issue explanation Hartmut Goebel
2018-03-18  0:57                   ` 宋文武
2018-03-18 10:05                     ` 宋文武
2018-03-24 20:47               ` Chris Marusich
2018-04-16 14:21             ` PYTHONPATH - let's systematically tame the baest Hartmut Goebel
2018-04-17  1:47               ` 宋文武
2018-04-17  7:03                 ` Hartmut Goebel
2018-04-18  8:34               ` Ricardo Wurmus

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

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

  git send-email \
    --in-reply-to=874llfvtl6.fsf_-_@member.fsf.org \
    --to=iyzsong@member.fsf.org \
    --cc=guix-devel@gnu.org \
    --cc=h.goebel@crazy-compilers.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.