From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#72849: [PATCH] Keep project's exec-path during with-temp-buffer call Date: Fri, 30 Aug 2024 01:08:25 +0900 Message-ID: References: <87v7zlo8yy.fsf@lipklim.org> <86y14ghmm1.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Fri_Aug_30_01:08:25_2024-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18410"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 72849@debbugs.gnu.org To: Eli Zaretskii , Evgenii Klimov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 29 18:10:32 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 1sjhjD-0004eu-Fi for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Aug 2024 18:10:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjhir-0006Wb-1m; Thu, 29 Aug 2024 12:10:09 -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 1sjhio-0006Vy-RU for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 12:10:07 -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 1sjhio-0004bI-IT for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 12:10:06 -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:References:In-Reply-To:From:Date:To:Subject; bh=diDjS/SvO8xrSqGPSemnPtkLyX08isjvgDUXEbNGsAE=; b=toImxu6ZfL1Pxqe1rnONkguEip2tWfkDNbOkx/GwfR+n1Ba6oXXtEEMKCUd2tSzGa5Yp56/Mj5JCgso8JGvyGxDPNk6j1i7OpbJyPgfoq3BiqQ4WO9ytGWOyIj5DzyhQGSBzgXxPEpUa+BUrDQKEBw/s5i+Nvj8qtH3mmU0MTladuER1us50SBdyVpusDuaPs/k9QNnupy0cqFQqxhfIy/E9ZRwBzC5RaWOOJmFBvVZ5gDMxjRnaV+5u4OcUG7oEHvd4qZy09BCk2Awi4S+DxJdwFdllEzVXFAHsM0mEmyHxwK+tOQzDbE8TwH/I+FeH0/l2cHY1appL0fKw1Z3q/Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjhjh-0004fS-On for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 12:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Aug 2024 16:11:01 +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.172494783517880 (code B ref 72849); Thu, 29 Aug 2024 16:11:01 +0000 Original-Received: (at 72849) by debbugs.gnu.org; 29 Aug 2024 16:10:35 +0000 Original-Received: from localhost ([127.0.0.1]:52033 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjhjG-0004eK-SJ for submit@debbugs.gnu.org; Thu, 29 Aug 2024 12:10:35 -0400 Original-Received: from mail-pg1-f182.google.com ([209.85.215.182]:48610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjhjE-0004e3-2C for 72849@debbugs.gnu.org; Thu, 29 Aug 2024 12:10:33 -0400 Original-Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7cb3db0932cso569583a12.1 for <72849@debbugs.gnu.org>; Thu, 29 Aug 2024 09:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724947710; x=1725552510; darn=debbugs.gnu.org; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=diDjS/SvO8xrSqGPSemnPtkLyX08isjvgDUXEbNGsAE=; b=GusikFvnS+uHt+sGeXpbp4D3bZxUrkDANWg//e1wX7iRP1jtlZbblgCIis1UIHVfQR qfcoLpWGjQmjuw3AfElQYjFEfS+iCOkZNtbdjy4m53qwXp9NN+wyc0aJd28949c7kQeT d5tHT5G0xXGgMhFnkJ4iV/kT8Xhfd2HwbZsDXvkLMg0KYe6Kdk7Zzb5RGxO20N6YjsZQ 8EVwQ9OuGT8g584/qGTTefHvX7H/YfnsqN0jM4PXTmfLITwnLQVAc4NtMcbb3hvUCZCa AMyFCkdlXy7YuwwNQWf/UtVcyqBTintVuZmb0J6+kVGaCnx4rvtgshBBbEbsvTwaZQXV cPwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724947710; x=1725552510; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=diDjS/SvO8xrSqGPSemnPtkLyX08isjvgDUXEbNGsAE=; b=RCrm74BJ+6c9BhKoiZ8JWA4kVEC2+kjUhbLgOQqPKeC2uL+59QHr7DB28nix7d0+Ym 9nQE1eplOTBLGIV6ZoV/tghM3ijt3DZlDYQLC1pq/U41EKcgsiurx5+gVQBsZHVcVdNC VzXHci5zOg/f85LoydqqhUHLBgPINl8TRK23U2IgA9EWUSsKnJV5KlooHiO24XVu4zDg NxOHUHaWMp8tr/rk8rV1EVXWijVc7qg6PxRqnyxznA5ICFFJMkhY63j/1crzuMhaSOUQ 2H8HCGn7+NSd2j9ceHOB/7JcSoWm1w30dQa8vKSWb5CJCMIRW6oJEMAuhaFfyJJzwaeF krzQ== X-Gm-Message-State: AOJu0YyoJhiLLpwiQD6Y73pz4Pes64LxHwbfb6LQcM8TBBlE7LxBcRW4 WJ/6QYDSlpKCrxS4VQWeMQLI7uUlT6agAbINwsdpSQVcBRHqXbcq X-Google-Smtp-Source: AGHT+IEY2ujG+zrbtuz/Cs0GnG5uLMn6Pht1fgdYveTV2D/NSHFcrjoZKMNBdlnxwcECpUy+CuPqEA== X-Received: by 2002:a17:90a:51c4:b0:2c2:df58:bb8c with SMTP id 98e67ed59e1d1-2d85619f138mr3750970a91.18.1724947710056; Thu, 29 Aug 2024 09:08:30 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d8445e7faesm4340707a91.16.2024.08.29.09.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 09:08:29 -0700 (PDT) In-Reply-To: <86y14ghmm1.fsf@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:290939 Archived-At: --Multipart_Fri_Aug_30_01:08:25_2024-1 Content-Type: text/plain; charset=US-ASCII Eli Zaretskii wrote: > > 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? The problem is that `with-temp-buffer' creates a new buffer, so the buffer local value of `exec-path' is not maintained in the new buffer. It is used to find the Python interpreter unless the interpreter is specified using the absolute path. I think Evgenii's patch is logically correct, but it would be better to create a modified version of `with-temp-buffer' which keeps `exec-path' in the new buffer. The attached is my proposal to do so. --Multipart_Fri_Aug_30_01:08:25_2024-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-Python-prompt-detection-when-exec-path-is-buffer.patch" Content-Disposition: attachment; filename="0001-Fix-Python-prompt-detection-when-exec-path-is-buffer.patch" Content-Transfer-Encoding: 7bit >From b94ba0d4e07635a0abddf0cba7548b10b47dad92 Mon Sep 17 00:00:00 2001 From: kobarity Date: Fri, 30 Aug 2024 00:13:27 +0900 Subject: [PATCH] Fix Python prompt detection when 'exec-path' is buffer local * lisp/progmodes/python.el (python-with-temp-buffer): New macro same as 'with-temp-buffer', except the variable 'exec-path' is kept in the new buffer. (python-shell-prompt-detect): Use it. (Bug#72849) Co-authored-by: Evgenii Klimov --- lisp/progmodes/python.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a00289d6de9..480713c3aca 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3088,6 +3088,16 @@ 'python--parse-json-array (json-read-from-string string)))) "Parse the JSON array in STRING into a Lisp list.") +(defmacro python-with-temp-buffer (&rest body) + "Python mode specific version of `with-temp-buffer'. +Call `with-temp-buffer' with BODY. The variable `exec-path' is kept in +the new buffer even if it is buffer local." + (declare (indent 0) (debug t)) + `(let ((python--exec-path exec-path)) + (with-temp-buffer + (let ((exec-path python--exec-path)) + ,@body)))) + (defun python-shell-prompt-detect () "Detect prompts for the current `python-shell-interpreter'. When prompts can be retrieved successfully from the @@ -3116,7 +3126,7 @@ python-shell-prompt-detect (interpreter python-shell-interpreter) (interpreter-arg python-shell-interpreter-interactive-arg) (output - (with-temp-buffer + (python-with-temp-buffer ;; TODO: improve error handling by using ;; `condition-case' and displaying the error message to ;; the user in the no-prompts warning. -- 2.34.1 --Multipart_Fri_Aug_30_01:08:25_2024-1--