From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:5f26::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id CEPUJtg8j2USugAAkFu2QA (envelope-from ) for ; Fri, 29 Dec 2023 22:40:40 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 0MEbINg8j2WrRAAAqHPOHw (envelope-from ) for ; Fri, 29 Dec 2023 22:40:40 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TgyBhQpD; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1703886040; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=z0tglZPKdAJgTptVNjqAUhPhiCrDCNpOULnPPTT9fl8=; b=JtASVOQrkH/jk9MjCRYmbl5DChBXabJ+Pgl7AKLTLfavKv1ruHcgJNzgeZINiMuk4rc9Y9 NVzIvd7u6GyH9aSfPelAMbtxSkY5qYrZbj7XrAJeQbupOm44AJbNRvLw3rCAaOj7ADtiD0 vIo1kuSsaAgNP58DpbJ2eoAsYAacq5iJQgR895gAt/n+X9jIiupefbVMQlXD3yV22U0LS2 d9AFW5vf1st+h3+pf0f9d0KdUFzDmH3ntvET6ajoNfG1/oNjqAWydm1nasQ+67UdpYpdvd hKvRXa8bKX7zdqBz3kvmcjjn/ABMnxjbJf1p7nGX0YVg+dlFePc0SIxb1jFfYA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1703886040; a=rsa-sha256; cv=none; b=hfTGY5sWYsrofIKDoyHZD4DOUX2caFBTFkaESMWlepPxzM7ghMtsRZ5sJ1O6ColFShDsvW jGaO9XgL3Y3Ho1antuQDlVqeb7JdTM/RaX9jC2xuBQCJbS2O9HA1+wRB08IPuaefLhT3JG 6ItTthvjjX+qvYhquk+oGn8cOwpiWgRd9I0h+dV1azCVJjyoUHrLoksIf+XzWuzjyTyxym UYMkJ+lMflhXRjnvw5lX+u8UKo71fMzKYePbhosR/SPL4E4gGuLhMIEBmjR/uMT4BwK17v xzXxr/fdcXYw3fjRhMzrSXdKwgX6Bb4hGD4R+xyQy9tp8J97YL+bmY17CY0mXw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TgyBhQpD; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ED1E857C92 for ; Fri, 29 Dec 2023 22:40:39 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJKa6-0003u2-Cd; Fri, 29 Dec 2023 16:39:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJKa3-0003tf-Gn for emacs-orgmode@gnu.org; Fri, 29 Dec 2023 16:39:47 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJKa1-0004iq-17 for emacs-orgmode@gnu.org; Fri, 29 Dec 2023 16:39:47 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d4a980fdedso35475ad.1 for ; Fri, 29 Dec 2023 13:39:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703885983; x=1704490783; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=z0tglZPKdAJgTptVNjqAUhPhiCrDCNpOULnPPTT9fl8=; b=TgyBhQpDasDmVtiJciTjEnTNMkr7BitI71/UcS/MRGZXYbhkHQiWBdQ9obNzB7fnfG fTauEIVgvgz7FbaqZZwZC0asNAt0CPd316Iq1rI0eCOUCi3A8iTqSHZ3rSAQGPIW31RV UQaw5f5uLE+cHkBkCGaiChTeBMg9ZJPHvxb0DyUDWAEIUrbQOf5+gAjBPT5oDg0ekVhZ lk0wd1E127OPfAlY5M+xLAc6/xUk0UegyaKqNdwE9RdBmOdLs6T6p1emjQT81S90NbX2 4bBKFkQtPKDqU6ewOnX5IHJmeZaWcBjx2+kEI7MRX42dNZXN4vdUGcfOkfg+SargO5L+ CK/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703885983; x=1704490783; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=z0tglZPKdAJgTptVNjqAUhPhiCrDCNpOULnPPTT9fl8=; b=EJ2tmHTOfEyWO/918u626kFa1bzPMBScE7AIIwL4wWKLyveSJtkTMeUjW8AUjqjxtn POLSlnO28l/0h+ToyMdKFt6uPLoz7/zMUpCCqFOB7EUoYxIw+kTic9XHr3OkUjEqC+Mz s5eu1HI6Cr8cLgFU88d2y464TpCUKXGzPHNYCQV3YctZhnE0q6PSXJcoYSoJiUJrcTQE /u6Rjrpugfa2NNmGz7KGcrru4DVKb5vYa/ANbH3yBD2A0NUTI1qUN5ET+L1ToEK/TGSu iYQYtUjOx4HGuNcygrHW5LHA7MBBAMwWUEyo+W5zUHo2okailbnkhyyHKyV8iNQyQNbe y8uQ== X-Gm-Message-State: AOJu0YxJMALUEmGw+1v0HkhJ2ZNS/paYQXvd8R9kkj5fhNbh7Iczjmki PELXcZkLdLXvfcjldRZM/KtJWw+FEV8= X-Google-Smtp-Source: AGHT+IGm+1F7B8Rx5JdgJKYZONvO/MyipvbQStQHnpV0L/BnqayW3rxt+yNmvfyGJa0EOTPl7PySvQ== X-Received: by 2002:a17:902:ea85:b0:1d0:b5a8:f6f4 with SMTP id x5-20020a170902ea8500b001d0b5a8f6f4mr13751710plb.23.1703885982674; Fri, 29 Dec 2023 13:39:42 -0800 (PST) Received: from localhost (157-131-78-143.fiber.dynamic.sonic.net. [157.131.78.143]) by smtp.gmail.com with ESMTPSA id f1-20020a170902860100b001d3f5cfa741sm16002647plo.283.2023.12.29.13.39.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 13:39:41 -0800 (PST) From: Jack Kamm To: emacs-orgmode@gnu.org Subject: [PATCH] Change default ob-python session command to match run-python Date: Fri, 29 Dec 2023 13:39:40 -0800 Message-ID: <87edf41yeb.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=jackkamm@gmail.com; helo=mail-pl1-x62e.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.57 X-Spam-Score: -9.57 X-Migadu-Queue-Id: ED1E857C92 X-Migadu-Scanner: mx11.migadu.com X-TUID: GrmXy3zGz1YN --=-=-= Content-Type: text/plain The attached patch changes the default behavior of ob-python sessions, to respect python-shell-interpreter(-args) when starting an interactive session. It also allows separate customization of the default Python command for nonsessions and sessions. This mainly benefits IPython users. IPython isn't suitable as the default command for nonsessions, but until now there isn't a way to set it as the default interpreter for sessions only. Another benefit is to promote greater consistency between ob-python.el and upstream python.el, in particular for shells started with run-python. If a user configures python-shell-interpreter(-args), then ob-python will respect those settings now. As explained in the NEWS entry, this change should have no effect on users who previously configured `org-babel-python-command', or on users who stick to the default `python-shell-interpreter'. But I submit the patch for review before applying it, because it involves changing the default values of some custom variables. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-python-Changed-options-for-default-Python-command.patch >From a49ddcb6ef72cfefab400e36e6d4a19e869c47a1 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Fri, 29 Dec 2023 13:22:18 -0800 Subject: [PATCH] ob-python: Changed options for default Python command ob-python will now use the same settings as `run-python' when starting interactive sessions, by default. * lisp/ob-python.el (org-babel-python-command): Changed to have default value of nil. (org-babel-python-command-session): New option to control default session Python command. (org-babel-python-command-nonsession): New option to control default nonsession Python command. (org-babel-execute:python): Set `org-babel-python-command-session' and `org-babel-python-command-nonsession' using :python header arg. (org-babel-python-initiate-session-by-key): Call `run-python' without CMD arg. Instead, set `python-shell-interpreter' and `python-shell-interpreter-args' when needed. (org-babel-python-evaluate-external-process): Use `org-babel-python-command-nonsession' to start nonsession Python. --- etc/ORG-NEWS | 30 ++++++++++++++++++++++++ lisp/ob-python.el | 58 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 75 insertions(+), 13 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index c54473f55..688735a5b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -551,6 +551,36 @@ Currently implemented options are: The capture template expansion element =%K= creates links using ~org-store-link~, which respects the values of ~org-id-link-to-use-id~. +*** Changes to ~org-babel-python-command~, and new session/nonsession specific options + +The default Python command used by interactive sessions has been +changed to match ~python-shell-interpreter~ and +~python-shell-interpreter-args~ by default. The default Python +command for nonsessions has not changed. + +New options ~org-babel-python-command-nonsession~ and +~org-babel-python-command-session~ control the default Python command +for nonsessions and sessions, respectively. By default, +~org-babel-python-command-session~ is nil, which means to use the +configuration for ~python-shell-interpreter(-args)~ as default. + +The old option ~org-babel-python-command~ has been changed to have +default value of nil. When non-nil, it overrides both +~org-babel-python-command-nonsession~ and +~org-babel-python-command-session~. Therefore, users who had +previously set ~org-babel-python-command~ will not experience any +changes. + +Likewise, users who had neither set ~org-babel-python-command~ nor +~python-shell-interpreter(-args)~ will not see any changes -- ~python~ +remains the default command. + +The main change will be for users who did not configure +~org-babel-python-command~, but did configure +~python-shell-interpreter~, e.g. to use IPython. In this case, +~ob-python~ will now start interactive sessions in a more consistent +manner with ~run-python~. + ** New features *** =ob-plantuml.el=: Support tikz file format output diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 6b3a608c8..2b17f41fe 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -46,10 +46,31 @@ (defconst org-babel-header-args:python (python . :any)) "Python-specific header arguments.") -(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'." + :version "29.2" + :package-version '(Org . "9.7") + :group 'org-babel + :type '(choice string (const nil))) + +(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." + :version "29.2" + :package-version '(Org . "9.7") + :group 'org-babel + :type '(choice string (const nil))) + +(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." + :version "29.2" + :package-version '(Org . "9.7") :group 'org-babel :type 'string) @@ -70,9 +91,14 @@ (defcustom org-babel-python-None-to 'hline (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)) (session (org-babel-python-initiate-session (cdr (assq :session params)))) (graphics-file (and (member "graphics" (assq :result-params params)) @@ -267,13 +293,20 @@ (defun org-babel-python-initiate-session-by-key (&optional session) (let* ((session (if session (intern session) :default)) (py-buffer (or (org-babel-python-session-buffer session) (org-babel-python-with-earmuffs session))) - (cmd (if (member system-type '(cygwin windows-nt ms-dos)) - (concat org-babel-python-command " -i") - org-babel-python-command)) (python-shell-buffer-name (org-babel-python-without-earmuffs py-buffer)) (existing-session-p (comint-check-proc py-buffer))) - (run-python cmd) + (if org-babel-python-command-session + (let* ((cmd-split (split-string-and-unquote + org-babel-python-command-session)) + (python-shell-interpreter (car cmd-split)) + (python-shell-interpreter-args + (append (cdr cmd-split) + (when (member system-type + '(cygwin windows-nt ms-dos)) + (list "-i"))))) + (run-python)) + (run-python)) (with-current-buffer py-buffer (if existing-session-p ;; Session was created outside Org. Assume first prompt @@ -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 (concat preamble (and preamble "\n") (if graphics-file (format org-babel-python--output-graphics-wrapper @@ -382,8 +415,7 @@ (defun org-babel-python-evaluate-external-process body)))) (`value (let ((results-file (or graphics-file (org-babel-temp-file "python-")))) - (org-babel-eval - org-babel-python-command + (org-babel-eval org-babel-python-command-nonsession (concat preamble (and preamble "\n") (format -- 2.43.0 --=-=-=--