From patchwork Fri Jan 22 04:51:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 26555 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 31E2727BC18; Fri, 22 Jan 2021 04:52:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9B8FF27BC17 for ; Fri, 22 Jan 2021 04:52:10 +0000 (GMT) Received: from localhost ([::1]:50410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2oQb-0001m5-QE for patchwork@mira.cbaines.net; Thu, 21 Jan 2021 23:52:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2oQU-0001l4-FF for guix-patches@gnu.org; Thu, 21 Jan 2021 23:52:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:48342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2oQU-0003Ze-7V 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-0004VW-6W 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 1/2] utils: Add a version-minor procedure. References: <20210122044816.30058-1-maxim.cournoyer@gmail.com> In-Reply-To: <20210122044816.30058-1-maxim.cournoyer@gmail.com> 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.161129108417268 (code B ref 46028); Fri, 22 Jan 2021 04:52:02 +0000 Received: (at 46028) by debbugs.gnu.org; 22 Jan 2021 04:51:24 +0000 Received: from localhost ([127.0.0.1]:59885 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2oPs-0004US-3F for submit@debbugs.gnu.org; Thu, 21 Jan 2021 23:51:24 -0500 Received: from mail-qt1-f172.google.com ([209.85.160.172]:41855) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2oPr-0004UE-6t for 46028@debbugs.gnu.org; Thu, 21 Jan 2021 23:51:23 -0500 Received: by mail-qt1-f172.google.com with SMTP id j26so3312590qtq.8 for <46028@debbugs.gnu.org>; Thu, 21 Jan 2021 20:51:23 -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:mime-version :content-transfer-encoding; bh=BnUvdc6F7dARSUrR/n00PIxJaMIUGiN35ztDYge8pag=; b=sdaEQ0n8HnNiPdT+8imHMxddgJ4bMNTWiEEa6lHVO5CMtoz+eAHl4yhvzCif++rr7N Y2nHH8mdMdClgMFqN0KwbaCcWqa0u+olvfC/dsF7c/5NHUtkyFUMeDJWy5V+j1ejEOFt dCCB9wr7/aZmhEhs4MkP3HYep6vT7LvZXRdlEt1/9fhaE+Tem3rg2p8hZJTtR0rcPJvF gfJo0SaBWMuFWuAmiqb7M6HEq3Y8Tu0OGkBAHNmhQBL99a8hJkBCAjA4Be2XTvdZchvE 1B3W1l+M7MxpL0iqW7jzx9duoJHr5zHZWQUm0uavexbj7roLJt/hM7xF5Wb7ybNpZ62c /SVQ== 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:mime-version :content-transfer-encoding; bh=BnUvdc6F7dARSUrR/n00PIxJaMIUGiN35ztDYge8pag=; b=m7NLBQ8/MWixIS3lZEuvSAytt5RPuFRRf8IAILgNri3zVbiIYOBDPar8c6OSmPPulw lj7dcvI13td6cBov4RB2LFVl2RT0kCLfksttvSpLu9jLiYUSCBI7Wgv7lGD8Gqiarue6 Xyrn0SgFeJfYE5NDhFwYrCQ+fsAPR1MVd0rPTEkqZhY93sjnEGyhGG2bkxrldt7IJgbJ hzx7DzKWwnxBFoSUnilqBp/yI07zlK8MjIFKO9gKNq/hOp+25aNfX/ZLF2zBLzXpgr2Q gntCzp1EAUR8j2f77CvKGlEKOMG4CH7F2oRDjJKIerK/f1pIsBFWsrFjWguYGhmULzkV GatQ== X-Gm-Message-State: AOAM5328hMxHk+7oCCdmJxzBBQlBvx1HaIY3vDkQFITZzgzDbwED/C+r HSKiRFkA2Gfb6wn7fQ+I4j4caEJkgsM= X-Google-Smtp-Source: ABdhPJxiMBa2JLKH60R7QTj7Oh6PkfKBDUMUyWvhgWAVHpeJKqqR1IuMqDJS3X5VjEKPGu0LZLeQ/g== X-Received: by 2002:ac8:782:: with SMTP id l2mr2813930qth.271.1611291077360; Thu, 21 Jan 2021 20:51:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 20:51:16 -0800 (PST) From: Maxim Cournoyer Date: Thu, 21 Jan 2021 23:51:03 -0500 Message-Id: <20210122045104.30229-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/utils.scm (version-components): New procedure. (version-prefix): Use it. (version-major): Likewise. (version-minor): New procedure. --- guix/utils.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/guix/utils.scm b/guix/utils.scm index 678954dbfa..cd4e595f7e 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -8,7 +8,7 @@ ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2018, 2020 Marius Bakke ;;; Copyright © 2020 Efraim Flashner -;;; Copyright © 2020 Maxim Cournoyer +;;; Copyright © 2020, 2021 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -93,6 +93,7 @@ version-major+minor+point version-major+minor version-major + version-minor guile-version>? version-prefix? string-replace-substring @@ -573,10 +574,14 @@ or '= when they denote equal versions." ((negative? result) '<) (else '=)))))) +(define (version-components version-string) + "Return the dot-separated version components as a list." + (string-split version-string #\.)) + (define (version-prefix version-string num-parts) "Truncate version-string to the first num-parts components of the version. For example, (version-prefix \"2.1.47.4.23\" 3) returns \"2.1.47\"" - (string-join (take (string-split version-string #\.) num-parts) ".")) + (string-join (take (version-components version-string) num-parts) ".")) (define (version-major+minor+point version-string) "Return \"major>..\", where major, minor and point are the @@ -595,7 +600,11 @@ minor version numbers from version-string." (define (version-major version-string) "Return the major version number as string from the version-string." - (version-prefix version-string 1)) + (first (version-components version-string))) + +(define (version-minor version-string) + "Return the minor version number as string from the version-string." + (second (version-components version-string))) (define (version>? a b) "Return #t when A denotes a version strictly newer than B." From patchwork Fri Jan 22 04:51:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 26554 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1B55A27BC18; Fri, 22 Jan 2021 04:52:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9B4D027BC17 for ; Fri, 22 Jan 2021 04:52:09 +0000 (GMT) Received: from localhost ([::1]:50384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2oQa-0001lJ-P3 for patchwork@mira.cbaines.net; Thu, 21 Jan 2021 23:52:08 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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"))))