From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id CABUF/tZCmDLXgAA0tVLHw (envelope-from ) for ; Fri, 22 Jan 2021 04:52:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id ICQSE/tZCmABTgAAbx9fmQ (envelope-from ) for ; Fri, 22 Jan 2021 04:52:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B2770940275 for ; Fri, 22 Jan 2021 04:52:10 +0000 (UTC) Received: from localhost ([::1]:50384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2oQb-0001lJ-N2 for larch@yhetil.org; Thu, 21 Jan 2021 23:52:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2oQU-0001lA-Ur for guix-patches@gnu.org; Thu, 21 Jan 2021 23:52:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:48343) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2oQU-0003Zy-Nq for guix-patches@gnu.org; Thu, 21 Jan 2021 23:52:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l2oQU-0004Vd-J5 for guix-patches@gnu.org; Thu, 21 Jan 2021 23:52:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46028] [PATCH core-updates 2/2] gnu: python: Replace PYTHONPATH by GUIX_PYTHONPATH_X_Y. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 22 Jan 2021 04:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46028 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 46028@debbugs.gnu.org Received: via spool by 46028-submit@debbugs.gnu.org id=B46028.161129108717283 (code B ref 46028); Fri, 22 Jan 2021 04:52:02 +0000 Received: (at 46028) by debbugs.gnu.org; 22 Jan 2021 04:51:27 +0000 Received: from localhost ([127.0.0.1]:59888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2oPv-0004Uh-C7 for submit@debbugs.gnu.org; Thu, 21 Jan 2021 23:51:27 -0500 Received: from mail-qt1-f175.google.com ([209.85.160.175]:40816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2oPt-0004UH-Er for 46028@debbugs.gnu.org; Thu, 21 Jan 2021 23:51:25 -0500 Received: by mail-qt1-f175.google.com with SMTP id z22so3314434qto.7 for <46028@debbugs.gnu.org>; Thu, 21 Jan 2021 20:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DAKsMQUxZaW1nzVfX9e16+bw2XOIs+QM18RH8UFP5us=; b=dx+c4Aa6kMmmOT+O7r4sNYI4fuYDWwNFVbwESXXBe2KXZnFH7u4RNi3mcD492/HEiE soYTlTXM0sCXAlldT70bFyHk3Ml5waRH06X4LFWQJxuxud7sZITIlwm1PXEhPGpNUtHY kBSlhby0tiTM72ecV7pvGtJFyVS4jHY46ghW8LR75ENNn5hyH+VJ/5ESZuNrL+K0NUTu acFwOKVR995ot+B8m57ct48e+E1+xO39N/kECztXPMT83d/y0wzMqjue+b2Hb2SLAZWd 3Phe8Cfp2C3OpQ1yDpxgh5xWkVdfEfEWo6ADjOYWrbi2gl7yZzOsaUGZn135OZZjqQl7 T0Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DAKsMQUxZaW1nzVfX9e16+bw2XOIs+QM18RH8UFP5us=; b=ZKvkhUGEbjNWmXbB0ujMnHn/IdMU+rAldVPfdU+mFiaC7wnsCZ+XllHPhEowLKmZ/j bpBglONnhF9EfL5/I2IFVLOihFa0Xwzh24gQHwt/tZmCYMyma5Hq1hyqPden72rucneO Afde33UXPGi3KlZo20FmoB8WVzMeIMeM4O5t1KfzrjKVM4HFj5c3/Cv5WbSy4wZAXCif w9Z3wLoH0AkKsVT06LvNBCB/PCFaOytN0BjA965sOSokVNb9mqUPcivlL8hJYJNcROj5 Nv9wc0y3NMmjtL62OQRDH87tTYJd/v8IUL9PKMoiKOQGAw37viEupOZlQkG+A8VF7JNv TFEw== X-Gm-Message-State: AOAM532NheShAmuFlvCobv7fTOYXbq088+vpM8EyqCDaO2heoHy30gDg 1Za6M0iYpLtKBRxxhHPi1z2EpIH6I2c= X-Google-Smtp-Source: ABdhPJyTWvRGeXSx+wUFb1LPpOHSJD2U1NA9wiZrV1s5i4zha62levbFjdpLYsVLKXM5NgG9TsQTqw== X-Received: by 2002:ac8:2adb:: with SMTP id c27mr2921611qta.145.1611291079730; Thu, 21 Jan 2021 20:51:19 -0800 (PST) Received: from localhost.localdomain (dsl-152-143.b2b2c.ca. [66.158.152.143]) by smtp.gmail.com with ESMTPSA id h8sm5162004qtm.5.2021.01.21.20.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 20:51:19 -0800 (PST) From: Maxim Cournoyer Date: Thu, 21 Jan 2021 23:51:04 -0500 Message-Id: <20210122045104.30229-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210122045104.30229-1-maxim.cournoyer@gmail.com> References: <20210122045104.30229-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 2.75 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=dx+c4Aa6; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: B2770940275 X-Spam-Score: 2.75 X-Migadu-Scanner: scn0.migadu.com X-TUID: ojMJbmS+OZ3Z 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_X_Y environment variable, where X is the major and Y the minor version numbers, is read from the environment and spliced in 'sys.path' just before Python's own site location, which provides the expected behavior. * gnu/packages/python.scm (python-2.7)[phases]{customize-site}: Add phase. [native-search-paths]: Modify so that GUIX_PYTHONPATH_X_Y is used. * gnu/packages/python.scm (python-3.9)[native-search-paths]: Likewise. --- gnu/packages/python.scm | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index d3df1a4dab..79cea3d43a 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -313,7 +313,30 @@ "/site-packages"))) (install-file tkinter.so target) (delete-file tkinter.so))))) - #t)))))) + #t))) + (add-after 'install 'customize-site + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (site-packages (string-append + out "/lib/python" + ,(version-major+minor version) + "/site-packages")) + (pythonpath (format #f "GUIX_PYTHONPATH_~a_~a" + ,(version-major version) + ,(version-minor version))) + (sitecustomize.py (string-append site-packages + "/sitecustomize.py"))) + (with-output-to-file sitecustomize.py + (lambda _ + (format #t "\ +import os +import sys + +# Insert the GUIX_PYTHONPATH_X_Y values just before Python's own site. +sys_path_absolute = [os.path.realpath(p) for p in sys.path] +index = sys_path_absolute.index(~s) +sys.path = sys.path[:index] + os.environ[~s].split(':') + sys.path[index:] +" site-packages pythonpath))))))))) (inputs `(("bzip2" ,bzip2) ("expat" ,expat) @@ -334,8 +357,12 @@ '()))) (native-search-paths (list (search-path-specification - (variable "PYTHONPATH") - (files '("lib/python2.7/site-packages"))))) + (variable (format #f "GUIX_PYTHONPATH_~a_~a" + (version-major version) + (version-minor version))) + (files (list (string-append "lib/python" + (version-major+minor version) + "/site-packages")))))) (home-page "https://www.python.org") (synopsis "High-level, dynamically-typed programming language") (description @@ -472,7 +499,9 @@ data types.") ,@(package-native-inputs python-2))) (native-search-paths (list (search-path-specification - (variable "PYTHONPATH") + (variable (format #f "GUIX_PYTHONPATH_~a_~a" + (version-major version) + (version-minor version))) (files (list (string-append "lib/python" (version-major+minor version) "/site-packages")))) -- 2.29.2