This commit is contained in:
John Miller 2015-08-26 16:24:36 -05:00
commit 23e01cb3d7
5 changed files with 50 additions and 30 deletions

View file

@ -26,6 +26,17 @@ Jupyter.
.. _3.x: http://ipython.org/ipython-doc/3/index.html
.. _Jupyter: http://jupyter.org
Check out ob-ipython_!
======================
EIN unfortunately has limited integration_ with org-mode, but if you
are looking to use the IPython kernel with your org files you should
check out ob-ipython_ (available on MELPA).
.. _integration: http://millejoh.github.io/emacs-ipython-notebook/#org-mode-integration
.. _ob_ipython: https://github.com/gregsexton/ob-ipython/
Screenshot
==========

View file

@ -48,11 +48,11 @@ TEXT is a string and PROMPT-NUMBER is an integer."
"Create a plist representing JSON data for code-type cell.
To make OUTPUTS data, use `ein:testing-codecell-pyout-data'."
(list :cell_type "code"
:input (or input "")
:source (or input "")
:language "python"
:outputs outputs
:collapsed json-false
:prompt_number prompt-number))
:metadata (list :collapsed json-false :autoscroll json-false)
:execution_count prompt-number))
(defun ein:testing-textcell-data (&optional source cell-type)
(list :cell_type cell-type

View file

@ -31,40 +31,45 @@
(require 'ein-notebook)
(require 'ein-testing-cell)
(defun ein:testing-notebook-from-json (json-string &optional notebook-name path)
(defun ein:testing-notebook-from-json (json-string &optional name path)
(let* ((data (ein:json-read-from-string json-string))
(notebook-name (plist-get data :name))
(name (plist-get data :name))
(path (plist-get data :path))
(content (make-ein:$content :url-or-port "DUMMY-URL"
:ipython-version 2
:ipython-version 3
:path path)))
(unless notebook-name (setq notebook-name "NOTEBOOK-DUMMY"))
(unless path (setq path ""))
(unless name (setq name "NOTEBOOK-DUMMY"))
(unless path (setq path "NOTEBOOK-DUMMY"))
;; cl-flet does not work correctly here!
(cl-flet ((pop-to-buffer (buf)
(flet ((pop-to-buffer (buf)
buf)
(ein:query-ipython-version (&optional url-or-port force)
3)
(ein:notebook-start-kernel (notebook)
notebook))
(let ((notebook (ein:notebook-new "DUMMY-URL" (ein:query-ipython-version) notebook-name path)))
(let ((notebook (ein:notebook-new "DUMMY-URL" path)))
(setf (ein:$notebook-kernel notebook)
(ein:kernel-new 8888 "/kernels" (ein:$notebook-events notebook) (ein:query-ipython-version)))
(setf (ein:$kernel-events (ein:$notebook-kernel notebook))
(ein:events-new))
(ein:notebook-request-open-callback notebook (ein:new-content content data nil))
(ein:notebook-request-open-callback notebook (ein:new-content content nil :data data))
(ein:notebook-buffer notebook)))))
(defun ein:testing-notebook-make-data (cells &optional name path)
(setq cells
(ein:testing-notebook--preprocess-cells-data-for-json-encode cells))
(unless name (setq name "Dummy Name.ipynb"))
(unless path (setq path ""))
`((name . ,name)
(path . ,path)
(unless path (setq path "Dummy Name.ipynb"))
`((path . ,path)
(name . ,name)
(type . "notebook")
(format . "json")
(mimetype . nil)
(writeable . t)
(content (metadata . ())
(nbformat . 3)
(nbformat . 4)
(nbformat_minor . 0)
(worksheets . [((cells . ,(apply #'vector cells)))]))))
(cells . ,(apply #'vector cells)))))
(defun ein:testing-notebook--preprocess-cells-data-for-json-encode (cells)
"Preprocess CELLS data to make it work nice with `json-encode'."

View file

@ -41,8 +41,9 @@
(ein:testing-with-one-cell
(ein:cell-from-json
(list :cell_type "code"
:input "some input"
:prompt_number 111)
:source "some input"
:metadata (list :collapsed json-false :autoscroll json-false)
:execution_count 111)
:ewoc (oref ein:%worksheet% :ewoc))
(goto-char (ein:cell-location cell))
(should (looking-at "\
@ -54,8 +55,9 @@ some input
(ein:testing-with-one-cell
(ein:cell-from-json
(list :cell_type "code"
:input "some input"
:prompt_number "*")
:source "some input"
:metadata (list :collapsed json-false :autoscroll json-false)
:execution_count "*")
:ewoc (oref ein:%worksheet% :ewoc))
(goto-char (ein:cell-location cell))
(should (looking-at "\
@ -67,7 +69,8 @@ some input
(ein:testing-with-one-cell
(ein:cell-from-json
(list :cell_type "code"
:input "some input")
:metadata (list :collapsed json-false :autoscroll json-false)
:source "some input")
:ewoc (oref ein:%worksheet% :ewoc))
(goto-char (ein:cell-location cell))
(should (looking-at "\
@ -85,8 +88,9 @@ some input
(ein:cell-from-json
(list :cell_type "code"
:outputs outputs
:input "some input"
:prompt_number 111)
:source "some input"
:metadata (list :collapsed json-false :autoscroll json-false)
:execution_count 111)
:ewoc (oref ein:%worksheet% :ewoc))
(goto-char (ein:cell-location cell))
(should (looking-at (format "\
@ -105,7 +109,7 @@ some input
(loop for i from 1
for x in outputs
collect
(append x (list :output_type "pyout" :prompt_number i))))
(append x (list :output_type "execute_result" :execution_count i))))
(outputs-display-data
(mapcar (lambda (x) (append '(:output_type "display_data") x))
outputs))

View file

@ -21,7 +21,7 @@
(let* ((input-prompt-number 111)
(output-prompt-number 222)
(input (ein:join-str "\n" '("first input" "second input")))
(output-0 (list :output_type "pyout"
(output-0 (list :output_type "execute_result"
:prompt_number output-prompt-number
:text (list "first output"
"second output")))
@ -82,7 +82,7 @@
(let* ((input-prompt-number 111)
(output-prompt-number 222)
(input (ein:join-str "\n" '("first input" "second input")))
(output-0 (list :output_type "pyout"
(output-0 (list :output_type "execute_result"
:prompt_number output-prompt-number
:text (list "first output"
"second output")))
@ -100,7 +100,7 @@
(let* ((input-prompt-number 111)
(output-prompt-number 222)
(input (ein:join-str "\n" '("first input" "second input")))
(output-0 (list :output_type "pyout"
(output-0 (list :output_type "execute_result"
:prompt_number output-prompt-number
:text (list "first output"
"second output")))
@ -162,7 +162,7 @@
(let* ((input-prompt-number 111)
(output-prompt-number 222)
(input (ein:join-str "\n" '("first input" "second input")))
(output-0 (list :output_type "pyout"
(output-0 (list :output_type "execute_result"
:prompt_number output-prompt-number
:text (list "first output"
"second output")))
@ -189,7 +189,7 @@
(let* ((input-prompt-number 111)
(output-prompt-number 222)
(input (ein:join-str "\n" '("first input" "second input")))
(output-0 (list :output_type "pyout"
(output-0 (list :output_type "execute_result"
:prompt_number output-prompt-number
:text (list "first output"
"second output")))
@ -210,7 +210,7 @@
for cell-p = (intern (format "ein:%scell-p" cell-type))
do
(let* ((input (ein:join-str "\n" '("first input" "second input")))
(data (list :cell_type cell-type :source input))
(data (list :cell_type cell-type :source input :metadata nil))
(dummy-ewoc (ewoc-create 'dummy))
(old (eintest:cell-from-json data :ewoc dummy-ewoc))
(new (ein:cell-copy old)))