From cb72f9a773e0931ee3758c851d96007ded034e4c Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 21 Jan 2021 23:26:01 -0500 Subject: gnu: python: Replace PYTHONPATH by GUIX_PYTHONPATH. Using PYTHONPATH as a mean to discover the Python packages had the following issues: 1. It is not versioned, so different versions of Python would clash if installed in a shared profile. 2. It would interfere with the host Python site on foreign distributions, sometimes preventing a a user to login their GDM session (!). 3. It would take precedence over user installed Python packages installed through pip. 4. It would leak into Python virtualenvs, which are supposed to create isolated Python environments. This changes fixes the above issues by making use of a sitecustomize.py module. The newly introduced GUIX_PYTHONPATH environment variable is read from the environment, filtered for the current Python version of the interpreter, and spliced in 'sys.path' just before Python's own site location, which provides the expected behavior. * gnu/packages/aux-files/python/sitecustomize.py: New file. * Makefile.am: Register it. * gnu/packages/python.scm (customize-site) (guix-pythonpath-search-path): New procedures. (python-2.7)[phases]{install-sitecustomize.py}: New phase. [native-inputs]{sitecustomize.py}: New input. [native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH. (python-3.9)[native-search-paths]: Likewise. [phases]{install-sitecustomize}: Override with correct version. [native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH. * gnu/packages/commencement.scm (python-boot0): [phases]{install-sitecustomize}: Likewise. [native-inputs]{sitecustomize.py}: New input. [native-search-paths]: Replace PYTHONPATH with GUIX_PYTHONPATH. * guix/build/python-build-system.scm (site-packages): Do not add a trailing '/'. squash! gnu: python: Replace PYTHONPATH by GUIX_PYTHONPATH. --- gnu/packages/commencement.scm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gnu/packages/commencement.scm') diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm index 3e91179c71..22ec5a04ec 100644 --- a/gnu/packages/commencement.scm +++ b/gnu/packages/commencement.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2019, 2020 Marius Bakke ;;; Copyright © 2020 Timothy Sample ;;; Copyright © 2020 Guy Fleury Iteriteka +;;; Copyright © 2021 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,6 +55,7 @@ #:use-module (guix download) #:use-module (guix build-system gnu) #:use-module (guix build-system trivial) + #:use-module (guix gexp) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix memoization) #:use-module (guix utils) @@ -3095,7 +3097,9 @@ memoized as a function of '%current-system'." (inputs `(,@(%boot0-inputs) ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc. - (native-inputs '()) ;and pkg-config + (native-inputs ;and pkg-config + `(("sitecustomize.py" ,(local-file (search-auxiliary-file + "python/sitecustomize.py"))))) (arguments `(#:implicit-inputs? #f #:guile ,%bootstrap-guile @@ -3136,8 +3140,12 @@ memoized as a function of '%current-system'." (substitute* "Lib/plat-generic/regen" (("/usr/include/") (string-append libc "/include/"))))))) - '()))) - ((#:tests? _ #f) #f)))))) + '()) + (replace 'install-sitecustomize.py + ,(customize-site version)))) + ((#:tests? _ #f) #f)))) + (native-search-paths + (list (guix-pythonpath-search-path version))))) (define/system-dependent ld-wrapper-boot0 ;; The first 'ld' wrapper, defined with 'define/system-dependent' because -- cgit v1.2.3