Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@

This is the most basic ipython block. You *must* provide a session
argument. You can name the session if you wish to separate state.
You can also pass an connection json of existing ipython session
as a session name in order to connect to it.

#+BEGIN_SRC org
,#+BEGIN_SRC ipython :session
Expand Down
12 changes: 8 additions & 4 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def msg_router(name, ch):
clients = {}

def create_client(name):
cf = find_connection_file('emacs-' + name)
if name.endswith('.json'):
# Received an existing kernel we should connect to.
cf = find_connection_file(name)
else:
cf = find_connection_file('emacs-' + name)
c = client.BlockingKernelClient(connection_file=cf)
c.load_connection_file()
c.start_channels()
Expand Down Expand Up @@ -117,10 +121,10 @@ def get(self):

def make_app():
return tornado.web.Application([
tornado.web.url(r"/execute/(\w+)", ExecuteHandler),
tornado.web.url(r"/inspect/(\w+)", InspectHandler),
tornado.web.url(r"/execute/([\w\-\.]+)", ExecuteHandler),
tornado.web.url(r"/inspect/([\w\-\.]+)", InspectHandler),
tornado.web.url(r"/debug", DebugHandler),
])
])

def main(args):
parser = argparse.ArgumentParser()
Expand Down
11 changes: 8 additions & 3 deletions ob-ipython.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@
;;; process management

(defun ob-ipython--kernel-repl-cmd (name)
(list "ipython" "console" "--existing" (format "emacs-%s.json" name)))
(let ((conn-json
(if (s-ends-with-p ".json" name)
name
(format "emacs-%s.json" name))))
(list "ipython" "console" "--existing" conn-json)))

(defun ob-ipython--create-process (name cmd)
(apply 'start-process name (format "*ob-ipython-%s*" name) (car cmd) (cdr cmd)))
Expand Down Expand Up @@ -345,8 +349,9 @@ VARS contains resolved variable references"
(error "ob-ipython currently only supports evaluation using a session.
Make sure your src block has a :session param.")
(ob-ipython--create-client-driver)
(ob-ipython--create-kernel-driver (ob-ipython--normalize-session session)
(cdr (assoc :kernel params)))
(when (not (s-ends-with-p ".json" session))
(ob-ipython--create-kernel-driver (ob-ipython--normalize-session session)
(cdr (assoc :kernel params))))
(ob-ipython--create-repl (ob-ipython--normalize-session session))))

(provide 'ob-ipython)
Expand Down