From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 0K+nHj4AkWWA3gAAkFu2QA (envelope-from ) for ; Sun, 31 Dec 2023 06:46:38 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id yJ7VGD4AkWVRWQAAe85BDQ (envelope-from ) for ; Sun, 31 Dec 2023 06:46:38 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DcALCkDy; 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=1704001597; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=292XBua67RoCPYp1uTxQNN2NW5oCl87nT7Ugn3JzUo4=; b=ucOIuk1rz77dAiOvCZ39aoDMruGdM9pE7bAWww+rfDvuQeaE2/vHSduJC77gHfxvBEt6zE g3jOxLfb8HDPjfMdL5OMMWdLs2dy9aMvqywjY39QXehhEjng93U2RdHYl40HbRqwEHWrZ8 EFdDw43Io11H/hMheflOcCAqbneT6iMrMpm1EKfbCPXD29+d1zoP/WTFQCr5twDplRrQk+ qniB/Ty4swSmxqnk3O0oUEXbJQZ6jocedjPpzQ4Y8PuL3D8stum3T1vCo4k4QuSFFD7wdH 1+Jo2B69ixEgE44notOKyPC0mkJ+EPzN+9IIQDAWwoAUeqgzZvuDD0ADJH7cEg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DcALCkDy; 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-Seal: i=1; s=key1; d=yhetil.org; t=1704001597; a=rsa-sha256; cv=none; b=a9rSyX0oLg0uc3K23Dze1/123Zv/C4zxqay8+VsPL/jjZ38SOXQAbQaLOTbavVXQ7Ku9TB V0yiqUtCX7y4TNjCBdzVTuJKr4J3B1uMcjieq6cFRNLVCJTxXEiQWZoM2SzvqgCuXtW8PL rzpNOWDJEpJGYK8Mwib/RKdmm4SKW2s8MTweVbabxBsOyXT9TPJYeoYUH20KV9JLcuwsge y8MWsEhBhvh9k7d/O6PnhktgnPGygIzwlkQ5Rat5XzCSEP6L8EvTQ3pMOKjFSe+vzx3lrQ Q9K+X6bLmd2un71dRnATh5MyEI7ZsOvViDr+7o4HzwuoM3DI7LM9kBjSiavySA== 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 6824D60314 for ; Sun, 31 Dec 2023 06:46:36 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJodw-0006dL-Nv; Sun, 31 Dec 2023 00:45:48 -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 1rJodu-0006dC-RD for emacs-orgmode@gnu.org; Sun, 31 Dec 2023 00:45:46 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJods-000317-O9 for emacs-orgmode@gnu.org; Sun, 31 Dec 2023 00:45:46 -0500 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-28bd623c631so6605345a91.3 for ; Sat, 30 Dec 2023 21:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704001543; x=1704606343; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=292XBua67RoCPYp1uTxQNN2NW5oCl87nT7Ugn3JzUo4=; b=DcALCkDy9QNvqRvHp1h3Frq4Os0OoEfseQT/uvw+Q/izo3gLxd2kJSa2zKK3us/ytM 4dPExjCf6/3j3PCOw7WlDWS34FlbXGeQ8S6mHGnIoSu0qYuF+vwTOMeeEKaCdzxsX64I jwK7hs86uCzbta1Bi7lqjm2GsmqU+zibsp0CHAEKzLv01PqH2s0JsafCtkeWY4BOPTi9 TEfm+Df2VHlMVcEFPcEDxyssO/9xeyZ/HNaiueV7Xlt89fETYmUtOyCQSdyzBe0tNhUT hZe4DvSQ9CvKOeTy02FwR8IRPnZWeioUaZ8GgsTN7h6v6/NOEAFtoQKpcqSuadpYDIVP DAxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704001543; x=1704606343; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=292XBua67RoCPYp1uTxQNN2NW5oCl87nT7Ugn3JzUo4=; b=FMo8+yOqFK8Kvbf9z3l4sXByBe6zDmG60QgKsOTqVUE8LjG1ET6WQ5KMbuWyjebEaF m9tLeLu4m8nX/KtT3pEF7Lb5xoA8I6epyG7k/EVopa5N2NcjWlyajgAl8G7uz/Dg8bg6 VEJdxQ9oYD6aCZ8fIT9Jm3Nnyu65WhX0atL5wSdNF25jIiEWIhMgHUwx1FxLCGIIvetN J2JRnbL8FZieRR4dUq9qKoy8GWJFzZmULigGvc4/kZy/1G7GaWD32Et5IBocdA9mGeHm ZM9RTdpIIWCJMz2Kkg19Aovz3xF6yaJYeEP+vgOqGGpnspr15aTNFViQmZQekpcHtcQG AisQ== X-Gm-Message-State: AOJu0YzuziMeDLanxCR00WQH2exeA2irBkMZlwlYuy2Ij61jUKtntsTl ijOaajIJ4jVIyZPtNV6gI70= X-Google-Smtp-Source: AGHT+IEsQVOYqHHkycAQEVQAaMFsPe+doOkr1exLLrTVX+UI+z+yMHgsr6vu/b8krYD3Ur/4EXJucA== X-Received: by 2002:a17:902:7ed0:b0:1d4:7d37:d448 with SMTP id p16-20020a1709027ed000b001d47d37d448mr6008014plb.44.1704001543130; Sat, 30 Dec 2023 21:45:43 -0800 (PST) Received: from localhost (157-131-78-143.fiber.dynamic.sonic.net. [157.131.78.143]) by smtp.gmail.com with ESMTPSA id g10-20020a17090a714a00b0028ad7a2867asm21987193pjs.17.2023.12.30.21.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 21:45:42 -0800 (PST) From: Jack Kamm To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Change default ob-python session command to match run-python In-Reply-To: <87frzj8zft.fsf@localhost> References: <87edf41yeb.fsf@gmail.com> <87frzj8zft.fsf@localhost> Date: Sat, 30 Dec 2023 21:45:41 -0800 Message-ID: <874jfy2ad6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=jackkamm@gmail.com; helo=mail-pj1-x102e.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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -7.45 X-Spam-Score: -7.45 X-Migadu-Queue-Id: 6824D60314 X-TUID: q8LkK01hVYak --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Thanks! > I have several comments. Thanks for the feedback! I attach a followup patch in response. If all looks good, I will squash before applying. >> -(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. Sure, I have updated `org-babel-python-command(-session)' to use auto as default. > :version tags should not be used when we use :package-version - we drop > them as we change the defcustom that still has them. I've dropped the :version tags for the updated variables. I can also make a separate commit later to drop :version from other ob-python variables like `org-babel-python-hline-to' and `org-babel-python-None-to'. > 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. I've updated the docstrings to say they are for the command including arguments. >> (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. That's a good catch. I've fixed this by reverting `org-babel-execute:python' to set `org-babel-python-command' (not `org-babel-python-command-nonsession'). Then, `org-babel-python-evaluate-external-process' checks both variables to decide what the command is. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Incorporate-feedback-from-Ihor-to-be-squashed-before.patch >From 91352d03c897dc546f57f48a14847cc78e74ec85 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sat, 30 Dec 2023 20:44:46 -0800 Subject: [PATCH 2/2] Incorporate feedback from Ihor; to be squashed before applying --- lisp/ob-python.el | 67 ++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 2b17f41fe..5251c3b33 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -46,30 +46,27 @@ (defconst org-babel-header-args:python (python . :any)) "Python-specific header arguments.") -(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" +(defcustom org-babel-python-command 'auto + "Command (including arguments) for interactive and non-interactive Python code. +When not `auto', it overrides `org-babel-python-command-session' +and `org-babel-python-command-nonsession'." :package-version '(Org . "9.7") :group 'org-babel - :type '(choice string (const nil))) + :type '(choice string (const auto))) -(defcustom org-babel-python-command-session nil - "Name of the command for starting interactive Python sessions. -If `nil' (the default), uses the values from +(defcustom org-babel-python-command-session 'auto + "Command (including arguments) for starting interactive Python sessions. +If `auto' (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))) + :type '(choice string (const auto))) (defcustom org-babel-python-command-nonsession "python" - "Name of the command for executing non-interactive Python code. + "Command (including arguments) 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) @@ -91,14 +88,9 @@ (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-nonsession + (let* ((org-babel-python-command (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-session)) + org-babel-python-command)) (session (org-babel-python-initiate-session (cdr (assq :session params)))) (graphics-file (and (member "graphics" (assq :result-params params)) @@ -272,6 +264,20 @@ (defun org-babel-python--python-util-comint-end-of-output-p () (buffer-substring-no-properties (car prompt) (cdr prompt))))) +(defun org-babel-python--command (is-session) + "Helper function to return the Python command. +This checks `org-babel-python-command', and then +`org-babel-python-command-session' (if IS-SESSION) or +`org-babel-python-command-nonsession' (if not IS-SESSION). If +IS-SESSION, this might return `nil', which means to use +`python-shell-calculate-command'." + (or (unless (eq org-babel-python-command 'auto) + org-babel-python-command) + (if is-session + (unless (eq org-babel-python-command-session 'auto) + org-babel-python-command-session) + org-babel-python-command-nonsession))) + (defvar-local org-babel-python--initialized nil "Flag used to mark that python session has been initialized.") (defun org-babel-python--setup-session () @@ -295,16 +301,17 @@ (defun org-babel-python-initiate-session-by-key (&optional session) (org-babel-python-with-earmuffs session))) (python-shell-buffer-name (org-babel-python-without-earmuffs py-buffer)) - (existing-session-p (comint-check-proc py-buffer))) - (if org-babel-python-command-session - (let* ((cmd-split (split-string-and-unquote - org-babel-python-command-session)) + (existing-session-p (comint-check-proc py-buffer)) + (cmd (org-babel-python--command t))) + (if cmd + (let* ((cmd-split (split-string-and-unquote cmd)) (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"))))) + (combine-and-quote-strings + (append (cdr cmd-split) + (when (member system-type + '(cygwin windows-nt ms-dos)) + (list "-i")))))) (run-python)) (run-python)) (with-current-buffer py-buffer @@ -407,7 +414,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-nonsession + (`output (org-babel-eval (org-babel-python--command nil) (concat preamble (and preamble "\n") (if graphics-file (format org-babel-python--output-graphics-wrapper @@ -415,7 +422,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-nonsession + (org-babel-eval (org-babel-python--command nil) (concat preamble (and preamble "\n") (format -- 2.43.0 --=-=-=--