all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call
@ 2024-08-27 23:13 Evgenii Klimov via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-28  7:12 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-28 12:12 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Evgenii Klimov via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-08-27 23:13 UTC (permalink / raw)
  To: 72849

[-- Attachment #1: Type: text/plain, Size: 1576 bytes --]

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 ‘exec-path’.


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=/gnu/store/fl3l5wx8qynjrvx5lilz6c38hb77cf36-bash-minimal-5.1.16/bin/bash
 SHELL=/gnu/store/fl3l5wx8qynjrvx5lilz6c38hb77cf36-bash-minimal-5.1.16/bin/bash
 --prefix=/gnu/store/45nwc8hc8fn1fhvr9qw01ylkfpvzxwsw-emacs-next-30.0.60-1.4e22ef8
 --enable-fast-install --with-cairo --with-modules
 --with-native-compilation=aot --disable-build-details'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Keep-project-s-exec-path-during-with-temp-buffer-cal.patch --]
[-- Type: text/patch, Size: 3219 bytes --]

From 9a6ca1c11a2849753fd3b854a79561224629a6bf Mon Sep 17 00:00:00 2001
From: Evgenii Klimov <eugene.dev@lipklim.org>
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-08-31 10:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-27 23:13 bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call Evgenii Klimov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-28  7:12 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-28 12:12 ` Eli Zaretskii
2024-08-29 16:08   ` kobarity
2024-08-29 16:25     ` Eli Zaretskii
2024-08-29 22:51   ` Evgenii Klimov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-30 14:43     ` kobarity
2024-08-31 10:17       ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.