This is to handle message relaying in `jupyter-widget-client`.
* jupyter-client.el (jupyter-send): Do it. Update doc.
* jupyter-widget-client.el (jupyter-widgets-on-message): Change
argument order of `jupyter-send` call.
Somehow this was not done until now. I had in my mind that shutting
down and interrupting a kernel was part of the responsibility of the
manager class. This is how it is done in the reference
jupyter/jupyter_client implementation, I think.
* jupyter-client.el (jupyter-shutdown-kernel)
(jupyter-interrupt-kernel): New functions.
* jupyter-repl.el
(jupyter-repl-restart-kernel): Use the `jupyter-shutdown-kernel`
method to restart a client's kernel.
* jupyter-client.el (jupyter-client-has-manager-p): Do it.
(initialize-instance)
* jupyter-repl.el
(jupyter-repl-kill-buffer-query-function)
* test/jupyter-test.el (jupyter-repl-client-predicates): Update all callers.
Remove `jupyter-channel-ioloop-comm.el`, `jupyter-comm-layer.el`, `jupyter-ioloop-comm.el`.
Remove the kcomm slot of a client, replace it with a kernel slot.
jupyter-server.el: Remove kernel communication related code.
Remove `jupyter-kernel-lifetime`.
* jupyter-kernel-manager.el (jupyter-kernel-lifetime): Do it. Update
all subclasses. All methods it defined no longer take a type. This
is in preparation of removing most of them altogether.
(jupyter-kernel-manager): Update doc.
* jupyter-kernel-process-manager.el
(jupyter-kernel-process): Update documentation.
(jupyter--kernel-died-process-sentinel): Remove type check.
* test/jupyter-test.el (jupyter-local-tcp-conn-info): Remove.
(jupyter-kernel-lifetime): Remove.
[conn] Have `jupyter-kernel-manager.el` re-direct to the new interface
* jupyter-kernel-manager.el
(jupyter-kernel-alive-p): Check that the kernel is
live, not an Emacs connection to it.
(jupyter-start-kernel)
[jupyter-kernel, jupyter-kernel-manager]: Use `jupyter-launch`.
(jupyter-shutdown-kernel) [jupyter-kernel-manager]: Use `jupyer-shutdown`.
(jupyter-kill-kernel) [jupyter-kernel]: Ditto. Remove a method
definition.
(jupyter-make-client): Use `jupyter-client`.
(jupyter-interrupt-kernel) [jupyter-kernel-manager]: Use `jupyer-interrupt`.
* jupyter-kernel-process-manager.el: Remove.
Don't add finalizer to cleanup process.
Cleanup is done in other ways, e.g. in
`jupyter--gc-kernel-processes`. Also it doesn't make sense to delete
a general kernel because the object that represents it in Emacs is no
longer accessible.
* jupyter-channel-ioloop-comm.el
(jupyter-channel-ioloop-comm): Remove it from the super-class list.
Add a `hb` slot to compensate.
(jupyter-hb-beating-p, jupyter-hb-pause)
(jupyter-hb-unpause): Relocated from...
* jupyter-comm-layer.el: ...here.
* jupyter-client.el (jupyter-hb-beating-p, jupyter-hb-pause)
(jupyter-hb-unpause): Check for a `hb` slot instead of it.
Previously it was hard to step through the code whenever messages were
coming in live from a kernel due to the asynchronous nature of
handling process output in Emacs.
but first...
* jupyter-base.el: ...idle-received-p -> idle-p for jupyter-request objects
* jupyter-client.el: ...then, do it.
* test/jupyter-test.el: Do it.
These will be used in future commits.
* jupyter-client.el (jupyter-idle-sync)
(jupyter-add-idle-sync-hook): New functions.
* test/jupyter-test.el (jupyter-idle-sync): New test.
The following changes are made:
jupyter--run-handler-p -> jupyter--request-allows-handler-p
jupyter--handler-dispatch -> jupyter--run-handler
* jupyter-client.el: Do it.
* test/jupyter-test.el: Do it.
`jupyter-handle-*` methods now only take an argument list like
(client req msg)
instead of each method being passed an expanded list of arguments
unpacked from a message contents. Not sure why the unpacking was done
in the first place. The strategy now is to use
`jupyter-with-message-contents` when accessing the contents of a
message.
* jupyter-client.el
(define-jupyter-client-handler)
(define--jupyter-client-sender): New macros.
(jupyter-send-execute-request)
(jupyter-send-inspect-request)
(jupyter-send-complete-request)
(jupyter-send-history-request)
(jupyter-send-is-complete-request)
(jupyter-send-comm-info-request)
(jupyter-send-comm-open)
(jupyter-send-comm-msg)
(jupyter-send-comm-close)
(jupyter-send-kernel-info-request)
(jupyter-send-shutdown-request): Use `define--jupyter-client-sender`.
(jupyter-handle-input-request)
(jupyter-handle-execute-reply)
(jupyter-handle-inspect-reply)
(jupyter-handle-complete-reply)
(jupyter-handle-history-reply)
(jupyter-handle-is-complete-reply)
(jupyter-handle-comm-info-reply)
(jupyter-handle-kernel-info-reply)
(jupyter-handle-shutdown-reply)
(jupyter-handle-comm-open)
(jupyter-handle-comm-close)
(jupyter-handle-stream)
(jupyter-handle-execute-input)
(jupyter-handle-execute-result)
(jupyter-handle-error)
(jupyter-handle-status)
(jupyter-handle-clear-output)
(jupyter-handle-display-data)
(jupyter-handle-update-display-data): Use
`define-jupyter-client-handler`.
* jupyter-org-client.el
(jupyter-handle-stream)
(jupyter-handle-error)
(jupyter-handle-execute-result)
(jupyter-handle-display-data)
(jupyter-handle-execute-reply): Update to take into account changes in
the argument lists of `jupyter-handle-*` methods.
* jupyter-python.el
(jupyter-handle-error): Ditto.
* jupyter-repl.el
(jupyter-handle-execute-reply)
(jupyter-handle-execute-result)
(jupyter-handle-clear-output)
(jupyter-handle-display-data)
(jupyter-handle-update-display-data)
(jupyter-handle-status)
(jupyter-handle-stream)
(jupyter-handle-error):
(jupyter-handle-history-reply)
(jupyter-handle-shutdown-reply): Ditto.
* jupyter-widget-client.el
(jupyter-handle-comm-open)
(jupyter-handle-comm-close)
(jupyter-handle-comm-msg): Ditto.
Reduce the number of arguments `jupyter-handle-message` takes, by just
passing the message property list directly. Expanding out the
arguments just creates unnecessary work. Make the
`jupyter-kernel-client' implementation of `jupyter-handle-message`
more readable. Remove the unnecessary and confusing handler method
dispatching. Document `jupyter-handle-message`.
* README.org: Update reference to `jupyter-handle-*` method.
* jupyter-client.el
(jupyter-dispatch-messages-cases): Remove.
(jupyter-run-hook-with-args-until-success): Remove.
(jupyter-handle-message-p): New function. Similar to the above except
its return value is negated.
(jupyter--client-handlers): New variable. Holds the table of message
handlers.
(jupyter--handler-dispatch): Use them.
(jupyter--run-callbacks): Change to `defsubst`
(jupyter--run-handler-maybe): Remove. Expand out at call sites, replace
`jupyter-handle-message` with `jupyter--handler-dispatch` at the sites.
(jupyter--handler-dispatch): New function. Unifies all the
`jupyter-handle-message` implementations for channels.
(jupyter--update-execution-state, jupyter--message-completes-request-p): New functions.
(jupyter-handle-message): Remove channel implementations. Use the new
functions in the client implementation.
The following changes are made:
`jupyter-initialize-connection` -> `jupyter-comm-initialize`
`jupyter-connect-client` -> `jupyter-comm-add-handler`
`jupyter-disconnect-client` -> `jupyter-comm-remove-handler`
`jupyter-comm-client-loop` -> `jupyter-comm-handler-loop`
* README.org: Do it.
* jupyter-channel-ioloop-comm: Do it.
* jupyter-client.el: Do it.
* jupyter-comm-layer.el: Do it.
(jupyter-comm-layer): Rename `clients` slot to `handlers`. Update all uses.
* jupyter-kernel-process-manager.el: Do it.
* jupyter-repl.el: Do it.
* jupyter-server.el: Do it.
* jupyter-zmq-channel-comm.el: Do it.
* test/jupyter-server-test.el: Do it.
* test/jupyter-test.el: Do it.
* README.org: Add notes on behavior when a kernel's language name has spaces
and uppercase characters.
* jupyter-base.el (jupyter-canonicalize-language-string): New function.
* jupyter-client.el (jupyter-kernel-info): Use it.
* jupyter-kernelspec.el (jupyter-available-kernelspecs): Use it.
* ob-jupyter.el (org-babel-jupyter-aliases-from-kernelspecs): Use it.
* test/jupyter-test.el (jupyter-canonicalize-language-string): New test.
`jupyter-wait-until-idle` can return immediately if an idle message has already
been received, but the function `jupyter-wait-until` will eventually raise an
error in that case. Avoid the error by checking
`jupyter-request-idle-received-p` before calling `jupyter-wait-until`.
* jupyter-client.el (jupyter-wait-until-idle): Do it.
* ob-jupyter.el (org-babel-execute:jupyter): Account for changes in
`jupyter-wait-until-idle`.