From unknown Thu Jun 19 14:04:16 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#50516 <50516@debbugs.gnu.org> To: bug#50516 <50516@debbugs.gnu.org> Subject: Status: Allow using 'python-shell-send-file' across machines Reply-To: bug#50516 <50516@debbugs.gnu.org> Date: Thu, 19 Jun 2025 21:04:16 +0000 retitle 50516 Allow using 'python-shell-send-file' across machines reassign 50516 emacs submitter 50516 Augusto Stoffel severity 50516 normal tag 50516 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 11 03:03:29 2021 Received: (at submit) by debbugs.gnu.org; 11 Sep 2021 07:03:29 +0000 Received: from localhost ([127.0.0.1]:39479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOx2u-0006Vi-Kk for submit@debbugs.gnu.org; Sat, 11 Sep 2021 03:03:28 -0400 Received: from lists.gnu.org ([209.51.188.17]:55464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOx2s-0006Vb-TB for submit@debbugs.gnu.org; Sat, 11 Sep 2021 03:03:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOx2s-0005Zc-NG for bug-gnu-emacs@gnu.org; Sat, 11 Sep 2021 03:03:26 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:42665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOx2q-0007zL-Td for bug-gnu-emacs@gnu.org; Sat, 11 Sep 2021 03:03:26 -0400 Received: by mail-wm1-x334.google.com with SMTP id u19-20020a7bc053000000b002f8d045b2caso2848184wmc.1 for ; Sat, 11 Sep 2021 00:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=J8wIG7cuAV+88WxuBNScAZ/qt3i6VB1x85vPNAoPK9U=; b=bKcTLWx2AatbfCgz2TknMkQtbRfNAtkd7k1oJDr5lQo32jx4aSDWxrHDlsE/MjqTZI fCHkuxvY73G0jMmEeOfGPCGSgbMLtMNPK9ugaeNQ0iT8iwVazi9fZ+tIvBlAjxYbMLwR wXzGwTLzRmpvR92PyaIyTXyxmpBqSHOdiRtuefvMeGX3FIHiULK7+o7RmsaDUbB8bgD5 LMv1kyLni5MggzHtVPCFr6fd4y/JHDbhTGSmJKXyn8roEhnct4S4d7jMcgv985rKD+tN jC5vkMpBmuzQ6sQ7gWAvT1Om1AtHzHYb/URJXKoTMgfjJLIn3HCOWraqx55aS2t/RFHE aMgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=J8wIG7cuAV+88WxuBNScAZ/qt3i6VB1x85vPNAoPK9U=; b=J+RmkXB8T03F4yi8ErXd3OMaQ3wix/BWveYRsa6Q0I9vs/AqGR8MZdqIXJW1g5uw3c k4ZsPKz+EoU/FR8temgF8qefe/QJVrGD+fvH68+z0I2DC1AyGVS+k/BFXrCwACgMFnS+ JHCP64Jmdwe2qYp/LzoC4UAliJmLGFuRU5sW2ExNd1uj/B27OiKDBSQFW+B7LlPoZH05 ZPiHBKlZpbKChrKu6NSqm1CEqKUNf0fPf4vS+mBAk00TOYVQJgsnki2zOekrvJu/QG3b PoiG9Zh+ejMc4HbLEkYjuVyaeIAJ7heW5fE4iwvIiIi4p/TtO0E1noKN2wQpVeOyqw88 aKPQ== X-Gm-Message-State: AOAM533KCYBxMQW1UC6lorVzGRTFEYolzx/wZcZ0Sng21mKvrv4wxL2Y QhE2HgTUNaOM09VSAlpMu2hYNxlvr8Ld2g== X-Google-Smtp-Source: ABdhPJzOaB09mFCgBFG83S5eJw4it60ugsfyZJJt+m7bpUAoHMD2aJotkgY0oeO3AX8m5/PWBQpx9g== X-Received: by 2002:a05:600c:35c4:: with SMTP id r4mr1463719wmq.194.1631343801766; Sat, 11 Sep 2021 00:03:21 -0700 (PDT) Received: from ars3 ([2a02:8109:8ac0:56d0::b1d]) by smtp.gmail.com with ESMTPSA id k18sm800034wmi.25.2021.09.11.00.03.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 00:03:21 -0700 (PDT) From: Augusto Stoffel To: bug-gnu-emacs@gnu.org Subject: Allow using 'python-shell-send-file' across machines Date: Sat, 11 Sep 2021 09:03:19 +0200 Message-ID: <87ee9vd26g.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=arstoffel@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain Tags: patch This addresses the case where you do 'C-c C-l' (python-shell-send-file) and the selected file is in a different machine than the Python process. (This is different from a patch I sent a while back, which concerned non-interactive use and ensured that the temp files were created in the right machine.) And I think this would be the last change I have to propose in the Python shell for the time being. Thanks! --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Allow-using-python-shell-send-file-across-machines.patch >From c32fd5541f97cc8e527f38c18ce7bc68b81a5513 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sat, 11 Sep 2021 08:27:25 +0200 Subject: [PATCH] Allow using 'python-shell-send-file' across machines * progmodes/python.el (python-shell-eval-file-setup-code): Look for a file coding cookie on the Python rather than on the Emacs side, to avoid additional file transfers. (python-shell--save-temp-file): Allow argument to be a buffer. (python-shell-send-file): Address the case where the selected file and the inferior process are on different machines. --- lisp/progmodes/python.el | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 2eef52de0c..22c4dfb375 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2842,14 +2842,20 @@ python-shell-eval-setup-code (defconst python-shell-eval-file-setup-code "\ -def __PYTHON_EL_eval_file(filename, tempname, encoding, delete): - import codecs, os +def __PYTHON_EL_eval_file(filename, tempname, delete): + import codecs, os, re + pattern = r'^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)' + with codecs.open(tempname or filename, encoding='latin-1') as file: + match = re.match(pattern, file.readline()) + match = match or re.match(pattern, file.readline()) + encoding = match.group(1) if match else 'utf-8' with codecs.open(tempname or filename, encoding=encoding) as file: source = file.read().encode(encoding) if delete and tempname: os.remove(tempname) return __PYTHON_EL_eval(source, filename)" - "Code used to evaluate files in inferior Python processes.") + "Code used to evaluate files in inferior Python processes. +The coding cookie regexp is specified in PEP 263.") (defun python-shell-comint-watch-for-first-prompt-output-filter (output) "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT." @@ -3126,7 +3132,9 @@ python-shell--save-temp-file (temp-file-name (make-temp-file "py")) (coding-system-for-write (python-info-encoding))) (with-temp-file temp-file-name - (insert string) + (if (bufferp string) + (insert-buffer-substring string) + (insert string)) (delete-trailing-whitespace)) temp-file-name)) @@ -3402,11 +3410,15 @@ python-shell-send-defun (defun python-shell-send-file (file-name &optional process temp-file-name delete msg) "Send FILE-NAME to inferior Python PROCESS. + If TEMP-FILE-NAME is passed then that file is used for processing instead, while internally the shell will continue to use -FILE-NAME. If TEMP-FILE-NAME and DELETE are non-nil, then -TEMP-FILE-NAME is deleted after evaluation is performed. When -optional argument MSG is non-nil, forces display of a +FILE-NAME. FILE-NAME can be remote, but TEMP-FILE-NAME must be +in the same host as PROCESS. If TEMP-FILE-NAME and DELETE are +non-nil, then TEMP-FILE-NAME is deleted after evaluation is +performed. + +When optional argument MSG is non-nil, forces display of a user-friendly message if there's no process running; defaults to t when called interactively." (interactive @@ -3416,22 +3428,25 @@ python-shell-send-file nil ; temp-file-name nil ; delete t)) ; msg - (let* ((process (or process (python-shell-get-process-or-error msg))) - (encoding (with-temp-buffer - (insert-file-contents - (or temp-file-name file-name)) - (python-info-encoding))) - (file-name (file-local-name (expand-file-name file-name))) + (setq process (or process (python-shell-get-process-or-error msg))) + (with-current-buffer (process-buffer process) + (unless (or temp-file-name + (string= (file-remote-p file-name) + (file-remote-p default-directory))) + (setq delete t + temp-file-name (with-temp-buffer + (insert-file-contents file-name) + (python-shell--save-temp-file (current-buffer)))))) + (let* ((file-name (file-local-name (expand-file-name file-name))) (temp-file-name (when temp-file-name (file-local-name (expand-file-name temp-file-name))))) (comint-send-string process (format - "__PYTHON_EL_eval_file(%s, %s, %s, %s)\n" + "__PYTHON_EL_eval_file(%s, %s, %s)\n" (python-shell--encode-string file-name) (python-shell--encode-string (or temp-file-name "")) - (python-shell--encode-string (symbol-name encoding)) (if delete "True" "False"))))) (defun python-shell-switch-to-shell (&optional msg) -- 2.31.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 11 09:02:36 2021 Received: (at 50516) by debbugs.gnu.org; 11 Sep 2021 13:02:36 +0000 Received: from localhost ([127.0.0.1]:39749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mP2eS-0002w7-47 for submit@debbugs.gnu.org; Sat, 11 Sep 2021 09:02:36 -0400 Received: from quimby.gnus.org ([95.216.78.240]:36774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mP2eQ-0002rR-HU for 50516@debbugs.gnu.org; Sat, 11 Sep 2021 09:02:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xISvRYam2yUg+piaBSmvQ29nNLlZmYYt7hSHBievf10=; b=iIITNAl6gQ33y0XEeWVljp6Bxk YhrJY92HiGVj9CMEDIuu0WDDRMjMWrkY9TiLeyJ+6QV67tD1pnw/oDs/krmjUgLCmj/4xtDohsEKx NIbcZHlIb2FclbzOgrMsPnedKnPw21BHugXevPaz2FJyiKbpiH9bKHUoUXJNvQDd+x10=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mP2eI-0000K5-L5; Sat, 11 Sep 2021 15:02:29 +0200 From: Lars Ingebrigtsen To: Augusto Stoffel Subject: Re: bug#50516: Allow using 'python-shell-send-file' across machines References: <87ee9vd26g.fsf@gmail.com> Date: Sat, 11 Sep 2021 15:02:26 +0200 In-Reply-To: <87ee9vd26g.fsf@gmail.com> (Augusto Stoffel's message of "Sat, 11 Sep 2021 09:03:19 +0200") Message-ID: <87tuirl0yl.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Augusto Stoffel writes: > This addresses the case where you do 'C-c C-l' (python-shell-send-file) > and the selected file is in a different machine than the Python process. > (This is different from a patch I sent a while ba [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 50516 Cc: 50516@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Augusto Stoffel writes: > This addresses the case where you do 'C-c C-l' (python-shell-send-file) > and the selected file is in a different machine than the Python process. > (This is different from a patch I sent a while back, which concerned > non-interactive use and ensured that the temp files were created in the > right machine.) Sounds good to me; pushed to Emacs 28. > And I think this would be the last change I have to propose in the > Python shell for the time being. Thanks! :-) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 11 09:02:40 2021 Received: (at control) by debbugs.gnu.org; 11 Sep 2021 13:02:40 +0000 Received: from localhost ([127.0.0.1]:39752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mP2eW-0002yj-Au for submit@debbugs.gnu.org; Sat, 11 Sep 2021 09:02:40 -0400 Received: from quimby.gnus.org ([95.216.78.240]:36788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mP2eU-0002uM-PU for control@debbugs.gnu.org; Sat, 11 Sep 2021 09:02:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=HGGAEF5cwdr+EluR//odxuNOF41eNbXWeNJaOl2XMBQ=; b=DvfpYnoniVPrMLjt8RBXHWYcDD zfWBoE+3f+Ed0aunuSFXcgZQ0ujVCuMWBB7VEde0p+b7qJegVeTjPkgysddhQRIyx84djQx/4R6Ow OnC4gcflLrRIMYQulOSHYTjPErjXv1OAgLf70WQmP8aioMwwlOlJ6RoJoDf+pjtc7Pr8=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mP2eN-0000KE-DU for control@debbugs.gnu.org; Sat, 11 Sep 2021 15:02:33 +0200 Date: Sat, 11 Sep 2021 15:02:31 +0200 Message-Id: <87sfybl0yg.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #50516 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 50516 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 50516 28.1 quit From unknown Thu Jun 19 14:04:16 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 10 Oct 2021 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator