Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure babel blocks for each kernel #74

Closed
wants to merge 32 commits into from

Conversation

izahn
Copy link
Contributor

@izahn izahn commented Jun 28, 2016

This is a first pass at addressing some of the goals in #57. Specifically it

  • detects installed kernels
  • adds jupyter-<language> entries to org-src-lang-modes for each detected kernel
  • sets default kernelm results and session values for each detected kernel in org-babel-default-header-args:jupyter-<language>
  • aliases org-babel-execute:jupyter-<language> to org-babel-execute:ipython for each detected kernel

The upshot is that you can now write

#+BEGIN_SRC jupyter-python 
  print("hello from python")
#+END_SRC

#+BEGIN_SRC jupyter-R
  print("hello from R"
#+END_SRC

#+BEGIN_SRC jupyter-julia
  println("hello from julia")
#+END_SRC

instead of

#+BEGIN_SRC ipython :kernel python :results output :session python
  print("hello from python")
#+END_SRC

#+BEGIN_SRC ipython :kernel ir :results output :session r
  print("hello from R"
#+END_SRC

#+BEGIN_SRC ipython :kernel julia-4.0 :results output :session julia
  println("hello from julia")
#+END_SRC

In addition, editing code blocks with C-c ' (or M-x org-edit-special) will now (usually) put you in the correct mode.

This PR is probably not ready to be merged. My emacs-lisp is not good, I basically just tried stuff, got error messages, tried stuff to make the errors go away, and repeated until it worked. I would very much appreciate suggestions for improving this code. My hope is that despite my obvious lack of elisp skills this PR can serve as a starting point for improving multi-kernel support in ob-ipython.

Use cases:
- Start an ipython kernel on a server with lots of ram and cpu
  and connect it to local lightweight machine running emacs.
- Ipython kernel launched by some tool. My team have a tool that
  configures ipython session and configuration can't simply be
  added to profile_default.

I considered passing additional argument, but simply naming session
with connection json is simple solution that works well.

I am running it in my emacs and it works. To test:
1. Start ipython session outside of org mode with:

  import os
  from ipykernel.kernelapp import IPKernelApp

  app = IPKernelApp.instance()
  app.initialize([])
  kernel = app.kernel
  kernel.shell.push({'print_me': 'Running in previously started kernel.'})

  app.start()
2. Get json from previous command and name a session after your json
file. For example: #+BEGIN_SRC ipython :session kernel-8520.json
@jiegec
Copy link

jiegec commented Jun 29, 2016

I would prefer to wrap these in an interactive function and let the user decide whether use it or not.

ob-ipython.el Outdated
(set (intern (format "org-babel-default-header-args:jupyter-%S"
(intern (car (cdr x)))))
`((:session . ,(car (cdr x)))
(:kernel . ,(symbol-name (car x)))
Copy link

@jiegec jiegec Jun 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a variable to store the language? These 'cadr' calls appear many times.

@gregsexton gregsexton self-assigned this Jul 3, 2016
@gregsexton
Copy link
Owner

Thanks so much for the PR. I like the idea! Let me dig in to this and check it out. I've got a backlog of PRs so you'll have to bear with me.

@izahn
Copy link
Contributor Author

izahn commented Jul 16, 2016

I cleaned things up following the feedback from @jiegec. Still probably not ready for prime time in terms of code quality, but closer.

garaud and others added 2 commits July 27, 2016 00:16
Snippet of code to active 'ob-ipython' in org-babel
gregsexton and others added 10 commits July 30, 2016 09:24
Opportunistically interpret output as a table.
When text output is beyond a certain length, the result supplied from
Jupyter can be incomplete. With the IHaskell Jupyter backend, at least,
It turns out this is because the alist can have mulitple 'text/plain
key-value pairs in the alist, where earlier values are strict prefixes
of later onces. Reversing the alist before applying assoc gives us the
final, complete text output.
We support 5.0 and later only.
@haberdashPI
Copy link

Any word on this? I'd really love to make use of this feature. I don't have a lot of know how about org-babel or jupyter but I'm willing to learn if that means this feature will be available. I just don't want to duplicate effort...

Giri and others added 11 commits June 28, 2017 14:13
…e paramter for src block and for exporing image output to file use :async-file file.png

Fix list and temp file handling on error

Better handling on error
Use result parameters from a source block when replacing sentinel
No longer do you have to provide files. With pandoc, tables (for
example) get rendered to org.
@izahn
Copy link
Contributor Author

izahn commented Sep 6, 2017

I rebased on current master in preparation for additional cleanup/documentation etc.

@gregsexton
Copy link
Owner

Finally merged as part of #138.

This is so good. Thanks for working on this.

@gregsexton gregsexton closed this Nov 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants