unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50057: 27.2; Issue evaluating Python code across machines
@ 2021-08-14 16:01 Augusto Stoffel
  2021-08-15 12:01 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Augusto Stoffel @ 2021-08-14 16:01 UTC (permalink / raw)
  To: 50057

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

Suppose the current buffer is editing a local file and you would like to
evaluate some code on a Python inferior running in a remote machine.
The following should work:

(let ((default-directory "/ssh:some-remote-machine:/"))
  (run-python))

(python-shell-send-string "5+5")

(python-shell-send-string "(5\n+5)")

The first python-shell-send-string call indeed works.  The second one
produces an error, because a temporary file is created in the local
machine instead of the remote one.  The same kind of error happens if
one tries to evaluate the region on the entire buffer.

I've attached a small patch to fix this.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-evaluating-Python-code-across-machines.patch --]
[-- Type: text/x-patch, Size: 1230 bytes --]

From b3f47f99da7b8ac2221b6bbafc85ae8076f92703 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
Date: Sat, 14 Aug 2021 17:48:45 +0200
Subject: [PATCH] Allow evaluating Python code across machines

* python.el (python-shell-send-string): Ensure that the temporary file
is created in the host running the Python process.
---
 lisp/progmodes/python.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 2557704e40..20299c20d2 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3085,7 +3085,8 @@ python-shell-send-string
    (list (read-string "Python command: ") nil t))
   (let ((process (or process (python-shell-get-process-or-error msg))))
     (if (string-match ".\n+." string)   ;Multiline.
-        (let* ((temp-file-name (python-shell--save-temp-file string))
+        (let* ((temp-file-name (with-current-buffer (process-buffer process)
+                                 (python-shell--save-temp-file string)))
                (file-name (or (buffer-file-name) temp-file-name)))
           (python-shell-send-file file-name process temp-file-name t))
       (comint-send-string process string)
-- 
2.31.1


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

* bug#50057: 27.2; Issue evaluating Python code across machines
  2021-08-14 16:01 bug#50057: 27.2; Issue evaluating Python code across machines Augusto Stoffel
@ 2021-08-15 12:01 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-15 12:01 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 50057

Augusto Stoffel <arstoffel@gmail.com> writes:

> The first python-shell-send-string call indeed works.  The second one
> produces an error, because a temporary file is created in the local
> machine instead of the remote one.  The same kind of error happens if
> one tries to evaluate the region on the entire buffer.
>
> I've attached a small patch to fix this.

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-08-15 12:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14 16:01 bug#50057: 27.2; Issue evaluating Python code across machines Augusto Stoffel
2021-08-15 12:01 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).