From patchwork Sat Jan 6 09:37:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konrad Hinsen X-Patchwork-Id: 58425 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 F328427BBE9; Sat, 6 Jan 2024 09:38:18 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 38B3127BBE2 for ; Sat, 6 Jan 2024 09:38:17 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rM37v-0006Y1-F8; Sat, 06 Jan 2024 04:37:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rM37t-0006Xf-Q6 for guix-patches@gnu.org; Sat, 06 Jan 2024 04:37:57 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM37t-0002Oj-IR for guix-patches@gnu.org; Sat, 06 Jan 2024 04:37:57 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rM37x-0004tc-On for guix-patches@gnu.org; Sat, 06 Jan 2024 04:38:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68241] [PATCH] gnu: python: Fix sitecustomize.py References: In-Reply-To: Resent-From: Konrad Hinsen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 06 Jan 2024 09:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68241 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68241@debbugs.gnu.org Received: via spool by 68241-submit@debbugs.gnu.org id=B68241.170453385818790 (code B ref 68241); Sat, 06 Jan 2024 09:38:01 +0000 Received: (at 68241) by debbugs.gnu.org; 6 Jan 2024 09:37:38 +0000 Received: from localhost ([127.0.0.1]:58595 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM37Z-0004sz-OS for submit@debbugs.gnu.org; Sat, 06 Jan 2024 04:37:38 -0500 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:38771) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM37W-0004sj-Tv for 68241@debbugs.gnu.org; Sat, 06 Jan 2024 04:37:35 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 53CAA3200B35; Sat, 6 Jan 2024 04:37:24 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sat, 06 Jan 2024 04:37:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.net; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm2; t=1704533843; x=1704620243; bh=ZyjO1UMWmj b+1MHGEfjXUVDVcX8tsCJwWuc1RJ876n8=; b=GHo3VDeLehGLacWE/k+gGFa2dS 3U+RkQ7LBZoUJmD8L70Su919r2tAOgQzsE8kqPAmA1M65RRftxQwoKW6CYZnZOXh 0fFmdI503sYUi+JNFn/5DDwQkmy3q0/rCVD3ENJ+kCLlFdDhkVSHswufflw/iV2W qL8YoTzoxXoTyKGFsFfPiwy98glPRHwtumpMmytZkN59Dw5Cjs/+pLrQdyoW4KUZ o05xbPjNewJqFLVZzcfpCo6RuZqmQcRfV/HomnE90Q0f+3Z0034UKVfb/t+oXJtZ NN/xDQYKiXCygsHBwx0EdESLyzGpwQtYgq84EF3p+6fROI3l0VGfymmlusEg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1704533843; x=1704620243; bh=ZyjO1UMWmjb+1MHGEfjXUVDVcX8t sCJwWuc1RJ876n8=; b=Zj0+v42hTrC9n/zzXNa5wQSrUY6R+e4EU92YiOPINViB hCwxo7CFT64QX+imrrxQy07G7fme7BHmTyeiyr9L2LpQFsWGkJ6Us29aTwXWK8eY fooPHnVT50R1jVX85gl0aUH900FEk01Johbhx9wixb4XtQctOWEIWUu07t89H/rj HY0fyeyjL+NbtTIRDxmC08jQzkkwej4qcW5zv6lGP16RcYo+YNp5YWyfYbEaKsO7 Of2qH9RXun+f4vS+fweri0wg4ogU6hW9dASEf5oimOEQ8LMyRX7o/UygJBnzMKeP 0fc2PRaRo8osz4Cswt9+NYC6Sd/q6ueLCudl3QPUyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdehuddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkgggtgfesthhqredttd dtjeenucfhrhhomhepmfhonhhrrgguucfjihhnshgvnhcuoehkohhnrhgrugdrhhhinhhs vghnsehfrghsthhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnhepgfegheehlefhvd ffveffteejueeiffffkeetuddvfeevffevieetfeelveeifeelnecuffhomhgrihhnpehg nhhurdhorhhgpdhprghthhdrthhonecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepkhhonhhrrggurdhhihhnshgvnhesfhgrshhtmhgrihhlrdhn vght X-ME-Proxy: Feedback-ID: i184641e2:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 Jan 2024 04:37:22 -0500 (EST) From: Konrad Hinsen Date: Sat, 06 Jan 2024 10:37:23 +0100 Message-ID: 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/packages/aux-files/python/sitecustomize.py: normalize sys.prefix to deal with situations where it contains "../" This happens in particular when running Python from a Singularity image created by Guix. See https://issues.guix.gnu.org/53258. This is a variant of https://issues.guix.gnu.org/68241 that implements the fix as a graft rather than as a patch to the Python package. Since many packages in Guix depend on Python, the basic patch leads to enormous build times. A graft should be sufficient since the fix has no impact on Python being used within Guix. Change-Id: I3b07f4edf474a12fcabfbf90f37c4c0223278330 --- .../aux-files/python/sitecustomize-fixed.py | 65 +++++++++++++++++++ gnu/packages/python.scm | 22 ++++++- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 gnu/packages/aux-files/python/sitecustomize-fixed.py base-commit: 7b0863f07a113caef26fea13909bd97d250b629e diff --git a/gnu/packages/aux-files/python/sitecustomize-fixed.py b/gnu/packages/aux-files/python/sitecustomize-fixed.py new file mode 100644 index 0000000000..82ea91104d --- /dev/null +++ b/gnu/packages/aux-files/python/sitecustomize-fixed.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# GNU Guix --- Functional package management for GNU +# Copyright © 2021 Maxim Cournoyer +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Guix is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Guix. If not, see . + +import os +import site +import sys + +# Commentary: +# +# Site-specific customization for Guix. +# +# The program below honors the GUIX_PYTHONPATH environment variable to +# discover Python packages. File names appearing in this variable that match +# a predefined versioned installation prefix are added to the sys.path. To be +# considered, a Python package must be installed under the +# 'lib/pythonX.Y/site-packages' directory, where X and Y are the major and +# minor version numbers of the Python interpreter. +# +# Code: + +major_minor = '{}.{}'.format(*sys.version_info) +site_packages_prefix = os.path.join( + 'lib', 'python' + major_minor, 'site-packages') +python_site = os.path.normpath(os.path.join(sys.prefix, site_packages_prefix)) + +try: + all_sites_raw = os.environ['GUIX_PYTHONPATH'].split(os.path.pathsep) +except KeyError: + all_sites_raw = [] +# Normalize paths, otherwise a trailing slash would cause it to not match. +all_sites_norm = [os.path.normpath(p) for p in all_sites_raw] +matching_sites = [p for p in all_sites_norm + if p.endswith(site_packages_prefix)] + +if matching_sites: + # Deduplicate the entries, append them to sys.path, and handle any + # .pth files they contain. + for s in matching_sites: + site.addsitedir(s) + + # Move the entries that were appended to sys.path in front of + # Python's own site-packages directory. This enables Guix + # packages to override Python's bundled packages, such as 'pip'. + python_site_index = sys.path.index(python_site) + new_site_start_index = sys.path.index(matching_sites[0]) + if python_site_index < new_site_start_index: + sys.path = (sys.path[:python_site_index] + + sys.path[new_site_start_index:] + + sys.path[python_site_index:new_site_start_index]) diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 51d5f598d7..3cc3c08360 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -414,7 +414,16 @@ (define-public python-2.7 packages; exception-based error handling; and very high level dynamic data types.") (properties '((cpe-name . "python"))) - (license license:psfl))) + (license license:psfl) + (replacement python-2.7-fixed))) + +(define-public python-2.7-fixed + (package + (inherit python-2.7) + (native-inputs + (modify-inputs (package-native-inputs python-2.7) + (replace "sitecustomize.py" + (local-file (search-auxiliary-file "python/sitecustomize-fixed.py"))))))) ;; Current 2.x version. (define-public python-2 python-2.7) @@ -594,7 +603,16 @@ (define-public python-3.10 ;; Python 3.9. (search-path-specification (variable "PYTHONTZPATH") - (files (list "share/zoneinfo"))))))) + (files (list "share/zoneinfo"))))) + (replacement python-3.10-fixed))) + +(define-public python-3.10-fixed + (package + (inherit python-3.10) + (native-inputs + (modify-inputs (package-native-inputs python-3.10) + (replace "sitecustomize.py" + (local-file (search-auxiliary-file "python/sitecustomize-fixed.py"))))))) ;; Current 3.x version. (define-public python-3 python-3.10)