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.
This was mainly used when having to refresh the websocket connections
to a server after a REST request. Refreshing the websocket
connections is now handled internally to the connection of a
`jupyter-server`.
* jupyter-server-kernel.el
(initialize-instance): Add `kernel-ids` variable, modify it when
connecting/disconnecting kernel channels to the server's websocket
connections. When starting the subprocess that handles websocket
connections, re-connect any previously connected kernels.
(jupyter-server--refresh-comm): Remove.
(jupyter-server-kernel-connected-p): Remove.
(jupyter-api-request): Use `jupyter-start`/`jupyter-stop` when
refreshing websocket connections.
(jupyter-server--connect-channels): Use `jupyter-ioloop-wait-until`.
(jupyter-connection): Remove `jupyter-server-kernel-connected-p`
call.
* jupyter-kernel-process.el
* jupyter-server-kernel.el (jupyter-kernel): New method.
* jupyter-kernel.el (jupyter-kernel): Convert. Load files that handle
keywords and re-dispatch when ARGS does not have any connection
info. Document behavior.
* test/test-helper.el (jupyter-test-with-kernel-client)
* jupyter-server.el
(jupyter-connect-server-repl)
(jupyter-server-start-new-kernel): Use `jupyter-kernel`.
* jupyter-repl.el
(jupyter-run-repl): Don't treat interactive calls separately from
non-interactive ones, validation of the kernel name in both types of
calls is done now by using `jupyter-guess-kernelspec`. Use
`jupyter-client` to launch the kernel and connect a client.
(jupyter-connect-repl): Use `jupyter-client`.
* jupyter-base.el (jupyter-read-connection): Validate connection info.
* jupyter-repl.el (jupyter--connection-info): Remove
(jupyter-connect-repl): Only allow a file path as the first argument of
`jupyter-connect-repl`. Update doc. No need to update any callers
since the other form of the argument was not used.
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.
`(slot-boundp client 'manager)` always returns t since the `manager`
slot defaults to `nil` for every client. To check for a manager we
need to check for a non-nil `manager` slot.
* test/test-helper.el
(jupyter-test-with-client-cache): Check for a non-nil `manager` slot.
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.
Since `jupyter-comm-layer` is being removed and `jupyter-server`s
behavior that involves kernel connections is being moved into an
implementation detail, see `jupyter-connection` and `jupyter-io` in
future commits.
* test/jupyter-server-test.el: Do it.
This commit removes the `jupyter-comm-layer` dependency of
`jupyter-server`.
* jupyter-server.el
(jupyter-connection): Require.
(jupyter-ioloop-comm): Remove require.
(jupyter-server): Remove the superclass. Add `ioloop` and `handlers`
slot to compensate.
(jupyter-gc-servers)
(jupyter-server-kernel-connected-p)
(jupyter-server--connect-channels)
(jupyter-server--disconnect-channels): Use the `ioloop` slot and
related methods instead of `jupyter-comm-layer` methods.
(jupyter-server--refresh-comm): Ditto, but replace the
`jupyter-comm-start` call with `jupyter-server--start-comm`.
(jupyter-event-handler): Transfer to `ioloop` slot initialization in
`jupyter-server--start-comm`.
(jupyter--server-event-handler): New type. The `handlers` slot is
a list of these.
(jupyter-server--start-comm): Initialize `ioloop` slot. All unhandled
events received on `ioloop` are passed to the handlers in `handlers`.
This commit has `jupyter-server-kernel-comm` use the new
`jupyter-connection` interface.
* jupyter-server.el
(jupyter-server-kernel-comm): Add `conn` slot.
(jupyter-server--connect-channels): Group with the new interface.
(jupyter-comm-start, jupyter-comm-add-handler)
(jupyter-comm-remove-handler) [jupyter-server]: Remove.
(jupyter-server--start-comm, jupyter--disconnect-channels)
(make-jupyter-server-connection): New functions. What the
removed functions did, these do.
(jupyter-comm-start, jupyter-comm-id, jupyter-comm-stop)
(jupyer-send, jupyter-comm-alive-p) [jupyter-server-kernel-comm]:
Replace the body of these with their equivalent in the new interface.
In `jupyter-comm-start`, set the `conn` slot to the connect returned
by `make-jupyter-server-connection` before starting the connection.
This is mostly a refactor of the old behavior except now the removal
of connection files happens in `kill-emacs-hook` and also when
cleaning up dead kernel processes.
* jupyter-env.el
(jupyter-write-connection-file): Turn into a `defun`. Remove the
connection file removal code.
* jupyter-kernel-process-manager.el
(jupyter--kernel-processes): Mention new form of elements in doc.
(jupyter-delete-connection-files): New function. Add it to
`kill-emacs-hook` at top-level.
(jupyter--gc-kernel-processes):
(jupyter--start-kernel-processes): Use new form of
`jupyter--kernel-processes`.
(jupyter-local-tcp-conn-info): Relocate to...
* test/jupyter-test.el: ...here.
(jupyter-write-connection-file): Update test.
* jupyter-kernel-process-manager.el
(jupyter--kernel-processes): New variable.
(jupyter--gc-kernel-processes): New function.
(jupyter--start-kernel-process): Use them.