Commit graph

1895 commits

Author SHA1 Message Date
Nathaniel Nicandro
7a52f6240d Update jupyter-kernel-process test 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
140284de80 Re-word doc of jupyter--kernel-processes 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
4c41ea176f Use an extra jupyter-shutdown method to stop a kernel's IO 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
c30d2effaa Make the server slot of a jupyter-server-kernel read-only 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
3e40fde7ec Replacement for jupyter-conn-id 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
dc91912d5b Remove duplicated use of jupyter-session-with-random-ports
This is already done in `jupyter-launch`.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
996d53e0b0 Use new connection interface in some places
* jupyter-repl.el
(jupyter-repl-kill-buffer-query-function): Use `jupyter-kernel`,
`jupyter-clients`, `jupyter-disconnect`, and `jupyter-shutdown`.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
58f281c7fc Remove conn slot of a client and clients slot of a kernel 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
4abf0d0714 Cleanup whitespace 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
73955c2d14 Clarify the name of some internally used functions 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
d1a344a000 Do not specify jupyter-send' and jupyter-stop as specific to jupyter-channel` 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
55009e3a0d Use jupyter-session-endpoints in one place 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
9b2a66868a IO function and connections 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
eba2bcc280 Move initialization of ioloop into the context of the connection 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
5d6dd04949 Remove duplicated function call
* jupyter-kernel-process.el (jupyter-connection): Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
6ca11d695d Add a special case to the jupyter-send method of a client
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
754f3ed5ff Use jupyter-connection for jupyter-server-kernel objects
This fixes errors with jupyter--send being defined
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
31f0ef4f93 Add jupyter--kernel-connection
Also tidy up `jupyter-connection`
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
0c6d90cc7e Undo a client connection when a kernel doesn't respond
* jupyter-client.el (jupyter-client): Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
705462c35d Remove the need to start a connection before sending a message 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
b814e05223 Formalize jupyter-disconnect and jupyter-connect 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
9df6d01070 Move ioloop synchronization into server conn object 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
5049cdf9ed jupyter-server-kernel.el organization
Also add missing `jupyter-connection` require.
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
39c30fff11 Fix kernel-alive-p predicate 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
2ccab95d0e Cleanup REPL launching commands
* 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`.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
d137540061 Simplify the meaning of a jupyter-connect-repl argument
* 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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
0521bca637 Add shutdown and interrupt functions to a client
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.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
790a29fe5d Reconnect clients after kernel restart 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
c06b71a3f0 Remove unused function
* jupyter-repl.el (jupyter-repl-display-kernel-buffer): Do it.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
61d01dfcf1 Skip some tests 2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
805048f0f7 Pre-fix jupyter-connect-repl to allow tests to pass
Just to allow tests to pass at this commit
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
390a6c814e Replace jupyter-start-new-kernel calls with jupyter-client 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
707ebd189f Add jupyter-client method 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
7398b2c4f8 2/2 Implement new connection interface for kernel servers
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`.
2023-02-13 20:21:14 -06:00
Nathaniel Nicandro
cb43fe137a 1/2 Implement new connection interface for kernel servers
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.
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
3fed81216e Cleanup dead kernel processes when starting new ones
* jupyter-kernel-process-manager.el
(jupyter--kernel-processes): New variable.
(jupyter--gc-kernel-processes): New function.
(jupyter--start-kernel-process): Use them.
2023-02-13 20:21:14 -06:00