mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
jupyter-<type>
-> jupyter-send-<type>
where appropriate
This commit is contained in:
parent
07ee759f90
commit
3b3fe9c43f
5 changed files with 71 additions and 71 deletions
|
@ -52,7 +52,7 @@ to prevent a client from calling its execute-reply handler, you
|
|||
would do
|
||||
|
||||
(let ((jupyter-inhibit-handlers '(:execute-reply)))
|
||||
(jupyter-execute-request client ...))
|
||||
(jupyter-send-execute-request client ...))
|
||||
|
||||
If set to t, disable all client handlers.")
|
||||
|
||||
|
@ -681,7 +681,7 @@ interpreted as additional CALLBACKS to add to REQ. So to add
|
|||
multiple callbacks you would do
|
||||
|
||||
(jupyter-add-callback
|
||||
(jupyter-execute-request client :code \"1 + 2\")
|
||||
(jupyter-send-execute-request client :code \"1 + 2\")
|
||||
:status (lambda (msg) ...)
|
||||
:execute-reply (lambda (msg) ...)
|
||||
:execute-result (lambda (msg) ...))"
|
||||
|
@ -906,15 +906,15 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
implementation_version language_info
|
||||
banner help_links)))))
|
||||
|
||||
(cl-defgeneric jupyter-execute-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(silent nil)
|
||||
(store-history t)
|
||||
(user-expressions nil)
|
||||
(allow-stdin
|
||||
(jupyter-channel-alive-p
|
||||
(oref client stdin-channel)))
|
||||
(stop-on-error nil))
|
||||
(cl-defgeneric jupyter-send-execute-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(silent nil)
|
||||
(store-history t)
|
||||
(user-expressions nil)
|
||||
(allow-stdin
|
||||
(jupyter-channel-alive-p
|
||||
(oref client stdin-channel)))
|
||||
(stop-on-error nil))
|
||||
"Send an execute request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -936,10 +936,10 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-inspect-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(pos 0)
|
||||
(detail 0))
|
||||
(cl-defgeneric jupyter-send-inspect-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(pos 0)
|
||||
(detail 0))
|
||||
"Send an inspect request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -956,9 +956,9 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-complete-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(pos 0))
|
||||
(cl-defgeneric jupyter-send-complete-request ((client jupyter-kernel-client)
|
||||
&key code
|
||||
(pos 0))
|
||||
"Send a complete request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -976,17 +976,17 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-history-request ((client jupyter-kernel-client)
|
||||
&key
|
||||
output
|
||||
raw
|
||||
(hist-access-type "tail")
|
||||
session
|
||||
start
|
||||
stop
|
||||
(n 10)
|
||||
pattern
|
||||
unique)
|
||||
(cl-defgeneric jupyter-send-history-request ((client jupyter-kernel-client)
|
||||
&key
|
||||
output
|
||||
raw
|
||||
(hist-access-type "tail")
|
||||
session
|
||||
start
|
||||
stop
|
||||
(n 10)
|
||||
pattern
|
||||
unique)
|
||||
"Send a history request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -1009,8 +1009,8 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-is-complete-request ((client jupyter-kernel-client)
|
||||
&key code)
|
||||
(cl-defgeneric jupyter-send-is-complete-request ((client jupyter-kernel-client)
|
||||
&key code)
|
||||
"Send an is-complete request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -1026,8 +1026,8 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-comm-info-request ((client jupyter-kernel-client)
|
||||
&key target-name)
|
||||
(cl-defgeneric jupyter-send-comm-info-request ((client jupyter-kernel-client)
|
||||
&key target-name)
|
||||
"Send a comm-info request."
|
||||
(declare (indent 1))
|
||||
(let ((channel (oref client shell-channel))
|
||||
|
@ -1042,7 +1042,7 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-kernel-info-request ((client jupyter-kernel-client))
|
||||
(cl-defgeneric jupyter-send-kernel-info-request ((client jupyter-kernel-client))
|
||||
"Send a kernel-info request."
|
||||
(let ((channel (oref client shell-channel))
|
||||
(msg (jupyter-message-kernel-info-request)))
|
||||
|
@ -1060,8 +1060,8 @@ the user. Otherwise `read-from-minibuffer' is used."
|
|||
(declare (indent 1))
|
||||
nil)
|
||||
|
||||
(cl-defgeneric jupyter-shutdown-request ((client jupyter-kernel-client)
|
||||
&key restart)
|
||||
(cl-defgeneric jupyter-send-shutdown-request ((client jupyter-kernel-client)
|
||||
&key restart)
|
||||
"Request a shutdown of CLIENT's kernel.
|
||||
If RESTART is non-nil, request a restart instead of a complete shutdown."
|
||||
(declare (indent 1))
|
||||
|
|
|
@ -383,7 +383,7 @@ Finally, INFO is the kernel info plist obtained from a
|
|||
(setq kernel-info
|
||||
(jupyter-message-content
|
||||
(jupyter-wait-until-received :kernel-info-reply
|
||||
(jupyter-kernel-info-request client)
|
||||
(jupyter-send-kernel-info-request client)
|
||||
;; TODO: Make this timeout configurable? The
|
||||
;; python kernel starts up fast, but the Julia
|
||||
;; kernel not so much.
|
||||
|
|
|
@ -756,7 +756,7 @@ to the previous cell. N defaults to 1."
|
|||
(defun jupyter-repl-goto-cell (req)
|
||||
"Go to the cell beginning position of REQ.
|
||||
REQ should be a `jupyter-request' that corresponds to one of the
|
||||
`jupyter-execute-request's created by a cell in the
|
||||
`jupyter-send-execute-request's created by a cell in the
|
||||
`current-buffer'. Note that the `current-buffer' is assumed to be
|
||||
a Jupyter REPL buffer."
|
||||
(goto-char (point-max))
|
||||
|
@ -921,13 +921,13 @@ lines then truncate it to something less than
|
|||
(ring-remove jupyter-repl-history -2))
|
||||
(ring-remove+insert+extend jupyter-repl-history code))
|
||||
|
||||
(cl-defmethod jupyter-execute-request ((client jupyter-repl-client)
|
||||
&key code
|
||||
(silent nil)
|
||||
(store-history t)
|
||||
(user-expressions nil)
|
||||
(allow-stdin t)
|
||||
(stop-on-error nil))
|
||||
(cl-defmethod jupyter-send-execute-request ((client jupyter-repl-client)
|
||||
&key code
|
||||
(silent nil)
|
||||
(store-history t)
|
||||
(user-expressions nil)
|
||||
(allow-stdin t)
|
||||
(stop-on-error nil))
|
||||
(with-jupyter-repl-buffer client
|
||||
(jupyter-repl-truncate-buffer)
|
||||
(if code (cl-call-next-method)
|
||||
|
@ -1151,14 +1151,14 @@ REPL buffer."
|
|||
(with-jupyter-repl-buffer client
|
||||
(pcase status
|
||||
("complete"
|
||||
(jupyter-execute-request client))
|
||||
(jupyter-send-execute-request client))
|
||||
("incomplete"
|
||||
(jupyter-repl-newline)
|
||||
(if (= (length indent) 0) (jupyter-repl-indent-line)
|
||||
(jupyter-repl-insert :read-only nil indent)))
|
||||
("invalid"
|
||||
;; Force an execute to produce a traceback
|
||||
(jupyter-execute-request client))
|
||||
(jupyter-send-execute-request client))
|
||||
("unknown"))))
|
||||
|
||||
(cl-defmethod jupyter-handle-shutdown-reply ((client jupyter-repl-client) _req restart)
|
||||
|
@ -1215,12 +1215,12 @@ execute the current cell."
|
|||
'("starting" "idle"))
|
||||
(jupyter-repl-sync-execution-state)
|
||||
(error "Kernel busy"))
|
||||
(if force (jupyter-execute-request jupyter-repl-current-client)
|
||||
(if force (jupyter-send-execute-request jupyter-repl-current-client)
|
||||
(if (not jupyter-repl-use-builtin-is-complete)
|
||||
(let ((res (jupyter-wait-until-received
|
||||
:is-complete-reply
|
||||
(let ((jupyter-inhibit-handlers '(:status)))
|
||||
(jupyter-is-complete-request
|
||||
(jupyter-send-is-complete-request
|
||||
jupyter-repl-current-client
|
||||
:code (jupyter-repl-cell-code)))
|
||||
jupyter-repl-maximum-is-complete-timeout)))
|
||||
|
@ -1431,7 +1431,7 @@ COMMAND and ARG have the same meaning as the elements of
|
|||
(jupyter-add-callback
|
||||
;; Ignore errors during completion
|
||||
(let ((jupyter-inhibit-handlers t))
|
||||
(jupyter-complete-request
|
||||
(jupyter-send-complete-request
|
||||
jupyter-repl-current-client
|
||||
:code code :pos pos))
|
||||
:complete-reply
|
||||
|
@ -1475,7 +1475,7 @@ TIMEOUT is how long to wait (in seconds) for the kernel to
|
|||
respond before returning nil."
|
||||
(let* ((jupyter-inhibit-handlers '(:status))
|
||||
(msg (jupyter-wait-until-received :inspect-reply
|
||||
(jupyter-inspect-request jupyter-repl-current-client
|
||||
(jupyter-send-inspect-request jupyter-repl-current-client
|
||||
:code code :pos pos)
|
||||
timeout)))
|
||||
(when msg
|
||||
|
@ -1544,7 +1544,7 @@ displayed without anything showing up in the REPL buffer."
|
|||
(setq str (string-trim str))
|
||||
(let* ((jupyter-inhibit-handlers
|
||||
(or silently '(:execute-reply :execute-result)))
|
||||
(req (jupyter-execute-request jupyter-repl-current-client
|
||||
(req (jupyter-send-execute-request jupyter-repl-current-client
|
||||
:code (if silently (string-trim str)
|
||||
(prog1 nil
|
||||
(jupyter-repl-replace-cell-code str))))))
|
||||
|
@ -1671,7 +1671,7 @@ With a prefix argument, SHUTDOWN the kernel completely instead."
|
|||
(message "Starting dead kernel...")
|
||||
(jupyter-start-kernel manager)))
|
||||
(unless (jupyter-wait-until-received :shutdown-reply
|
||||
(jupyter-shutdown-request jupyter-repl-current-client
|
||||
(jupyter-send-shutdown-request jupyter-repl-current-client
|
||||
:restart (not shutdown)))
|
||||
(jupyter-set jupyter-repl-current-client 'jupyter-include-other-output nil)
|
||||
(message "Kernel did not respond to shutdown request"))))
|
||||
|
@ -1824,7 +1824,7 @@ in the appropriate direction, to the saved element."
|
|||
;; ring.
|
||||
(ring-insert jupyter-repl-history 'jupyter-repl-history)
|
||||
(let ((jupyter-inhibit-handlers '(:status)))
|
||||
(jupyter-history-request jupyter-repl-current-client
|
||||
(jupyter-send-history-request jupyter-repl-current-client
|
||||
:n jupyter-repl-history-maximum-length :raw nil :unique t))
|
||||
(erase-buffer)
|
||||
;; Add local hooks
|
||||
|
@ -1890,7 +1890,7 @@ Set the execution-count slot of `jupyter-repl-current-client' to
|
|||
kernel goes idle for our request."
|
||||
(let* ((client jupyter-repl-current-client)
|
||||
(req (let ((jupyter-inhibit-handlers t))
|
||||
(jupyter-execute-request client :code "" :silent t))))
|
||||
(jupyter-send-execute-request client :code "" :silent t))))
|
||||
(jupyter-add-callback req
|
||||
:status (lambda (msg)
|
||||
(oset client execution-state
|
||||
|
@ -2116,7 +2116,7 @@ called interactively, display the new REPL buffer as well."
|
|||
(message "Requesting kernel info...")
|
||||
(let* ((jupyter-inhibit-handlers t)
|
||||
(info (jupyter-wait-until-received :kernel-info-reply
|
||||
(jupyter-kernel-info-request client)
|
||||
(jupyter-send-kernel-info-request client)
|
||||
5)))
|
||||
(unless info
|
||||
(destructor client)
|
||||
|
|
|
@ -152,14 +152,14 @@ testing the callback functionality of a
|
|||
(with-jupyter-echo-client client
|
||||
(ert-info ("Request callbacks")
|
||||
(ert-info ("Blocking callbacks")
|
||||
(let ((req (jupyter-execute-request client :code "foo")))
|
||||
(let ((req (jupyter-send-execute-request client :code "foo")))
|
||||
(should (jupyter-wait-until-idle req))
|
||||
(should (jupyter-request-idle-received-p req))
|
||||
;; Can't add callbacks after an idle message has been received
|
||||
(should-error (jupyter-add-callback req :status #'identity))))
|
||||
(ert-info ("Callback runs for the right message")
|
||||
(let ((req1 (jupyter-execute-request client :code "foo"))
|
||||
(req2 (jupyter-kernel-info-request client))
|
||||
(let ((req1 (jupyter-send-execute-request client :code "foo"))
|
||||
(req2 (jupyter-send-kernel-info-request client))
|
||||
ran-callbacks)
|
||||
;; callback for all message types received from a request
|
||||
(jupyter-add-callback req1
|
||||
|
@ -181,7 +181,7 @@ testing the callback functionality of a
|
|||
(should (equal ran-callbacks '(1 1 1 2 2 2)))))
|
||||
(ert-info ("Multiple callbacks for a single message type")
|
||||
(let* ((ran-callbacks nil)
|
||||
(req (jupyter-execute-request client :code "foo")))
|
||||
(req (jupyter-send-execute-request client :code "foo")))
|
||||
(jupyter-add-callback req
|
||||
:execute-reply (lambda (_msg) (push 1 ran-callbacks)))
|
||||
(jupyter-add-callback req
|
||||
|
@ -385,19 +385,19 @@ testing the callback functionality of a
|
|||
(progn
|
||||
(ert-info ("Kernel info")
|
||||
(let ((res (jupyter-wait-until-received :kernel-info-reply
|
||||
(jupyter-kernel-info-request client))))
|
||||
(jupyter-send-kernel-info-request client))))
|
||||
(should res)
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "kernel_info_reply"))))
|
||||
(ert-info ("Comm info")
|
||||
(let ((res (jupyter-wait-until-received :comm-info-reply
|
||||
(jupyter-comm-info-request client))))
|
||||
(jupyter-send-comm-info-request client))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "comm_info_reply"))))
|
||||
(ert-info ("Execute")
|
||||
(let ((res (jupyter-wait-until-received :execute-reply
|
||||
(jupyter-execute-request client :code "y = 1 + 2"))))
|
||||
(jupyter-send-execute-request client :code "y = 1 + 2"))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "execute_reply"))))
|
||||
|
@ -405,14 +405,14 @@ testing the callback functionality of a
|
|||
(cl-letf (((symbol-function 'read-from-minibuffer)
|
||||
(lambda (_prompt &rest _args) "foo")))
|
||||
(let ((res (jupyter-wait-until-received :execute-result
|
||||
(jupyter-execute-request client :code "input('')"))))
|
||||
(jupyter-send-execute-request client :code "input('')"))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "execute_result"))
|
||||
(should (equal (jupyter-message-data data :text/plain) "'foo'")))))
|
||||
(ert-info ("Inspect")
|
||||
(let ((res (jupyter-wait-until-received :inspect-reply
|
||||
(jupyter-inspect-request client
|
||||
(jupyter-send-inspect-request client
|
||||
:code "list((1, 2, 3))"
|
||||
:pos 2
|
||||
:detail 0))))
|
||||
|
@ -421,7 +421,7 @@ testing the callback functionality of a
|
|||
(should (equal (jupyter-message-type res) "inspect_reply"))))
|
||||
(ert-info ("Complete")
|
||||
(let ((res (jupyter-wait-until-received :complete-reply
|
||||
(jupyter-complete-request client
|
||||
(jupyter-send-complete-request client
|
||||
:code "foo = lis"
|
||||
:pos 8))))
|
||||
(should-not (null res))
|
||||
|
@ -429,21 +429,21 @@ testing the callback functionality of a
|
|||
(should (equal (jupyter-message-type res) "complete_reply"))))
|
||||
(ert-info ("History")
|
||||
(let ((res (jupyter-wait-until-received :history-reply
|
||||
(jupyter-history-request client
|
||||
(jupyter-send-history-request client
|
||||
:hist-access-type "tail" :n 2))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "history_reply"))))
|
||||
(ert-info ("Is Complete")
|
||||
(let ((res (jupyter-wait-until-received :is-complete-reply
|
||||
(jupyter-is-complete-request client
|
||||
(jupyter-send-is-complete-request client
|
||||
:code "for i in range(5):"))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "is_complete_reply"))))
|
||||
(ert-info ("Shutdown")
|
||||
(let ((res (jupyter-wait-until-received :shutdown-reply
|
||||
(jupyter-shutdown-request client))))
|
||||
(jupyter-send-shutdown-request client))))
|
||||
(should-not (null res))
|
||||
(should (json-plist-p res))
|
||||
(should (equal (jupyter-message-type res) "shutdown_reply")))))
|
||||
|
|
|
@ -144,7 +144,7 @@ the header variables in PARAMS."
|
|||
(when no-execute
|
||||
(insert "\n")))
|
||||
(unless no-execute
|
||||
(jupyter-execute-request jupyter-repl-current-client))
|
||||
(jupyter-send-execute-request jupyter-repl-current-client))
|
||||
(current-buffer))))
|
||||
|
||||
(defun org-babel-load-session:jupyter (session body params)
|
||||
|
@ -464,7 +464,7 @@ the PARAMS alist."
|
|||
'(:stream
|
||||
:execute-reply :execute-result
|
||||
:display-data :error)))
|
||||
(jupyter-execute-request client)))))
|
||||
(jupyter-send-execute-request client)))))
|
||||
;; Setup callbacks for the request
|
||||
(let* ((result-type (alist-get :result-type params))
|
||||
(no-results (member "none" (alist-get :result-params params)))
|
||||
|
|
Loading…
Add table
Reference in a new issue