Commit graph

232 commits

Author SHA1 Message Date
Nathaniel Nicandro
8acb7bc487 Simplify jupyter-wait-until-idle 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
22d2a3f327 Remove the jupyter-send method...
- 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
2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
ac35f52e02 Add :callbacks and :handlers keys to request calls 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
bbb32457a9 Remove requests slot of a client 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
b46cf42aa3 Remove jupyter-last-sent-request 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
422c59ee48 Remove the pending request interface 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
a76d772716 (send ... (request ...)) -> (request ...) 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
dfd1d1e02d Remove the kernel slot of a client
`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.
2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
f81a44b865 Comment out failing part of test 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
134167e65e Remove keyword message types 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
cbd521dc72 Remove jupyter-find-server
The same `jupyter-server` instance is always returned for the same URL
by a call to `jupyter-server` so there is no need to find a server
anymore.
2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
f02337c23c Skip jupyter-connect-repl test
Connecting to a REPL via a JSON file is no longer possible.
2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
a430f4f0e1 Remove jupyter-channels-running-p 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
548b23cba2 test/test-helper.el: Fix client cache cleanup 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
0c0ff8fb0b Fix wrong usage of jupyter-request in tests 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
f2cc7ef269 Fix Org :dir header arg test
Since notebook kernels are being used, the directory switched to needs
to be under the tree accessible by the kernel.
2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
a66e15277d Actually delete temporary test directory after running tests 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
b0a9258bd7 Fix jupyter-send calls in tests 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
2cf188d761 Remove zmq dependency 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
67b633d52d Update jupyter-test-with-kernel-client to use a notebook kernel 2023-02-13 20:25:05 -06:00
Nathaniel Nicandro
b44bd8fff1 Remove more references to kernel managers 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
18027386d4 Update test helpers 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
e7c0919fce Remove tests related to jupyter-kernel-process, ioloop, comm, zmq, and channels 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
e1bf33ea55 Update jupyter-send calls in tests 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
9d801b72a3 Remove jupyter-connection.el 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
e133c34707 Add do prefix to launch,shutdown,interrupt functions of a kernel
launch,shutdown,interrupt are now monadic functions.
2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
dcf2e2ef6e Remove jupyter-finalized-object 2023-02-13 20:22:50 -06:00
Nathaniel Nicandro
8f9f563afc Fix test 2023-02-13 20:22:49 -06:00
Nathaniel Nicandro
2d807d8670 Replace uses of jupyter-clients
This function is used elsewhere.
2023-02-13 20:22:49 -06:00
Nathaniel Nicandro
b5fac750e3 Remove setting of conn slot of a client in tests 2023-02-13 20:22:49 -06:00
Nathaniel Nicandro
4393e8adb0 Update tests for jupyter-kernel-process 2023-02-13 20:22:49 -06:00
Nathaniel Nicandro
7a52f6240d Update jupyter-kernel-process test 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
e111aba096 Move jupyter-(dis)?connect into the jupyter-connection interface
The former pair of methods were only used to connect clients and
kernels.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
348df7feb5 Remove jupyter-send-* methods
These methods were not used much internally.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
82e5a0fbc2 Remove jupyter-server-kernel-connected-p
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
8cd90fb9e0 Fix ordering of test cleanup
Stop the clients before stopping an connections to kernel servers.

* test/test-helper.el: Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
55ee3e7e46 Use jupyter-process-environment in one place
* test/test-helper.el (jupyter-test-ipython-kernel-version): Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
c18a5a9763 Remove a use of the manager slot of a client 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
f2c9d5fb25 Convert jupyter-kernel into a method
* 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`.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
a33231b4d3 Rename many methods 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
20c1c80bc0 Remove jupyter-client-has-manager-p
* 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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
61d01dfcf1 Skip some tests 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
aa6826962d Fix manager slot check during tests
`(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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
bdb8488bf3 Remove comm-layer and related
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
dbbaf8ed77 Remove the jupyter-server test
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
1ac3d658e9 Simplify connection file removal
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
47689ed0ce Return file name as directory
* jupyter-env.el (jupyter-runtime-directory): Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
eafbc9f967 Merge jupyter-spec-kernel and jupyter-command-kernel
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`
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
93eeda42a6 Replace jupyter-channel-ioloop-comm internals with new impl.
* 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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
95f3e150b4 Add jupyter-kernel.el and related
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.
2023-02-13 20:21:14 -06:00