mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 09:01:40 -05:00
Merge pull request #577 from dickmao/bug-issue-576
org export needs to be synchronous
This commit is contained in:
commit
52f304d038
6 changed files with 83 additions and 31 deletions
|
@ -148,3 +148,27 @@ Scenario: portless url with path, image, C-c ' lets you C-c C-c as well
|
|||
And I ctrl-c-ctrl-c
|
||||
And I dump buffer
|
||||
And I wait for buffer to say "file:ein-image"
|
||||
|
||||
@export
|
||||
Scenario: Test ob-exp captures code and results.
|
||||
When I open temp file "ecukes.org"
|
||||
And I call "org-mode"
|
||||
And I type "<s"
|
||||
And I press "TAB"
|
||||
And I type "ein :results scalar :exports both"
|
||||
And I press "C-n"
|
||||
And I type "ratio = (1 + 5 ** 0.5) / 2"
|
||||
And I press "RET"
|
||||
And I type "ratio"
|
||||
And I ctrl-c-ctrl-c
|
||||
And I wait for buffer to say "1.618"
|
||||
And I press "M->"
|
||||
And I press "RET"
|
||||
And I press "RET"
|
||||
And I type "<s"
|
||||
And I press "TAB"
|
||||
And I type "ein :results scalar :exports both"
|
||||
And I press "RET"
|
||||
And I type "ratio"
|
||||
And I dump buffer
|
||||
And I call "org-latex-export-to-latex"
|
||||
|
|
|
@ -45,24 +45,25 @@
|
|||
(defun ein:testing-after-scenario ()
|
||||
(ein:testing-flush-queries)
|
||||
(with-current-buffer (ein:notebooklist-get-buffer (car (ein:jupyter-server-conn-info)))
|
||||
(if ein:%notebooklist%
|
||||
(loop for notebook in (ein:notebook-opened-notebooks)
|
||||
for path = (ein:$notebook-notebook-path notebook)
|
||||
do (ein:notebook-kill-kernel-then-close-command notebook)
|
||||
do (loop repeat 16
|
||||
until (not (ein:notebook-live-p notebook))
|
||||
do (sleep-for 0 1000)
|
||||
finally do (when (ein:notebook-live-p notebook)
|
||||
(ein:display-warning (format "cannot close %s" path))))
|
||||
do (when (or (search "Untitled" path) (search "Renamed" path))
|
||||
(ein:notebooklist-delete-notebook path)
|
||||
(loop repeat 16
|
||||
with fullpath = (concat (file-name-as-directory ein:testing-jupyter-server-root) path)
|
||||
for extant = (file-exists-p fullpath)
|
||||
until (not extant)
|
||||
do (sleep-for 0 1000)
|
||||
finally do (when extant
|
||||
(ein:display-warning (format "cannot del %s" path))))))))
|
||||
(loop for notebook in (ein:notebook-opened-notebooks)
|
||||
for path = (ein:$notebook-notebook-path notebook)
|
||||
do (ein:notebook-kill-kernel-then-close-command notebook)
|
||||
do (loop repeat 16
|
||||
until (not (ein:notebook-live-p notebook))
|
||||
do (sleep-for 0 1000)
|
||||
finally do (when (ein:notebook-live-p notebook)
|
||||
(ein:display-warning (format "cannot close %s" path))))
|
||||
do (when (or (ob-ein-anonymous-p path)
|
||||
(search "Untitled" path)
|
||||
(search "Renamed" path))
|
||||
(ein:notebooklist-delete-notebook path)
|
||||
(loop repeat 16
|
||||
with fullpath = (concat (file-name-as-directory ein:testing-jupyter-server-root) path)
|
||||
for extant = (file-exists-p fullpath)
|
||||
until (not extant)
|
||||
do (sleep-for 0 1000)
|
||||
finally do (when extant
|
||||
(ein:display-warning (format "cannot del %s" path)))))))
|
||||
(ein:aif (ein:notebook-opened-notebooks)
|
||||
(loop for nb in it
|
||||
for path = (ein:$notebook-notebook-path nb)
|
||||
|
|
|
@ -134,9 +134,10 @@
|
|||
(ein:log 'verbose "ein:completions--prepare-oinfo: %s"
|
||||
(plist-get content :traceback)))))
|
||||
(error
|
||||
(ein:log 'verbose "ein:completions--prepare-oinfo: [%s]"
|
||||
(error-message-string err))
|
||||
(let (eval-expression-print-length eval-expression-print-level)
|
||||
(ein:log 'verbose "ein:completions--prepare-oinfo: [%s] %s"
|
||||
(error-message-string err) output))
|
||||
(prin1 output #'external-debugging-output))
|
||||
(setf (gethash obj (ein:$kernel-oinfo-cache kernel)) :json-false))))
|
||||
|
||||
;;; Support for Eldoc
|
||||
|
|
|
@ -221,7 +221,7 @@ the log of the running jupyter server."
|
|||
(list 'shutdown-server url-or-port)
|
||||
(ein:url url-or-port "api/shutdown")
|
||||
:type "POST"
|
||||
:timeout 10 ;; content-query-timeout and query-timeout default nil
|
||||
:timeout 3 ;; content-query-timeout and query-timeout default nil
|
||||
:sync t))
|
||||
|
||||
;;;###autoload
|
||||
|
@ -235,7 +235,7 @@ the log of the running jupyter server."
|
|||
until (zerop (hash-table-count ein:query-running-process-table))
|
||||
do (sleep-for 0 500))
|
||||
(ein:shutdown-server url-or-port)
|
||||
(loop repeat 10
|
||||
(loop repeat 3
|
||||
for proc = (ein:jupyter-server-process)
|
||||
until (not proc)
|
||||
do (sleep-for 0 1000)
|
||||
|
|
|
@ -162,11 +162,6 @@ Called from ewoc pretty printer via `ein:cell-pp'."
|
|||
Create a cell if the buffer has none."
|
||||
(slot-value (ein:shared-output-get-or-create) 'cell))
|
||||
|
||||
(defun ein:shared-output-get-kernel ()
|
||||
(let ((cell (ein:shared-output-get-cell)))
|
||||
(when (slot-boundp cell :kernel)
|
||||
(slot-value cell 'kernel))))
|
||||
|
||||
;;;###autoload
|
||||
(defun ein:shared-output-pop-to-buffer ()
|
||||
"Open shared output buffer."
|
||||
|
|
|
@ -42,6 +42,11 @@
|
|||
(defvar *ob-ein-sentinel* "[....]"
|
||||
"Placeholder string replaced after async cell execution")
|
||||
|
||||
(defcustom ob-ein-timeout-seconds 600
|
||||
"Maximum seconds to wait for block to finish (for synchronous operations)."
|
||||
:type 'integer
|
||||
:group 'ein)
|
||||
|
||||
(defcustom ob-ein-languages
|
||||
'(("ein" . python)
|
||||
("ein-python" . python)
|
||||
|
@ -180,8 +185,33 @@ Based on ob-ipython--configure-kernel."
|
|||
processed-params
|
||||
result-params
|
||||
name))))
|
||||
(ob-ein--initiate-session session kernelspec callback))
|
||||
*ob-ein-sentinel*)
|
||||
(save-excursion
|
||||
(cl-assert (not (stringp (org-babel-goto-named-src-block name))))
|
||||
(org-babel-insert-result *ob-ein-sentinel* result-params))
|
||||
(ob-ein--initiate-session session kernelspec callback)
|
||||
(if (ein:eval-if-bound 'org-current-export-file)
|
||||
(save-excursion
|
||||
(loop with interval = 2000
|
||||
with pending = t
|
||||
repeat (/ (* ob-ein-timeout-seconds 1000) interval)
|
||||
do (progn
|
||||
(org-babel-goto-named-result name)
|
||||
(forward-line 1)
|
||||
(setq pending (re-search-forward
|
||||
(regexp-quote *ob-ein-sentinel*)
|
||||
(org-babel-result-end) t)))
|
||||
until (not pending)
|
||||
do (sleep-for 0 interval)
|
||||
finally return
|
||||
(if pending
|
||||
(progn
|
||||
(ein:log 'error "ob-ein--execute-body: %s timed out" name)
|
||||
"")
|
||||
(ob-ein--process-outputs
|
||||
(ein:oref-safe (ein:shared-output-get-cell) 'outputs)
|
||||
processed-params))))
|
||||
(org-babel-remove-result)
|
||||
*ob-ein-sentinel*)))
|
||||
|
||||
(defsubst ob-ein--execute-async-callback (buffer params result-params name)
|
||||
"Callback of 1-arity (the shared output cell) to update org buffer when
|
||||
|
@ -198,11 +228,11 @@ Based on ob-ipython--configure-kernel."
|
|||
(org-babel-result-cond result-params*
|
||||
raw (org-babel-import-elisp-from-file tmp-file '(16)))))
|
||||
(info (org-babel-get-src-block-info 'light)))
|
||||
(ein:log 'debug "ob-ein--execute-async-callback %s %s" name* result)
|
||||
(ein:log 'debug "ob-ein--execute-async-callback %s \"%s\" %s" name* result buffer*)
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(with-current-buffer buffer*
|
||||
(when (not (stringp (org-babel-goto-named-src-block name*)))
|
||||
(unless (stringp (org-babel-goto-named-src-block name*)) ;; stringp=error
|
||||
(when info ;; kill #+RESULTS: (no-name)
|
||||
(setf (nth 4 info) nil)
|
||||
(org-babel-remove-result info))
|
||||
|
@ -226,6 +256,7 @@ one at a time. Further, we do not order the queued up blocks!"
|
|||
(ob-ein--execute-async-callback buffer params
|
||||
result-params name)))
|
||||
(setf (slot-value cell 'callback) callback))
|
||||
;; still pending previous callback
|
||||
(deferred:nextc (deferred:wait 1200) self)))))
|
||||
(deferred:nextc it
|
||||
(lambda (_x)
|
||||
|
|
Loading…
Add table
Reference in a new issue