- Add a `message-publisher` slot to `jupyter-request`, set when
sending a request.
- `*-request` functions now return a delayed request value instead of
a request. Update call sites.
- Add the functions `jupyter-messages`, `jupyter-idle`,
`jupyter-message-subscribed` and `jupyter-client-subscribed`.
- Move client subscription to a request's messages to
`jupyter-client-subscribed`.
- Request callbacks are now added via `jupyter-message-subscribed`.
- Reduce usage of callbacks in favor of searching `jupyter-messages`
where appropriate.
- Update tests
`jupyter-websocket-io` now returns, in addition to an IO function, a
kernel action subscriber. A client now sends messages to the
subscriber to interrupt or shutdown a kernel instead of doing so using
a `kernel` slot.
Also add the `jupyter-kernel-action` convenience function for
evaluating arbitrary code on a client's kernel.
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-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 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.
The merged class is `jupyter-kernel-process`.
The `jupyter-command-kernel` class existed to launch kernels using the
`jupyter kernel` shell command. This was done to support launching
kernels on remote systems via TRAMP. The work of generating a
connection info. file was offloaded to that command since it can find
out a set of open ports more reliably on a remote system than Emacs
can.
The only difference between the two classes was that the connection
info. was generated manually for a `jupyter-spec-kernel`, so now the
`jupyter kernel` command is relied on in that case too (via
`jupyter-session-with-random-ports` from
8ad90b887a4afa161d907056ae44db5b119dbc5d).
* jupyter-kernel-process-manager.el
(jupyter-env, jupyter-kernelspec): Require.
(jupyter--after-kernel-process-ready): Remove.
(jupyter--start-kernel-process): New function.
(jupyter-start-kernel)
[jupyter-kernel-process]: Use it, set the SESSION slot of a kernel
before doing so.
(jupyter-command-kernel, jupyter-spec-kernel): Remove. Also remove all
related methods.
(jupyter-start-new-kernel): Use `jupyer--kernel-process` to replace
calls to the removed classes.
* test/jupyter-test.el
(jupyter-kernel-lifetime)
(jupyter-command-kernel): Replace references to removed classes with
`jupyter--kernel-process`
* jupyter-comm-layer.el
(jupyter-comm-initialize): Remove default method. This is in
preparation for moving over to classless communication.
* jupyter-channel-ioloop-comm (jupyter-connection): Require.
(jupyter--proxy-channel): New type.
(jupyter--make-channel-group, jupyter--channel-alive-p)
(jupyter--start-channel, jupyter--stop-channel)
(make-jupyter-async-connection): New functions.
(jupyter-channel-ioloop-comm): Remove `ioloop-class` slot, update all
callers. Remove `channels` slot, update all setters and
references. Add `conn` slot which holds a `jupyter-connection`.
(jupyter-comm-initialize): Initialize the `conn` slot to the
connection returned by `make-jupyter-async-connection`.
(jupyter-comm-start, jupyter-comm-stop)
(jupyter-comm-alive-p, jupyter-comm-id, jupyter-channel-alive-p)
(jupyter-stop-channel, jupyter-start-channel): Replace the body of these
functions with their equivalents in `conn`.
* jupyter-kernel-process-manager.el
(jupyter-make-client): Update `jupyter-channel-ioloop-comm` call.
* jupyter-repl.el:
(jupyter-connect-repl): Ditto.
* test/test-helper.el
(initialize-instance) [jupyter-echo-client]: Ditto. Replace setting of
`channel` slot with setting the `conn` clot.
The new files added in this commit will eventually replace the manager
and kernel classes and favor struct types to represent kernels instead
of classes. A kernel manager was a concept ripped from the
jupyter/jupyter_client reference implementation.
In Emacs the concept makes the client implementation more complicated
and is replaced by functions that manage the lifetime of a kernel:
`jupyter-launch`, `jupyter-shutdown`, and `jupyter-interrupt`.
* jupyter-kernel-manager.el
* jupyter-kernel-process-manager.el
* jupyter-server.el
* test/jupyter-server-test.el
* test/test-helper.el: Make `jupyter-kernel`, `jupyter-server-kernel`,
and `jupyter-kernel-process` private classes. The new files below
use the public names, but as structs now.
* jupyter-kernel.el
* jupyter-kernel-process.el
* jupyter-server-kernel.el: New files.