From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?utf-8?B?5a6L5paH5q2m?=) Subject: Re: [PATCH] gnu: python: Honor 'GUIX_PYTHON_X_Y_SITE_PACKAGES'. Date: Sun, 18 Mar 2018 08:07:08 +0800 Message-ID: <87po42utzn.fsf@member.fsf.org> References: <87371tqbyb.fsf@elephly.net> <20180223165953.GA6088@thebird.nl> <40dc2378-a039-fec8-55cd-23911f1642ab@crazy-compilers.com> <87lgerwk9s.fsf@member.fsf.org> <874llfvtl6.fsf_-_@member.fsf.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exLr8-0001wR-AZ for guix-devel@gnu.org; Sat, 17 Mar 2018 20:07:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exLr5-0004b8-5X for guix-devel@gnu.org; Sat, 17 Mar 2018 20:07:22 -0400 Received: from rezeros.cc ([2001:19f0:7001:2f3e:5400:ff:fe84:e55d]:41372) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exLr4-0004Wt-LS for guix-devel@gnu.org; Sat, 17 Mar 2018 20:07:19 -0400 In-Reply-To: <874llfvtl6.fsf_-_@member.fsf.org> (=?utf-8?B?IuWui+aWhw==?= =?utf-8?B?5q2mIidz?= message of "Sat, 17 Mar 2018 19:18:13 +0800") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Hartmut Goebel Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable iyzsong@member.fsf.org (=E5=AE=8B=E6=96=87=E6=AD=A6) writes: >> 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: > > [patch with typo...] > > > This targets 'core-updates' and will rebuild the world, I can't afford > to test it... Updated with typo fixed: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-gnu-python-2.7-python-3.6-Honor-GUIX_PYTHON_X_Y_SITE.patch >From d9c273c0ee8c5e87b12b37a325c649f8df808af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= 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 . See 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 --=-=-=--