diff options
| author | kobarity | 2025-08-06 23:08:49 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2025-08-07 16:06:28 +0300 |
| commit | 3d8fbb0716df669b552daef8ada02b4357ca7b49 (patch) | |
| tree | 3191cf3b757172866372fbd876f9af7ba835bb58 /lisp/progmodes/python.el | |
| parent | 68aaeb3519fd7f6176050e142f0dbc27e07992d2 (diff) | |
| download | emacs-3d8fbb0716df669b552daef8ada02b4357ca7b49.tar.gz emacs-3d8fbb0716df669b552daef8ada02b4357ca7b49.zip | |
Fix Python PDB tracking for remote inferior Python
* lisp/progmodes/python.el (python-shell-local-prefix): New
constant.
(python-shell--convert-file-name-to-send): New function to
add/remove prefix.
(python-shell-send-string, python-shell-send-file): Changed to
use 'python-shell--convert-file-name-to-send'.
(python-pdbtrack-set-tracked-buffer): Changed to add/remove
prefix.
* test/lisp/progmodes/python-tests.el
(python-shell--convert-file-name-to-send-1): New test.
(Bug#79036)
Diffstat (limited to '')
| -rw-r--r-- | lisp/progmodes/python.el | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 8b5ffae57d6..3cd20d6babf 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3698,6 +3698,10 @@ def __PYTHON_EL_eval_file(filename, tempname, delete): | |||
| 3698 | "Code used to evaluate files in inferior Python processes. | 3698 | "Code used to evaluate files in inferior Python processes. |
| 3699 | The coding cookie regexp is specified in PEP 263.") | 3699 | The coding cookie regexp is specified in PEP 263.") |
| 3700 | 3700 | ||
| 3701 | (defconst python-shell-local-prefix "/local:" | ||
| 3702 | "A prefix used to indicate that a file is local. | ||
| 3703 | It is used when sending file names to remote Python processes.") | ||
| 3704 | |||
| 3701 | (defun python-shell-comint-watch-for-first-prompt-output-filter (output) | 3705 | (defun python-shell-comint-watch-for-first-prompt-output-filter (output) |
| 3702 | "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT." | 3706 | "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT." |
| 3703 | (when (not python-shell--first-prompt-received) | 3707 | (when (not python-shell--first-prompt-received) |
| @@ -4016,6 +4020,27 @@ there for compatibility with CEDET.") | |||
| 4016 | (signal 'wrong-type-argument (list 'stringp text))))) | 4020 | (signal 'wrong-type-argument (list 'stringp text))))) |
| 4017 | "Encode TEXT as a valid Python string.") | 4021 | "Encode TEXT as a valid Python string.") |
| 4018 | 4022 | ||
| 4023 | (defun python-shell--convert-file-name-to-send (process file-name) | ||
| 4024 | "Convert the FILE-NAME for sending to the inferior Python PROCESS. | ||
| 4025 | If PROCESS is local and FILE-NAME is prefixed with | ||
| 4026 | `python-shell-local-prefix', remove the prefix. If PROCESS is remote | ||
| 4027 | and the FILE-NAME is not prefixed, prepend `python-shell-local-prefix'. | ||
| 4028 | If PROCESS is remote and the file is on the same remote host, remove the | ||
| 4029 | remote prefix. Otherwise, return the file name as is." | ||
| 4030 | (when file-name | ||
| 4031 | (let ((process-prefix | ||
| 4032 | (file-remote-p | ||
| 4033 | (with-current-buffer (process-buffer process) default-directory))) | ||
| 4034 | (local-prefix (string-prefix-p python-shell-local-prefix file-name))) | ||
| 4035 | (cond | ||
| 4036 | ((and (not process-prefix) local-prefix) | ||
| 4037 | (string-remove-prefix python-shell-local-prefix file-name)) | ||
| 4038 | ((and process-prefix (not (or local-prefix (file-remote-p file-name)))) | ||
| 4039 | (concat python-shell-local-prefix (file-local-name file-name))) | ||
| 4040 | ((and process-prefix (string= (file-remote-p file-name) process-prefix)) | ||
| 4041 | (file-local-name file-name)) | ||
| 4042 | (t file-name))))) | ||
| 4043 | |||
| 4019 | (defun python-shell-send-string (string &optional process msg) | 4044 | (defun python-shell-send-string (string &optional process msg) |
| 4020 | "Send STRING to inferior Python PROCESS. | 4045 | "Send STRING to inferior Python PROCESS. |
| 4021 | When optional argument MSG is non-nil, forces display of a | 4046 | When optional argument MSG is non-nil, forces display of a |
| @@ -4023,11 +4048,13 @@ user-friendly message if there's no process running; defaults to | |||
| 4023 | t when called interactively." | 4048 | t when called interactively." |
| 4024 | (interactive | 4049 | (interactive |
| 4025 | (list (read-string "Python command: ") nil t)) | 4050 | (list (read-string "Python command: ") nil t)) |
| 4026 | (let ((process (or process (python-shell-get-process-or-error msg))) | 4051 | (let* ((process (or process (python-shell-get-process-or-error msg))) |
| 4027 | (code (format "__PYTHON_EL_eval(%s, %s)\n" | 4052 | (code (format "__PYTHON_EL_eval(%s, %s)\n" |
| 4028 | (python-shell--encode-string string) | 4053 | (python-shell--encode-string string) |
| 4029 | (python-shell--encode-string (or (buffer-file-name) | 4054 | (python-shell--encode-string |
| 4030 | "<string>"))))) | 4055 | (or (python-shell--convert-file-name-to-send |
| 4056 | process (buffer-file-name)) | ||
| 4057 | "<string>"))))) | ||
| 4031 | (unless python-shell-output-filter-in-progress | 4058 | (unless python-shell-output-filter-in-progress |
| 4032 | (with-current-buffer (process-buffer process) | 4059 | (with-current-buffer (process-buffer process) |
| 4033 | (save-excursion | 4060 | (save-excursion |
| @@ -4358,7 +4385,8 @@ t when called interactively." | |||
| 4358 | temp-file-name (with-temp-buffer | 4385 | temp-file-name (with-temp-buffer |
| 4359 | (insert-file-contents file-name) | 4386 | (insert-file-contents file-name) |
| 4360 | (python-shell--save-temp-file (current-buffer)))))) | 4387 | (python-shell--save-temp-file (current-buffer)))))) |
| 4361 | (let* ((file-name (file-local-name (expand-file-name file-name))) | 4388 | (let* ((file-name (python-shell--convert-file-name-to-send |
| 4389 | process (expand-file-name file-name))) | ||
| 4362 | (temp-file-name (when temp-file-name | 4390 | (temp-file-name (when temp-file-name |
| 4363 | (file-local-name (expand-file-name | 4391 | (file-local-name (expand-file-name |
| 4364 | temp-file-name))))) | 4392 | temp-file-name))))) |
| @@ -5082,8 +5110,12 @@ Never set this variable directly, use | |||
| 5082 | "Set the buffer for FILE-NAME as the tracked buffer. | 5110 | "Set the buffer for FILE-NAME as the tracked buffer. |
| 5083 | Internally it uses the `python-pdbtrack-tracked-buffer' variable. | 5111 | Internally it uses the `python-pdbtrack-tracked-buffer' variable. |
| 5084 | Returns the tracked buffer." | 5112 | Returns the tracked buffer." |
| 5085 | (let* ((file-name-prospect (concat (file-remote-p default-directory) | 5113 | (let* ((file-name-prospect |
| 5086 | file-name)) | 5114 | (if (string-prefix-p python-shell-local-prefix file-name) |
| 5115 | (string-remove-prefix python-shell-local-prefix file-name) | ||
| 5116 | (if (file-remote-p file-name) | ||
| 5117 | file-name | ||
| 5118 | (concat (file-remote-p default-directory) file-name)))) | ||
| 5087 | (file-buffer (get-file-buffer file-name-prospect))) | 5119 | (file-buffer (get-file-buffer file-name-prospect))) |
| 5088 | (unless file-buffer | 5120 | (unless file-buffer |
| 5089 | (cond | 5121 | (cond |