Commit graph

40 commits

Author SHA1 Message Date
Nathaniel Nicandro
fca3671d4e jupyter-meta-kernel -> jupyter-kernel 2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
25270f7d3b Remove some method implementations
The `jupyter-kill-kernel` of a kernel manager serves no purpose, just
use `jupyter-shutdown-kernel`.

* jupyter-kernel-manager.el
(jupyter-kill-kernel) [jupyter-kernel-manager]: Remove.

* jupyter-server.el (jupyter-kill-kernel) [jupyter-server-kernel-manager]: Remove.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
71789f7cfd Remove more jupyter-channels-running-p implementations
The implementations are really aliases of `jupyter-comm-alive-p` so
keep that one instead.  The `jupyter-channels-running-p` method is a
remnant of an older design, still used by `jupyter-kernel-client'
though.

* jupyter-channel-ioloop-comm.el: Do it.

* jupyter-server.el: Do it.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
403c70c83c Bump version 2020-04-07 15:13:51 -05:00
Nathaniel Nicandro
4ce54a056b Add jupyter-server-has-kernelspec-p
* jupyter-server.el (jupyter-server-has-kernelspec-p): New method.

* ob-jupyter.el (org-babel-jupyter--server-repl): Use it.
2020-04-03 18:43:53 -05:00
Nathaniel Nicandro
a4e0616ed4 Revert commits making ZMQ optional
These commits were pre-maturely pushed to master.

This reverts commits:

    - 3322ce7b31
    - ee8b5180e5
    - 8883a6631a
    - ae5dad9796
    - 0e202a02fa
    - 5725215268
    - 3b3e358933
    - a5f8d991b0
    - 1a739feec7
    - 4115ff5f73
2020-04-02 10:48:44 -05:00
Nathaniel Nicandro
ee8b5180e5 Make ZMQ an optional user dependency
* jupyter-server.el (jupyter-ioloop, jupyter-server-ioloop): Remove requires.
(jupyter-server): Don't subclass `jupyter-ioloop-comm`.
(jupyter-server--connect-channels, jupyter-server--refresh-comm): Only do
something when the SERVER argument is a `jupyter-comm-layer`, i.e. a
`jupyter-server-ioloop-comm`.  We don't check for that class directly since we
would end up requiring ZMQ.
(jupyter-comm-start) [jupyter-server-kernel-manager]: Use the right subclass of
`jupyter-server-abstract-kcomm` depending on if the `jupyter-server` object is
using ZMQ for communication.
(jupyter-server-make-instance): New function. Returns a `jupyter-server`
instance (a `jupyter-server-ioloop-comm`) that uses ZMQ if
`jupyter-server-use-zmq` is non-nil, and a plain old `jupyter-server` instance
otherwise.
(jupyter-current-server): `jupyter-server` -> `jupyter-server-make-instance`.

* ob-jupyter.el (org-babel-jupyter--server-repl): `jupyter-server` ->
  `jupyter-server-make-instance`.

* test/test-helper.el (jupyter-test-with-notebook): `jupyter-server` ->
  `jupyter-server-make-instance`.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
5725215268 Implement a jupyter-comm-layer using a websocket
The `jupyter-server-kernel-comm` class is re-purposed for this, as mentioned in
the previous commit.

* jupyter-server.el (jupyter-server--ws-on-message): New function.
(jupyter-comm-start, jupyter-comm-stop, jupyter-comm-alive-p, jupyter-send)
[jupyter-server-kernel-comm]: New methods.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
3b3e358933 Split ZMQ related code from jupyter-server.el
In the following, accept means moved from `jupyter-server.el` and move means
moved to `jupyter-server-ioloop-comm.el`.  A label like [class] means the
references that appear before the label are actually methods of class.

  * jupyter-server.el: Move all `jupyter-event-handler` methods.
  (jupyter-server-kernel-comm): Add `ws` slot. The class has
  been repurposed for communication using a websocket in the current Emacs
  instance.  The old behavior has been assigned to the
  `jupyter-server-ioloop-kernel-comm` class.
  (jupyter-comm-id, jupyter-server-name-client-kernel)
  (jupyter-channel-alive-p, jupyter-channels-running-p)
  (jupyter-server-kernel-manager, jupyter-current-server): Rename
  `jupyter-server-kernel-comm` to `jupyter-server-abstract-kcomm`.
  (jupyter-server-kernel-connected-p): Redefine as a generic function.  Move the
  method body.
  (jupyter-comm-start, jupyter-connect-client)
  (jupyter-disconnect-client) [jupyter-server]: Move.
  (jupyter-comm-start, jupyter-comm-stop)
  (jupyter-send, jupyter-comm-alive-p) [jupyter-server-kernel-comm]: Move.

  * jupyter-server-ioloop-comm.el: Accept moved `jupyter-event-handler`
    methods.  Rename `jupyter-server` to `jupyter-server-ioloop-comm`.  Rename
    `jupyter-server-kernel-comm` to `jupyter-server-ioloop-kernel-comm`.
  (jupyter-server-kernel-connected-p)
  (jupyter-comm-start, jupyter-connect-client)
  (jupyter-disconnect-client) [jupyter-server]: Accept.
  (jupyter-comm-start, jupyter-comm-stop)
  (jupyter-comm-alive-p, jupyter-send) [jupyter-server-kernel-comm]: Accept.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
a5f8d991b0 Introduce new file and custom variable
* jupyter-server-ioloop-comm.el: New file.

* jupyter-server.el (jupyter-server-use-zmq): New variable.
(jupyter-server-abstract-kcomm): New class.
(jupyter-server-kernel-comm): Inherit from it. This is in preparation of
re-purposing the class in a future commit.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
1c45c3226b Mass rename of jupyter-comm-layer related functions
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.
2020-03-29 03:08:53 -05:00
conao3
fb8c2c75fd two spaces after a period 2020-03-12 18:20:15 -05:00
conao3
1546a72f57 clean header 2020-03-10 23:39:35 -05:00
Nathaniel Nicandro
e92d265869 jupyter-server-kernel-list-mode: Sort list by activity
* jupyter-server.el (jupyter-server--kernel-list-entries):
Add missing jupyter-time text property to activity string.
(jupyter-server-list-kernels): Set `tabulated-list-sort-key`.
2019-09-23 20:40:39 -05:00
Nathaniel Nicandro
c1b597556b Light refactoring
* jupyter-base.el: Don't add `jupyter-server-mode--unset-client-soon` to
`server-switch-hook` at toplevel
(jupyter-server-mode-set-client): Add `jupyter-server-mode--unset-client-soon`
to `server-switch-hook` if necessary.

* jupyter-client.el: (jupyter--run-callbacks): Use `when-let`.
(jupyter--set-callback): Remove.
(jupyter--add-callback): Use `add-function`.

* jupyter-ioloop.el (jupyter-ioloop-add-arg-type): Use `setf` along with `alist-get`.
(jupyter-ioloop--replace-args): Use `pcase`.
(jupyter-ioloop--event-dispatcher): Extract out event cases into variable `user-events`.
(jupyter-ioloop--body): New function.
(jupyter-ioloop--function): Use it.

* jupyter-kernel-process-manager.el
(jupyter--kernel-died-process-sentinel)
(jupyter-stop-channels): Use `when-let`.

* jupyter-org-client.el (jupyter-org-interaction-mode): Use `cl-callf2?`.

* jupyter-server.el: Add TODO.

* jupyter-tramp.el: Remove unused function declaration.
2019-09-22 14:27:40 -05:00
Nathaniel Nicandro
470521dac5 jupyter-current-server: Signal an error for non-existent servers
Only do so when asking the user for a URL and no server exists at the URL
provided. See #183.

* jupyter-server.el (jupyter-server-non-existent): New error.
(jupyter-current-server): Signal `jupyter-server-non-existent` when asking the
user for a server URL and a server doesn't exist at URL.
2019-09-15 20:26:54 -05:00
Nathaniel Nicandro
8fd5d8d95e Fix error handling in TRAMP functions for Emacs >= 27
TRAMP sets its own value of `signal-hook-function` which interferes with
`signal` data when handling errors in `condition-case` so unbind
`signal-hook-function` until we have a chance to look at `signal` data.

* jupyter-server.el (jupyter-kernel-alive-p): Use `nth`

* jupyter-tramp.el (jupyter-tramp--get-directory-or-file-model)
(jupyter-tramp-delete-directory): Unbind `signal-hook-function`.
2019-09-15 19:00:18 -05:00
Nathaniel Nicandro
49ad1eef83 jupyter-comm-id (jupyter-server-kernel-comm): Return kernel alias if available 2019-09-15 14:50:43 -05:00
Nathaniel Nicandro
7a1c91eef4 Add the jupyter-kernel-process-manager class
So as to further generalize and separate out the abstract kernel manager class
from its various implementations.

* jupyter-kernel-manager.el (jupyter-meta-kernel): Fix documentation.
(jupyter-kernel-process, jupyter-command-kernel, jupyter-spec-kernel):
Move related functions and methods to `jupyter-kernel-process-manager.el`
(jupyter-kernel-manager-base): Remove class.
(jupyter-kernel-manager): Re-purpose class as the base class of all kernel
managers. The class corresponding to the old functionality is now named
`jupyter-kernel-process-manager`. Move all related functions and methods for
`jupyter-kernel-process-manager` to `jupyter-kernel-process-manager.el`.

* jupyter-kernel-process-manager.el: New file.

* jupyter-repl.el: Require `jupyter-kernel-process-manager` instead of
`jupyter-kernel-manager`.

* jupyter-server.el (jupyter-server-kernel-manager): Inherit from
`jupyter-kernel-manager` instead of `jupyter-kernel-manager-base`.

* test/jupyter-test.el (jupyter-kernel-lifetime)
(jupyter-command-kernel): Use `jupyter-kernel-process-manager` instead of
`jupyter-kernel-manager`.

* test/test-helper.el: Require `jupyter-kernel-process-manager` instead of
`jupyter-kernel-manager`.
2019-08-08 22:04:27 -05:00
Nathaniel Nicandro
f4aa755126 Add jupyter-server--refresh-comm 2019-08-08 17:51:20 -05:00
Nathaniel Nicandro
8f35f135d7 jupyter-gc-servers: Delete cookies when cleaning up servers
See #161

* jupyter-rest-api.el (jupyter-api--delete-cookie):
(jupyter-api-delete-cookies): New functions.

* jupyter-server.el (jupyter-gc-servers): Do it.

* test/jupyter-server-test.el (jupyter-api-delete-cookies): New test.
2019-07-31 14:19:15 -05:00
Nathaniel Nicandro
6f97c958da Add jupyter-server-kernel-names variable and associated functions
Used to associate names to kernel IDs.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
ea22bd512d Re-authenticate after "Access Forbidden" 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
c711562207 jupyter-gc-servers: Only stop server comm if it is alive
Bug found by @dcherian, see
https://github.com/dzop/emacs-jupyter/issues/131#issuecomment-510920312
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
388f593955 jupyter-kernel-alive-p (jupyter-server-kernel): Handle non-existent server 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
6d7b07333f Add jupyter-api-server-exists-p 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
36b9edc31e jupyter-server-find-manager: Don't check if the kernel is alive
Delay any errors, e.g. if the server is no longer alive, to where they would be
more useful.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
5efa64ff19 jupyter-server-list-kernels: Better documentation 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
239715919f Move server slot of jupyter-server-kernel-manager to the kernel object 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
f4c03e71d1 Add jupyter-format-time-low-res 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
7d3de9e6b2 Implement jupyter-comm-(start|stop) methods for a jupyter-server-kernel-manager
These are wrappers around calls to the same method for the `comm` slot of a
`jupyter-server-kernel-manager`.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
bed724f2fe jupyter-server: Symmetrize (dis)connect channel events 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
46e4e6c40e jupyter-start-kernel (jupyter-server-kernel-manager): Also start the comm 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
900016d398 Include session ID when connecting websockets 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
df7071eac9 Add jupyter-gc-servers 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
1658cd0454 jupyter-kill-kernel (jupyter-server-kernel): Do nothing
There is no need to forcibly kill a kernel since the notebook handles this
already.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
de320f83d2 jupyter-current-server: Also consider a remote default-directory 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
4a87d35f76 Jupyter notebook contents API integration with TRAMP 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
e8edd4d5cc Promote time encoding/decoding functions to public
Also use `parse-iso8601-time-string` when decoding
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
67831c08fa Support Jupyter kernel servers
* jupyter-client.el (jupyter-initialize-connection): Elevate NOTE to FIXME.
(jupyter-kernel-info): Extend timeout.

* jupyter-kernel-manager.el (jupyter-shutdown-kernel):
(jupyter-interrupt-kernel): Allow any number of arguments.

* jupyter-kernelspec.el (jupyter-find-kernelspecs): Optionally allow specs.

* jupyter-messages.el (jupyter-encode-raw-message): New function.

* jupyter-rest-api.el (jupyter-api-auth-headers): New function.

* jupyter-server-ioloop.el: New file.

* jupyter-server.el: New file.

* test/jupyter-test.el (jupyter-server):
(jupyter-server-kernel-manager):
(jupyter-server-start-new-kernel): New tests.
2019-07-24 16:59:04 -05:00