From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?utf-8?B?5a6L5paH5q2m?=) Subject: Re: PYTHONPATH issue explanation Date: Sun, 18 Mar 2018 18:05:49 +0800 Message-ID: <87k1u9u29u.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> <5d65c8d2-e31b-ee1e-2b9a-145913015c7b@crazy-compilers.com> <87fu4yurno.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]:59568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exVCV-0001Wj-SO for guix-devel@gnu.org; Sun, 18 Mar 2018 06:06:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exVCR-0000KZ-Tx for guix-devel@gnu.org; Sun, 18 Mar 2018 06:06:03 -0400 Received: from rezeros.cc ([2001:19f0:7001:2f3e:5400:ff:fe84:e55d]:41406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exVCR-0000Jr-DX for guix-devel@gnu.org; Sun, 18 Mar 2018 06:05:59 -0400 In-Reply-To: <87fu4yurno.fsf@member.fsf.org> (=?utf-8?B?IuWui+aWh+atpiIn?= =?utf-8?B?cw==?= message of "Sun, 18 Mar 2018 08:57:31 +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'd like do more tests with the GUIX_PYTHON_X_Y_SITE_PACKAGES option > (patch sent), hope it works :-) Hello, I have write a shell script to do some tests, it looks good to me! Updated 'GUIX_PYTHON_X_Y_SITE_PACKAGES' patch, target 'core-updates' at commit 171a117c (you also have to comment out the "manual-database" profile hook in the "guix/profiles.scm", as it's broken in that commit): --=-=-= 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 d807306d02aab0a84de4fa3ff457a5b97ac15520 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 | 65 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index f3a75c30e..45de8c527 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* (#:key 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 @@ -428,13 +471,19 @@ data types.") ,file))) (find-files out "\\.py$"))) (list '() '("-O") '("-OO"))) + #t))) + (replace 'install-sitecustomize.py + (lambda* (#:key 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 --=-=-= Content-Type: text/plain And here is the test script: --=-=-= Content-Type: application/x-sh Content-Disposition: attachment; filename=test-python-site-packages.sh Content-Transfer-Encoding: base64 IyEvYmluL3NoCiMgVGhpcyBzY3JpcHQgd2lsbCBydW4gc29tZSB0ZXN0cyBmb3IgZ3VpeCdzIHB5 dGhvbjIgYW5kIHB5dGhvbjMsCiMgdGhlaXIgc3lzLnBhdGgsIGhhbmRpbmcgb2Ygc2l0ZS1wYWNr YWdlcywgZXRjLgoKIyBBYm9ydCB3aGVuIGFueSBjb21tYW5kIGZhaWxzLgpzZXQgLWUKCiMgW0hl bHBlciBmdW50aW9uc10KZnVuY3Rpb24gX2RvKCkgewogICAgZWNobyAiJEAiCiAgICBlY2hvICI9 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT0iCn0KCmZ1bmN0aW9uIF9vaygpIHsKICAgIGVjaG8gIj09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PSIKICAgIGVjaG8KICAgIGVjaG8K fQoKZnVuY3Rpb24gX2RpZSgpIHsKICAgIGVjaG8gIj09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PSIKICAgIGVjaG8gIkVSUk9SOiAkQCIg PiAvZGV2L3N0ZGVycgogICAgZXhpdCAxCn0KCgojIFtDaGVja3NdClRFU1RESVI9JChwd2QpL190 ZXN0XwoKX2RvICJNYWtlIHN1cmUgd2UncmUgaW4gdGhlIGNoZWNrb3V0IG9mIGd1aXguIgouL3By ZS1pbnN0LWVudiBndWl4IC0tdmVyc2lvbiB8fCBcCiAgICBfZGllICJQbGVhc2UgY2QgaW50byB0 aGUgY2hlY2tvdXQgb2YgZ3VpeC4iCl9vawoKX2RvICJDcmVhdGUgYSBlbXB0eSBkaXJlY3Rvcnkg JHtURVNURElSfSBmb3IgdGVzdC4iCm1rZGlyICR7VEVTVERJUn0gfHwgXAogICAgX2RpZSAiSWYg aXQgZXhpc3RzIGFscmVhbHksIHlvdSBjYW4gZGVsZXRlIGl0IG1hbnVhbGx5LiIKX29rCgpf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J9L3B5My12 ZW52K3N5c3RlbS1zaXRlLXBhY2thZ2VzL2Jpbi9weXRob24gLVNjICdpbXBvcnQgY2xpY2s7IHBy aW50KGNsaWNrKScgJiYgXAogICAgX2RpZSAiRmFpbGVkLiIKX29rCgoKCmVjaG8gIkxvb2tzIGdv b2Qgc28gZmFyISIKZWNobyAiJHtURVNURElSfSBpcyBhdmFpbGFibGUgZm9yIGZ1dHVyZSB0ZXN0 cy4uLiIK --=-=-= Content-Type: text/plain Do I miss something? Thanks! --=-=-=--