emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>, Bastien Guerry <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: [DISCUSSION] Should we deprecate python-mode.el (alternative to built-in python.el) support in ob-python?
Date: Sun, 22 Jan 2023 14:21:29 -0800	[thread overview]
Message-ID: <877cxe2ot2.fsf@gmail.com> (raw)
In-Reply-To: <87wn6atjid.fsf@localhost>

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

Ihor Radchenko <yantar92@posteo.net> writes:

> Marked for future removal in ob-python.el.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=21741a469

Thanks Ihor.

Not sure if it's too early for this, but I've prepared a patch to remove
the support for python-mode.el, attached.

Also, to help any python-mode users with the transition, I ported the
code to support python-mode to an external package here:

https://gitlab.com/jackkamm/ob-python-mode-mode

As always, feedback is welcome, either on this patch or the external
package.

Best,
Jack


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-python-Remove-python-mode.el-support.patch --]
[-- Type: text/x-patch, Size: 7948 bytes --]

From 44bdfbbd9858f4190e4404467fa61b8a3f445347 Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
Date: Sat, 21 Jan 2023 08:24:41 -0800
Subject: [PATCH] ob-python: Remove python-mode.el support

* lisp/ob-python.el (org-babel-python-mode): Remove customization
variable.
(org-babel-python-initiate-session-by-key): Remove code to support
python-mode.el.
(org-babel-python-send-string): Renamed from
org-babel-python--send-string, turning it into a public function to
accommodate ob-python-mode-mode which advises this function. Also,
remove some code for python-mode.el
(org-babel-python-evaluate-session): Update calls to renamed function
org-babel-python-send-string.
---
 etc/ORG-NEWS      | 10 ++++++
 lisp/ob-python.el | 88 +++++++++++++----------------------------------
 2 files changed, 34 insertions(+), 64 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3ef76ec1a..ad7bd6604 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -12,6 +12,16 @@ See the end of the file for license conditions.
 Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 
 * Version 9.7 (not released yet)
+** Important announcements and breaking changes
+*** =python-mode.el (MELPA)= support in =ob-python.el= is removed
+
+=python-mode.el= support has been removed from =ob-python.el=. The
+related customization =org-babel-python-mode= has also been removed.
+
+If you still want to use python-mode with ob-python, you might
+consider [[https://gitlab.com/jackkamm/ob-python-mode-mode][ob-python-mode-mode]], where the code to support python-mode
+has been ported to.
+
 ** New options
 *** New options for the "csl" citation export processor's LaTeX output
 
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 39fe5c28d..f19440e00 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -36,10 +36,6 @@ (require 'ob)
 (require 'org-macs)
 (require 'python)
 
-(declare-function py-shell "ext:python-mode" (&rest args))
-(declare-function py-choose-shell "ext:python-mode" (&optional shell))
-(declare-function py-shell-send-string "ext:python-mode" (strg &optional process))
-
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("python" . "py"))
 
@@ -52,16 +48,6 @@ (defcustom org-babel-python-command "python"
   :group 'org-babel
   :type 'string)
 
-;; FIXME: Remove third-party `python-mode' package support in the next release.
-(defcustom org-babel-python-mode
-  (if (featurep 'python-mode) 'python-mode 'python)
-  "Preferred python mode for use in running python interactively.
-This will typically be either `python' or `python-mode'."
-  :group 'org-babel
-  :version "24.4"
-  :package-version '(Org . "8.0")
-  :type 'symbol)
-
 (defcustom org-babel-python-hline-to "None"
   "Replace hlines in incoming tables with this when translating to python."
   :group 'org-babel
@@ -183,7 +169,6 @@ (defun org-babel-python-without-earmuffs (session)
 	(substring name 1 (- (length name) 1))
       name)))
 
-(defvar py-which-bufname)
 (defvar python-shell-buffer-name)
 (defvar-local org-babel-python--initialized nil
   "Flag used to mark that python session has been initialized.")
@@ -197,47 +182,25 @@ (defun org-babel-python-initiate-session-by-key (&optional session)
 	   (cmd (if (member system-type '(cygwin windows-nt ms-dos))
 		    (concat org-babel-python-command " -i")
 		  org-babel-python-command)))
-      (cond
-       ((eq 'python org-babel-python-mode) ; python.el
-	(unless py-buffer
-	  (setq py-buffer (org-babel-python-with-earmuffs session)))
-	(let ((python-shell-buffer-name
-	       (org-babel-python-without-earmuffs py-buffer)))
-	  (run-python cmd)
-          (with-current-buffer py-buffer
-            (add-hook
-             'python-shell-first-prompt-hook
-             (lambda ()
-               (setq-local org-babel-python--initialized t)
-               (message "I am running!!!"))
-             nil 'local))))
-       ((and (eq 'python-mode org-babel-python-mode)
-	     (fboundp 'py-shell)) ; python-mode.el
-	(require 'python-mode)
-	;; Make sure that py-which-bufname is initialized, as otherwise
-	;; it will be overwritten the first time a Python buffer is
-	;; created.
-	(py-choose-shell)
-	;; `py-shell' creates a buffer whose name is the value of
-	;; `py-which-bufname' with '*'s at the beginning and end
-	(let* ((bufname (if (and py-buffer (buffer-live-p py-buffer))
-			    (replace-regexp-in-string ;; zap surrounding *
-			     "^\\*\\([^*]+\\)\\*$" "\\1" py-buffer)
-			  (concat "Python-" (symbol-name session))))
-	       (py-which-bufname bufname))
-	  (setq py-buffer (org-babel-python-with-earmuffs bufname))
-	  (py-shell nil nil t org-babel-python-command py-buffer nil nil t nil)))
-       (t
-	(error "No function available for running an inferior Python")))
+      (unless py-buffer
+	(setq py-buffer (org-babel-python-with-earmuffs session)))
+      (let ((python-shell-buffer-name
+	     (org-babel-python-without-earmuffs py-buffer)))
+	(run-python cmd)
+        (with-current-buffer py-buffer
+          (add-hook
+           'python-shell-first-prompt-hook
+           (lambda ()
+             (setq-local org-babel-python--initialized t)
+             (message "I am running!!!"))
+           nil 'local)))
       ;; Wait until Python initializes.
-      (if (eq 'python org-babel-python-mode) ; python.el
-          ;; This is more reliable compared to
-          ;; `org-babel-comint-wait-for-output' as python may emit
-          ;; multiple prompts during initialization.
-          (with-current-buffer py-buffer
-            (while (not org-babel-python--initialized)
-              (org-babel-comint-wait-for-output py-buffer)))
-        (org-babel-comint-wait-for-output py-buffer))
+      ;; This is more reliable compared to
+      ;; `org-babel-comint-wait-for-output' as python may emit
+      ;; multiple prompts during initialization.
+      (with-current-buffer py-buffer
+        (while (not org-babel-python--initialized)
+          (org-babel-comint-wait-for-output py-buffer)))
       (setq org-babel-python-buffers
 	    (cons (cons session py-buffer)
 		  (assq-delete-all session org-babel-python-buffers)))
@@ -352,7 +315,7 @@ (defun org-babel-python-evaluate-external-process
       raw
       (org-babel-python-table-or-string (org-trim raw)))))
 
-(defun org-babel-python--send-string (session body)
+(defun org-babel-python-send-string (session body)
   "Pass BODY to the Python process in SESSION.
 Return output."
   (with-current-buffer session
@@ -370,12 +333,9 @@ (defun org-babel-python--send-string (session body)
     print('%s')"
 			 (org-babel-python--shift-right body 4)
 			 org-babel-python-eoe-indicator)))
-      (if (not (eq 'python-mode org-babel-python-mode))
-	  (let ((python-shell-buffer-name
-		 (org-babel-python-without-earmuffs session)))
-	    (python-shell-send-string body))
-	(require 'python-mode)
-	(py-shell-send-string body (get-buffer-process session)))
+      (let ((python-shell-buffer-name
+	     (org-babel-python-without-earmuffs session)))
+	(python-shell-send-string body))
       ;; same as `python-shell-comint-end-of-output-p' in emacs-25.1+
       (while (not (string-match
 		   org-babel-python-eoe-indicator
@@ -398,12 +358,12 @@ (defun org-babel-python-evaluate-session
 	       (let ((body (format org-babel-python--exec-tmpfile
 				   (org-babel-process-file-name
 				    tmp-src-file 'noquote))))
-		 (org-babel-python--send-string session body)))
+		 (org-babel-python-send-string session body)))
               (`value
                (let* ((tmp-results-file (org-babel-temp-file "python-"))
 		      (body (org-babel-python-format-session-value
 			     tmp-src-file tmp-results-file result-params)))
-		 (org-babel-python--send-string session body)
+		 (org-babel-python-send-string session body)
 		 (sleep-for 0 10)
 		 (org-babel-eval-read-file tmp-results-file)))))))
     (org-babel-result-cond result-params
-- 
2.39.1


  parent reply	other threads:[~2023-01-22 22:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01  3:11 [BUG] ob-python: async session evaluation does not support python-mode.el [9.6-pre (release_9.5.5-2661-g2d040b.dirty @ /home/yantar92/.emacs.d/straight/build/org/)] Ihor Radchenko
2022-11-02  4:26 ` Jack Kamm
2022-11-03  7:08   ` [DISCUSSION] Should we deprecate python-mode.el (alternative to built-in python.el) support in ob-python? (was: [BUG] ob-python: async session evaluation does not support python-mode.el [9.6-pre (release_9.5.5-2661-g2d040b.dirty @ /home/yantar92/.emacs.d/straight/build/org/)]) Ihor Radchenko
2022-11-03 17:20     ` Jack Kamm
2022-11-26  6:32       ` [DISCUSSION] Should we deprecate python-mode.el (alternative to built-in python.el) support in ob-python? Bastien
2022-11-26 10:03         ` Ihor Radchenko
2022-11-26 10:32           ` Bastien
2022-11-26  2:29     ` [DISCUSSION] Should we deprecate python-mode.el (alternative to built-in python.el) support in ob-python? (was: [BUG] ob-python: async session evaluation does not support python-mode.el [9.6-pre (release_9.5.5-2661-g2d040b.dirty @ /home/yantar92/.emacs.d/straight/build/org/)]) Ihor Radchenko
2022-11-26  5:55       ` [DISCUSSION] Should we deprecate python-mode.el (alternative to built-in python.el) support in ob-python? Bastien Guerry
2022-12-29 13:41         ` Ihor Radchenko
2022-12-29 14:21           ` Bastien
2023-01-22 22:21           ` Jack Kamm [this message]
2023-01-23 11:22             ` Ihor Radchenko
2023-01-27 23:13               ` Jack Kamm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cxe2ot2.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).