From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Evgenii Klimov via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call Date: Wed, 28 Aug 2024 00:13:25 +0100 Message-ID: <87v7zlo8yy.fsf@lipklim.org> Reply-To: Evgenii Klimov Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30337"; mail-complaints-to="usenet@ciao.gmane.io" To: 72849@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 28 03:22:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sj7OG-0007jy-8J for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Aug 2024 03:22:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sj7O1-0004AU-8y; Tue, 27 Aug 2024 21:22:13 -0400 Original-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 1sj7Nx-0004AD-Nh for bug-gnu-emacs@gnu.org; Tue, 27 Aug 2024 21:22:10 -0400 Original-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 1sj7Nx-0007kT-ER for bug-gnu-emacs@gnu.org; Tue, 27 Aug 2024 21:22:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=8/rHMyNG/uPcovRz6cceL1iJEZlxcVtjZx9tmdc4DSU=; b=K88UTRjlM4kuQI/TpHy7KLx2hX1auxlo2P7v2/GPzQ5NbJl6zsf+igTkaLtMhOZZDRIV96Ceufx9uyYgk22SEXZfjxkS0lbbyPRHPaqOLlNOTt7HH4XqUQisFTAczkIldTDVsEfkOViw9yNqaN+Q87EEcZwOWkyR9SYpIfGbPTuPGq3W+db34BYnTWyvvIX4ilII5qwNTTMBivRFEmG0EnRJkMJlWAsKeAX3/J0THX4+2LvHVBTw9d+4uj8Ere0E0qdsgdVbTAb6CMa9oHH8pBHQ/E7WeAT15nNSURd/tr33oaENwJXzSZycr0TnYhKi5Y6T+cyewLxEH/J/E3utWA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sj7Oo-00005r-AI for bug-gnu-emacs@gnu.org; Tue, 27 Aug 2024 21:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Evgenii Klimov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Aug 2024 01:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72849 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172480813632751 (code B ref -1); Wed, 28 Aug 2024 01:23:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Aug 2024 01:22:16 +0000 Original-Received: from localhost ([127.0.0.1]:47925 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sj7O2-0008W9-9r for submit@debbugs.gnu.org; Tue, 27 Aug 2024 21:22:16 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:40846) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sj5OS-0004uF-83 for submit@debbugs.gnu.org; Tue, 27 Aug 2024 19:14:34 -0400 Original-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 1sj5NX-00028i-4r for bug-gnu-emacs@gnu.org; Tue, 27 Aug 2024 19:13:37 -0400 Original-Received: from out-178.mta1.migadu.com ([95.215.58.178]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sj5NU-00006j-6G for bug-gnu-emacs@gnu.org; Tue, 27 Aug 2024 19:13:34 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lipklim.org; s=key1; t=1724800408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=8/rHMyNG/uPcovRz6cceL1iJEZlxcVtjZx9tmdc4DSU=; b=FwnT/dSNID02x/Efm+/pzXdpXTHw+GThBEkxBAdf8UcdYTDpRYLoh6S+UoUuPgtXv1gjJK kQ98sdrH0LCKg45SjUIYuHVNe3ztliz5JdkvuJwBURJ02l+XmeUEqAubdfqzk1rCL6S3k6 xsrDDIhhKrA4Rvf7Vscgsox8Pn0FYcM= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.178; envelope-from=eugene.dev@lipklim.org; helo=out-178.mta1.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 27 Aug 2024 21:22:13 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290845 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tags: patch `with-temp-buffer' doesn't respect buffer-local environment variables, `exec-path' in this case. Which results in executables not being found, or the wrong versions of executables being picked up. E.g. if environment variable is modified via .dir-local file or direnv/envrc package. I see that this function tries to be remote-host friendly (uses `process-file') so I tried to ensure that this patch doesn't break this effort, but I'm not sure that I understand the machinery behind TRAMP correctly. So please consider this aspect from your side. This patch shouldn't interfere with TRAMP, if I understand `process-file`s doc correctly: If a file name handler is invoked, it determines the program to run based on the first argument PROGRAM. For instance, suppose that a handler for remote files is invoked. Then the path that is used for searching for the program might be different from =E2=80=98exec-pa= th=E2=80=99. In GNU Emacs 30.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) Windowing system distributor 'The X.Org Foundation', version 11.0.12101011 System Description: Guix System Configured using: 'configure CONFIG_SHELL=3D/gnu/store/fl3l5wx8qynjrvx5lilz6c38hb77cf36-bash-minimal-5.= 1.16/bin/bash SHELL=3D/gnu/store/fl3l5wx8qynjrvx5lilz6c38hb77cf36-bash-minimal-5.1.16/bi= n/bash --prefix=3D/gnu/store/45nwc8hc8fn1fhvr9qw01ylkfpvzxwsw-emacs-next-30.0.60-= 1.4e22ef8 --enable-fast-install --with-cairo --with-modules --with-native-compilation=3Daot --disable-build-details' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Keep-project-s-exec-path-during-with-temp-buffer-cal.patch >From 9a6ca1c11a2849753fd3b854a79561224629a6bf Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Tue, 27 Aug 2024 23:08:47 +0100 Subject: [PATCH] Keep project's exec-path during with-temp-buffer call * lisp/progmodes/python.el (python-shell-prompt-detect): `with-temp-buffer' doesn't respect buffer-local environment variables, `exec-path' in this case. Which results in executables not being found, or the wrong versions of executables being picked up. E.g. if env var is modified via .dir-local file or direnv/envrc package. --- lisp/progmodes/python.el | 44 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 7193cc19425..d6bb409c286 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3116,27 +3116,29 @@ (defun python-shell-prompt-detect () (interpreter python-shell-interpreter) (interpreter-arg python-shell-interpreter-interactive-arg) (output - (with-temp-buffer - ;; TODO: improve error handling by using - ;; `condition-case' and displaying the error message to - ;; the user in the no-prompts warning. - (ignore-errors - (let ((code-file - ;; Python 2.x on Windows does not handle - ;; carriage returns in unbuffered mode. - (let ((inhibit-eol-conversion (getenv "PYTHONUNBUFFERED"))) - (python-shell--save-temp-file code)))) - (unwind-protect - ;; Use `process-file' as it is remote-host friendly. - (process-file - interpreter - code-file - '(t nil) - nil - interpreter-arg) - ;; Try to cleanup - (delete-file code-file)))) - (buffer-string))) + (let ((current-exec-path exec-path)) + (with-temp-buffer + ;; TODO: improve error handling by using + ;; `condition-case' and displaying the error message to + ;; the user in the no-prompts warning. + (ignore-errors + (let ((code-file + ;; Python 2.x on Windows does not handle + ;; carriage returns in unbuffered mode. + (let ((inhibit-eol-conversion (getenv "PYTHONUNBUFFERED"))) + (python-shell--save-temp-file code)))) + (unwind-protect + ;; Use `process-file' as it is remote-host friendly. + (let ((exec-path current-exec-path)) + (process-file + interpreter + code-file + '(t nil) + nil + interpreter-arg)) + ;; Try to cleanup + (delete-file code-file)))) + (buffer-string)))) (prompts (catch 'prompts (dolist (line (split-string output "\n" t)) -- 2.45.2 --=-=-=--