Subject: bug#12340: 24.2.50; python-shell-switch-to-shell in TRAMP buffer gives "No such file or directory: '/var/folders/vk/p95wm1qx0vdf0087p0z9qzc40000gn/T/py62333GTT'"

From: Michael Albinus <[email-masked]>
Date: Wed, 05 Sep 2012 17:03:10 +0200

Matt McClure <[email-masked]> writes:

> Actually, the first attempt didn't really work. Here's an updated
> patch: <https://github.com/matthewlmcclure/emacs/compare/master...debbug-12340>.
> I've tested this one on local and remote interpreters, using
> python-shell-send-{buffer,region,file}.

This are more than 15 changed lines, it doesn't count as tiny change. If
you want to get it pushed to Emacs, you would need to sign FSF legal
papers. Are you interested in?

I believe, the patch is too complicate. When you call
python-shell-send-file, you pass file-name in remote syntax, but
temp-file-name already stripped to the local file name part on the
remote side. This confuses, I believe. I wouldn't use
host-rel-temp-file-name here, and just pass temp-file-name as it is. All
the remote name strippings could be performed in python-shell-send-file.
Something like this (completely untested, but you get the idea):

--8<---------------cut here---------------start------------->8---
*** ~/src/emacs/lisp/progmodes/python.el.~109871~	2012-09-05 16:01:08.029147300 +0200
--- ~/src/emacs/lisp/progmodes/python.el	2012-09-05 16:35:03.756949973 +0200
***************
*** 1824,1830 ****
          (lines (split-string string "\n" t)))
      (and msg (message "Sent: %s..." (nth 0 lines)))
      (if (> (length lines) 1)
!         (let* ((temp-file-name (make-temp-file "py"))
                 (file-name (or (buffer-file-name) temp-file-name)))
            (with-temp-file temp-file-name
              (insert string)
--- 1824,1834 ----
          (lines (split-string string "\n" t)))
      (and msg (message "Sent: %s..." (nth 0 lines)))
      (if (> (length lines) 1)
!         (let* ((temporary-file-directory
!                 (if (file-remote-p default-directory)
!                     (concat (file-remote-p default-directory) "/tmp")
!                   temporary-file-directory))
!                (temp-file-name (make-temp-file "py"))
                 (file-name (or (buffer-file-name) temp-file-name)))
            (with-temp-file temp-file-name
              (insert string)
***************
*** 1940,1946 ****
        (concat "__pyfile = open('''%s''');"
                "exec(compile(__pyfile.read(), '''%s''', 'exec'));"
                "__pyfile.close()")
!       (or temp-file-name file-name) file-name)
       process)))

  (defun python-shell-switch-to-shell ()
--- 1944,1951 ----
        (concat "__pyfile = open('''%s''');"
                "exec(compile(__pyfile.read(), '''%s''', 'exec'));"
                "__pyfile.close()")
!       (or (file-remote-p temp-file-name 'localname) temp-file-name)
!       (or (file-remote-p file-name 'localname) file-name))
       process)))

  (defun python-shell-switch-to-shell ()
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.