Subject: bug#79036: [PATCH] Fix pdb tracking for remote filenames

From: Liu Hui <[email-masked]>
Date: Tue, 22 Jul 2025 18:14:31 +0800

On Tue, Jul 22, 2025 at 12:01 AM kobarity <[email-masked]> wrote:

> The case of multiple remote hosts should also be considered.  In
> summary, it seems to me that it would be a good idea to pass the file
> names as shown in the following table.
>
> |                   | Local Python        | Python on remote1   |
> |-------------------+---------------------+---------------------|
> | Local tmp.py      | tmp.py              | /ssh::tmp.py        |
> | tmp.py on remote1 | /ssh:remote1:tmp.py | tmp.py              |
> | tmp.py on remote2 | /ssh:remote2:tmp.py | /ssh:remote2:tmp.py |
>
> Local Python cases are already covered with current python.el.
> Attached is a PoC-level patch to support Remote Python cases.
>
> What do you think of this approach?

Hi,

I think it is better since it explicitly identifies the source of
code. Then there is no confusion and file-exists-p is not needed in
python-pdbtrack-set-tracked-buffer.

> +(defun python-shell--file-name-to-send (process)
> +  "Return the file name to send to inferior Python PROCESS."
> +  (let ((file-name (buffer-file-name))
> +        (process-prefix
> +         (file-remote-p
> +          (with-current-buffer (process-buffer process) default-directory))))
> +    (if file-name
> +        (if process-prefix
> +            (let ((remote-p (file-remote-p file-name))
> +                  (local-name (file-local-name file-name)))
> +              (if remote-p
> +                  (if (string= remote-p process-prefix)
> +                      local-name
> +                    file-name)
> +                (concat python-shell-local-prefix local-name)))
> +          file-name)
> +      "<string>")))

For non-file buffers, could it return buffer name instead of <string>?
e.g. #<buffer NAME> or #<NAME> where NAME may need to be quoted. Then
python-pdbtrack-set-tracked-buffer can find it by (get-buffer-create
"NAME").