From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ken Mankoff Subject: Babel + sh + sessions Date: Sat, 08 Apr 2017 08:38:29 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwpdT-0008Ek-RW for emacs-orgmode@gnu.org; Sat, 08 Apr 2017 08:38:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwpdS-00087j-NI for emacs-orgmode@gnu.org; Sat, 08 Apr 2017 08:38:35 -0400 Received: from mail-qt0-x232.google.com ([2607:f8b0:400d:c0d::232]:35816) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwpdS-00086h-JD for emacs-orgmode@gnu.org; Sat, 08 Apr 2017 08:38:34 -0400 Received: by mail-qt0-x232.google.com with SMTP id n46so3581742qta.2 for ; Sat, 08 Apr 2017 05:38:33 -0700 (PDT) Received: from parma.local ([2601:98a:4001:daec:5041:31cd:58e7:2ee7]) by smtp.gmail.com with ESMTPSA id z4sm4974494qkc.68.2017.04.08.05.38.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Apr 2017 05:38:31 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-org Hi Org-Mode list, I'm having trouble running babel shells with nested applications with sessions. A simple MWE is that this works: #+BEGIN_SRC sh :results verbatim :eval no-export echo "bash" octave disp("Octave") #+END_SRC And if you add ":session BashOctave" to the header, it does not work. Inspecting the "BashOctave" buffer, I see that Babel attempts to determine end-of-execution with =echo 'org_babel_sh_eoe'=, which is an invalid command in Octave. I can fix this with: (setq org-babel-sh-eoe-indicator "disp('org_babel_sh_eoe')") I can also do this with Python and :session, but have to update the eoe indicator to use 'print': (setq org-babel-sh-eoe-indicator "print('org_babel_sh_eoe')") #+BEGIN_SRC sh :results verbatim :eval no-export :session BashPython echo "bash" python str="In Python" print(str) #+END_SRC Check that sessions work: #+BEGIN_SRC sh :results verbatim :eval no-export :session BashPython print(str) #+END_SRC Is this the correct solution? This seems a bit heavy-handed, because now regular shell sessions will not work because the "print()" or "disp()" functions do not exist in bash. Q1: How do I appropriately update "org-babel-sh-eoe-indicator" in this situation? Oddly, if I replace "python" with "IPython", things do not work: (setq org-babel-sh-eoe-indicator "print('org_babel_sh_eoe')") #+BEGIN_SRC sh :results verbatim :eval no-export :session BashIPython echo "bash" ipython --pylab=qt5 --pdb --pprint --nosep --no-confirm-exit --no-banner str="In IPython" print(str) #+END_SRC For me, Org hangs here. I might know why: If I run "ipython --classic" in my terminal, I get a ">>>" prompt. If I run that same command in the emacs shell spawned by the Babel session above, it does not respect the "--classic" option, and the prompt is "In [1]: ". I think this may be the cause. I cannot figure out why ipython behaves differently in a shell in emacs versus a shell in my terminal. The two environments appear identical to me when inspected via "printenv". Q2: Can anyone provide hints or advice so that Python and IPython behave the same? Why am I doing this when Babel has support for Octave, Python, and IPython? My actual use case is GRASS GIS, which I've been using for a while and works fine because it is built on top of bash. But GRASS has a Python interface, so now I'm actually trying to run babel blocks that are IPython nested in GRASS nested in bash. This works (note: no session): #+BEGIN_SRC sh :results verbatim :eval no-export echo "in bash" grass72 echo "in GRASS" ipython --pylab=qt5 --pdb --pprint --nosep --no-confirm-exit --no-banner print("In Python") #+END_SRC The above: + works without sessions + works with sessions and Python (not IPython) if I update eoe as above + Does not work with session + IPython Does anyone have any other suggestions how to get an IPython session with a custom bash environment loaded before (that is all GRASS is - a bash environment). Can I run Babel IPython blocks instead of shell blocks, but have some weird hack like: (setq org-babel-python-command "bash; grass72; ipython)? Thanks for reading this far, and thanks in advance for any advice or hints you might have -k.