>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