emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Jack Kamm <jackkamm@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Change default ob-python session command to match run-python
Date: Sat, 30 Dec 2023 15:47:34 +0000	[thread overview]
Message-ID: <87frzj8zft.fsf@localhost> (raw)
In-Reply-To: <87edf41yeb.fsf@gmail.com>

Jack Kamm <jackkamm@gmail.com> writes:

> The attached patch changes the default behavior of ob-python sessions,
> to respect python-shell-interpreter(-args) when starting an interactive
> session.

Thanks!
I have several comments.

> -(defcustom org-babel-python-command "python"
> -  "Name of the command for executing Python code."
> -  :version "24.4"
> -  :package-version '(Org . "8.0")
> +(defcustom org-babel-python-command nil
> +  "Name of the command for interactive and non-interactive Python code.
> +If set, it overrides `org-babel-python-command-session' and
> +`org-babel-python-command-nonsession'."

What about default value being 'auto? That would be more explicit.

> +  :version "29.2"

:version tags should not be used when we use :package-version - we drop
them as we change the defcustom that still has them.
See 15.1 Common Item Keywords section of Elisp manual:

    ‘:package-version '(PACKAGE . VERSION)’
         This keyword specifies that the item was first introduced in
         PACKAGE version VERSION, or that its meaning or default value was
         changed in that version.  This keyword takes priority over
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ‘:version’
         ^^^^^^^^^^

> +(defcustom org-babel-python-command-session nil
> +  "Name of the command for starting interactive Python sessions.
> +If `nil' (the default), uses the values from
> +`python-shell-interpreter' and `python-shell-interpreter-args'.
> +If `org-babel-python-command' is set, then it overrides this
> +option."
> ...
> +(defcustom org-babel-python-command-nonsession "python"
> +  "Name of the command for executing non-interactive Python code.
> +If `org-babel-python-command' is set, then it overrides this option."

Unless I miss something, it looks like you also allow command arguments,
not just command name as the value. You may need to adjust the docstring
to reflect this fact.

>  (defun org-babel-execute:python (body params)
>    "Execute Python BODY according to PARAMS.
>  This function is called by `org-babel-execute-src-block'."
> -  (let* ((org-babel-python-command
> +  (let* ((org-babel-python-command-nonsession
> +	  (or (cdr (assq :python params))
> +	      org-babel-python-command
> +              org-babel-python-command-nonsession))
> +         (org-babel-python-command-session
>  	  (or (cdr (assq :python params))
> -	      org-babel-python-command))
> +	      org-babel-python-command
> +              org-babel-python-command-session))

> @@ -374,7 +407,7 @@ (defun org-babel-python-evaluate-external-process
>  non-nil, then save graphical results to that file instead."
>    (let ((raw
>           (pcase result-type
> -           (`output (org-babel-eval org-babel-python-command
> +           (`output (org-babel-eval org-babel-python-command-nonsession
>

I am slightly concerned about
`org-babel-python-evaluate-external-process' relying upon being called
from `org-babel-execute:python' that let-binds
`org-babel-python-nonsession'.

Since `org-babel-python-evaluate-external-process' is a public function,
it may also be called independently. And it will not obey
`org-babel-python-command' then.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2023-12-30 15:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29 21:39 [PATCH] Change default ob-python session command to match run-python Jack Kamm
2023-12-30 15:47 ` Ihor Radchenko [this message]
2023-12-31  5:45   ` Jack Kamm
2023-12-31 12:18     ` Ihor Radchenko

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=87frzj8zft.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=jackkamm@gmail.com \
    /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).