all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Evgenii Klimov <eugene.dev@lipklim.org>, kobarity <kobarity@gmail.com>
Cc: 72849@debbugs.gnu.org
Subject: bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call
Date: Wed, 28 Aug 2024 15:12:54 +0300	[thread overview]
Message-ID: <86y14ghmm1.fsf@gnu.org> (raw)
In-Reply-To: <87v7zlo8yy.fsf@lipklim.org> (bug-gnu-emacs@gnu.org)

> 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" <bug-gnu-emacs@gnu.org>
> 
> `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 <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
> 





  parent reply	other threads:[~2024-08-28 12:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86y14ghmm1.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=72849@debbugs.gnu.org \
    --cc=eugene.dev@lipklim.org \
    --cc=kobarity@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.