From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call Date: Wed, 28 Aug 2024 15:12:54 +0300 Message-ID: <86y14ghmm1.fsf@gnu.org> References: <87v7zlo8yy.fsf@lipklim.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29668"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72849@debbugs.gnu.org To: Evgenii Klimov , kobarity Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 28 14:13: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 1sjHYF-0007Wm-Om for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Aug 2024 14:13:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHY0-0001gL-5g; Wed, 28 Aug 2024 08:13:12 -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 1sjHXx-0001VF-Dv for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 08:13: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 1sjHXx-0008GD-4b for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 08:13:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=ompPeFPR6s3WzQO54Duxcx3udK2WiIBSEaABjPoXuZs=; b=HOEUYU3N3HTOjp1MjTKckaRxM5kycFrWi/tDeVz6nMup7Dq+HWYwnCRpeO5FqfLb/tUoOpQF7zFTCod24lABPkLmTaSMFG5r4X6Qf4shGHiS/t3dr9Nlc5fMuH6O+atU8NrfcVE2EolabDRqcOusBccS5HP2R0rMzMyOwLDmC/p7z5h9rhprvRcAf0LGsfbeW8gwTOoJAThfBYZdWuWkezW7/URln1N99ROx0+b06g5BxuZcZXBxyihUNhg/qE+kGjJBbsdUyP4pIzth0eGG+yY/1HfAOW4KnA3wn8uTmBWKjkEysdPmwJPPzkhZetBnerk6x7I7fRnN0+tEf466Ng==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjHYo-000279-9K for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 08:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Aug 2024 12:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72849 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72849-submit@debbugs.gnu.org id=B72849.17248472398111 (code B ref 72849); Wed, 28 Aug 2024 12:14:02 +0000 Original-Received: (at 72849) by debbugs.gnu.org; 28 Aug 2024 12:13:59 +0000 Original-Received: from localhost ([127.0.0.1]:48386 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjHYl-00026j-3x for submit@debbugs.gnu.org; Wed, 28 Aug 2024 08:13:59 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:47792) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjHYj-00026S-HM for 72849@debbugs.gnu.org; Wed, 28 Aug 2024 08:13:58 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHXk-0008EJ-VI; Wed, 28 Aug 2024 08:12:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=ompPeFPR6s3WzQO54Duxcx3udK2WiIBSEaABjPoXuZs=; b=JAYYd6g2+vLl bTrdOm2p9l8cq07mV7SmTExo0AygGbYYUog+MQ/mzKwCZG4lEtp7tQetMWGnql9ykvo3cJ2FFI42z n9TIly2IFSx/VDKGDWV3ktc7BHUmeXESx9hEsZLPDw5PzfHEG7WqxtXA+p8fCE3RJeQGfiaCMuLSZ fPAJFsnLvmIlbwaUCL/te+yICWEN0fTrNN0atbMCGIUIxntsv/9XU1bR8d0dlvWLpeRQ7rItWPH1r boNAtHrEBKmq2ubESl+JX5RCj1P6Fdz2hH0vRRlgQ7Tfx9v6Gc154FiZwI5IAx3QmC/Gxz0MQ8vNF SJ2ArPjhcWZRTGtNw83sEQ==; In-Reply-To: <87v7zlo8yy.fsf@lipklim.org> (bug-gnu-emacs@gnu.org) 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:290862 Archived-At: > Date: Wed, 28 Aug 2024 00:13:25 +0100 > From: Evgenii Klimov via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > `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. Hmm, this doesn't look clean to me: exec-path is just one variable, what makes it special here? Moreover, it sounds like python-shell-with-environment, which python-shell-prompt-detect calls, already attempts to have buffer-local value of exec-path to be available to Python, so why isn't that working for you? And if it isn't work, I think we should amend python-shell-with-environment to do this, so we don't need to do it "by hand". kobarity, any comments or suggestions? > >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 >