emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ken Mankoff <mankoff@gmail.com>
To: emacs-org <emacs-orgmode@gnu.org>
Subject: Babel + sh + sessions
Date: Sat, 08 Apr 2017 08:38:29 -0400	[thread overview]
Message-ID: <m2zifrm5ve.fsf@gmail.com> (raw)

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.

                 reply	other threads:[~2017-04-08 12:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=m2zifrm5ve.fsf@gmail.com \
    --to=mankoff@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).