* Babel + sh + sessions
@ 2017-04-08 12:38 Ken Mankoff
0 siblings, 0 replies; only message in thread
From: Ken Mankoff @ 2017-04-08 12:38 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-04-08 12:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-08 12:38 Babel + sh + sessions Ken Mankoff
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).