Commit graph

283 commits

Author SHA1 Message Date
Nathaniel Nicandro
fca89359fd Rename jupyter-repl-display-traceback to jupyter-display-traceback
Also move the function to jupyter-client.el from jupyter-repl.el

* jupyter-repl.el (jupyter-repl-display-traceback): Do it.

* jupyter-client.el (jupyter-display-traceback): Do it.
2018-11-21 12:35:34 -06:00
Nathaniel Nicandro
872c5cde79 Ensure the execution state is always set regardless of jupyter-inhibit-handlers
`jupyter-iopub-message-hook` is called in a channel's `jupyter-handle-message`
method, but setting the execution state should be independent of the value of
`jupyter-inhibit-handlers. So move setting the execution state into the
client's `jupyter-handle-message` method.
2018-11-21 12:35:30 -06:00
Nathaniel Nicandro
6a1da44904 Move evaluation functions from jupyter-repl.el to jupyter-client.el
These functions are general and not only useful for REPLs.
2018-11-19 08:50:32 -06:00
Nathaniel Nicandro
50ac28910a Remove usage of deprecated when-let
This was deprecated in Emacs 26.1
2018-11-16 04:59:09 -06:00
Nathaniel Nicandro
081f329da1 v0.6.0 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
42cc3d3853 Do not use the make- prefix for struct constructors 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
823ea8adde Fix checkdoc warnings 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
5a7c083169 More reliably capture the startup message
It still sometimes isn't caught but it is more reliable. This mainly affects
testing.

* jupyter-client.el (jupyter-start-channels): Add a small delay after starting
  channels.

* jupyter-kernel-manager.el (jupyter-start-kernel): Remove superfluous delay.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
b45321b181 Add jupyter--run-handler-p
Split from `jupyter--run-handler-maybe`. Makes for easier testing of the
handler logic.

* jupyter-client.el (jupyter--run-handler-maybe): Use it.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
fbdcac6c37 Silence byte compiler 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
45a62b6b81 jupyter-inspect: Insert the message property list 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
b44c8871d4 Cleanup a clients ioloop process through finalizers
* jupyter-client.el (initialize-instance): Stop channels in finalizer.

* jupyter-ioloop.el (jupyter-ioloop--make-filter): New function.
(jupyter-ioloop-start): Make a weak reference OBJECT.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
9d0976e1ed jupyter-eval: Verify that a client is available 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
53ff8635fc Split ioloop initialization into :before and :after methods 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
c0e47165a9 Add instance tracker class
This is needed as opposed to eieio-instance-tracker so that we can create weak
references to objects. We don't want to have to manually delete an instance.

* jupyter-base.el (jupyter-instance-tracker): Do it.
(jupyter-all-objects): New function.

* jupyter-client.el (jupyter--clients): New variable.
(jupyter-kernel-client): Inherit from new class.
(jupyter-clients): Use jupyter-all-objects.

* jupyter-kernel-manager.el (jupyter-kernel-managers): New function.
2018-11-15 23:04:25 -06:00
Nathaniel Nicandro
134f84a59c Add object finalizer class
* jupyter-base.el (jupyter-finalized-object): New class.
(initialize-instance): New method addition.
(jupyter-add-finalizer): New method.

* jupyter-client.el (jupyter-kernel-client):
Inherit from jupyter-finalize-object.
(initialize-instance): Cleanup private buffer when client loses scope.
(jupyter-finalize): Remove.

* jupyter-kernel-manager.el (jupyter-kernel-manager):
Inherit from jupyter-finalized-instance.
(jupyter-kernl-manager--cleanup): New function.
(jupyter-finalize, jupyter-kill-kernel-managers): Remove. Update all callers.
(jupyter--kernel-sentinel): Remove MANAGER argument. Update all callers.
(jupyter--start-kernel): Remove MANAGER argument. Update all callers.
(jupyter-start-kernel): Add finalizer to kernel process to cleanup conn-file.

* jupyter-repl.el (jupyter-repl-kill-buffer-query-function):
Remove calls to jupyter-finalize.
2018-11-15 23:02:41 -06:00
Nathaniel Nicandro
ba13ef2419 Move inspection related functions to jupyter-client.el
* jupyter-repl.el (jupyter-inspect, jupyter-inspect-at-point): Do it.

* jupyter-client.el: See above.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
a82ae13438 Add jupyter-with-timeout macro
* jupyter-base.el (jupyter-default-timeout)
(jupyter-long-timeout): Moved from jupyter-client.el
(jupyter-with-timeout): Do it.

* jupyter-client.el (jupyter-wait-until): Use it.

* jupyter-kernel-manager.el (jupyter-shutdown-kernel)
(jupyter-interrupt-kernel, jupyter-start-new-kernel):
(jupyter-start-kernel): Use it.

use timeout
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
bbf1d19af3 jupyter-drop-request: Decouple debugging statements from primary method
* jupyter-client.el (jupyter-drop-request):
New :before method that prints debugging statements.
Remove debugging statements from primary method.
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
82e0e2cda9 jupyter-ioloop-printer 2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
f18c3dfcc6 jupyter-finalize: Kill process if necessary
If an error happens early, the process won't get killed before we kill the
buffer.

* jupyter-client.el (jupyter-finalize): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
af32a3352f Promote the execution-state to be a slot of jupyter-kernel-client
* jupyter-client.el (jupyter-kernel-client): Do it.
(jupyter-run-hook-with-args-until-success): Pass client as first argument to
hooks.
(jupyter-execution-state): New convenience function.
(jupyter--set-execution-state): New helper function. Add as global IOPUB
message hook to set the execution-state slot.

* jupyter-repl.el (jupyter-repl-client): Remove execution-state slot.
(jupyter-handle-status): Don't set the execution-state slot.
(jupyter-repl-ret, jupyter-repl-interaction-mode-line): Use
jupyter-execution-state.
(jupyter-repl-initialize-hooks): Take into account changes to message hooks.

* jupyter-kernel-manager (jupyter-start-new-kernel): Update callback.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
9f2c88d252 Refactor callback handling
* jupyter-client.el (jupyter--run-callbacks): Simplify.
(jupyter--set-callback): New macro.
(jupyter--add-callback): Use new macro.
(jupyter-add-callback): Make more readable.

callbacks
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
0221a9571d Light refactoring
* jupyter-client.el (jupyter-wait-until): Let `with-timeout` handle errors.
(jupyter--run-handler-maybe, jupyter-add-callback):
(jupyter-kernel-info): Readability.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
8a6aa9baf5 Refactor client channel methods
* jupyter-client.el (jupyter-initialize-connection):
Stop channels if any are running.
Fix wrong usage of collect when constructing channel plist.
(jupyter-ioloop-handler): Remove usage of `with-slots` when a slot is only
accessed once.
(jupyter-start-channel, jupyter-stop-channel): Split waiting for channel to
start/stop into an :after method. Verify CHANNEL argument is valid.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
6c16d184b3 jupyter-handle-message: Let bind `jupyter-current-client' when handling messages
This is necessary to allow for the `jupyter-lang' method specializer to work in
contexts other than the REPL buffer, such as in an `org-mode` buffer when
handling `jupyter-org-request' objects.

* jupyter-client.el (jupyter-handle-message): (CLIENT ...) Do it.

* jupyter-org-client.el (jupyter-org-add-result):
Don't let bind `jupyter-current-client`.
Remove CLIENT argument. Update all callers.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
12085afa96 Add jupyter-channel-ioloop
This commit extracts out the IOLoop functions which are used to define an
IOLoop that send and receive messages on Jupyter channels into is own object.

* jupyter-channel-ioloop.el: New file.
(jupyter-channel-ioloop): A sub-type of `jupyter-ioloop` that sets up an IOLoop
to send/receive messages on Jupyter channels.
(jupyter-ioloop-channels):
(jupyter-ioloop-session): New variables used in `jupyter-channel-ioloop`
events.
(jupyter-ioloop-add-arg-type jupyter-channel): Moved from `jupyter-client.el`.
(jupyter-channel-ioloop-add-session): New function.
(jupyter-ioloop-start): Setup ioloop to communicate with Jupyter channels.
(jupyter-channel-ioloop-recv-messages):
(jupyter-channel-ioloop-add-start-channel-event):
(jupyter-channel-ioloop-add-stop-channel-event):
(jupyter-channel-ioloop-add-send-event): Moved from `jupyter-client.el`,
replaced jupyter-ioloop prefix with jupyter-channel-ioloop.

* jupyter-client.el: Require `jupyter-channel-ioloop` instead of
`jupyter-ioloop`.
(jupyter-kernel-client): Change type of `ioloop` to `jupyter-channel-ioloop`.
(jupyter-client--ioloop-setup-form): Remove.
(jupyter-ioloop-add-arg-type jupyter-channel): Move to
`jupyter-channel-ioloop.el`.
(jupyter-ioloop-add-start-channel-event):
(jupyter-ioloop-add-stop-channel-event):
(jupyter-ioloop-add-send-event): Move to `jupyter-channel-ioloop.el`, replace
jupyter-ioloop prefix with jupyter-channel-ioloop.
(jupyter-ioloop-start): Remove.
(jupyter-start-channels): Ensure `jupyter-ioloop-start` method of
`jupyter-channel-ioloop` is called. Set ioloop process buffer to `-buffer` slot
of client.

* jupyter-ioloop.el (jupyter-ioloop-start): Remove :before method.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
6942a20e8a Add new jupyter-ioloop implementation
A `jupyter-kernel-client' defers most of its message sending, receiving, and
message processing to a subprocess which sends its messages to the kernel
through zmq sockets and polls for any messages to received from the kernel.
This commit generalizes this by introducing a new `jupyter-ioloop` type which
encapsulates the subprocess and the code necessary to build up the function
that does the work of communicating with a kernel in the subprocess
environment.

* jupyter-channels.el: Remove `jupyter-async-channel`

* jupyter-ioloop.el: New file.
(jupyter-ioloop-poller):
(jupyter-ioloop-nsockets):
(jupyter-ioloop-pre-hook):
(jupyter-ioloop-post-hook):
(jupyter-ioloop--argument-types): New variables.
(jupyter-ioloop): New function to create `jupyter-ioloop` objects.
(jupyter-ioloop-add-setup):
(jupyter-ioloop-add-teardown):
(jupyter-ioloop-add-arg-type):
(jupyter-ioloop-add-event): New macros.
(jupyter-ioloop-handler):
(jupyter-ioloop-add-callback):
(jupyter-ioloop-start):
(jupyter-ioloop-stop): New methods.
(jupyter-send): Method addition for `jupyter-ioloop` objects.
(jupyter-ioloop-wait-until): Moved function from `jupyter-client.el`, changed
argument order.
(jupyter-ioloop--replace-args):
(jupyter-ioloop--event-dispatcher):
(jupyter-ioloop--function):
(jupyter-ioloop--filter):
(jupyter-ioloop--sentinel): Helper functions.

* jupyter-client.el: Add `jupyter-ioloop` require.
Remove `jupyter-shell-channel`, `jupyter-iopub-channel`,
`jupyter-stdin-channel` classes.
(jupyter-kernel-client): Change type of `ioloop` slot to `jupyter-ioloop`,
remove `shell-channel`, iopub-channel`, `stdin-channel`, and `hb-channel`
slots. Add `channels` slot.
(jupyter-initialize-connection): Replace channel initialization with
initialization of new `channels` slot.
(jupyter-send): Add better assertion. Call an ioloop's `jupyter-send` method.
Expect a Jupyter channel keyword as the `channel` argument.
(jupyter--ioloop-do-command):
(jupyter--ioloop-with-lock-file):
(jupyter--ioloop-unlock):
(jupyter--ioloop-lock):
(jupyter--ioloop):
(jupyter--ioloop-sentinel):
(jupyter--get-channel):
(jupyter--ioloop-filter):
(jupyter--start-ioloop): Remove functions/macros.
(jupyter-ioloop-wait-until): Move to `jupyter-ioloop.el`
(jupyter-hb-pause):
(jupyter-hb-unpause):
(jupyter-hb-beating-p): Use `channels` slot.
(jupyter-client--ioloop-setup-form): New constant.
(jupyter-ioloop-add-arg-type): New jupyter-channel argument type.
(jupyter-ioloop-add-start-channel-event):
(jupyter-ioloop-add-stop-channel-event):
(jupyter-ioloop-add-send-event): New `jupyter-ioloop` event types for clients.
(jupyter-ioloop-start):
(jupyter-ioloop-handler): Method additions specializing to
`jupyter-kernel-client`s.
(jupyter-start-channel):
(jupyter-stop-channel):
(jupyter-channel-alive-p): Method additions for a client utilizing `channels` slot.
(jupyter-start-channels):
(jupyter-stop-channels):
(jupyter-channels-running-p): Use new `jupyter-ioloop` interface and channel
methods.
(jupyter-handle-message): (`jupyter-kernel-client` method) Add new `msg`
argument. Remove call to `jupyter-get-message`.
(jupyter-handle-message): (All channel methods) Replace
`jupyter-stdin-channel`, `jupyter-iopub-channel`, and `jupyter-shell-channel`
with `(eql :stdin)`, `(eql :iopub)`, and `(eql :shell)`
(jupyter-handle-input-request):
(jupyter-send-execute-request):
(jupyter-send-inspect-request):
(jupyter-send-complete-request):
(jupyter-send-history-request):
(jupyter-send-is-complete-request):
(jupyter-send-comm-info-request):
(jupyter-send-comm-open):
(jupyter-send-comm-msg):
(jupyter-send-comm-close):
(jupyter-sned-kernel-info-request):
(jupyter-send-shutdown-request): Remove uses of `shell-channel` and
`stdin-channel` slot. Pass in expected channel keyword as the `channel`
argument in the call to `jupyter-send`
2018-11-13 17:46:03 -06:00
Nathaniel Nicandro
005664a381 Decouple debugging statements from implementation
* jupyter-client.el (jupyter-send): Add new :before method that prints
debugging statements, remove debugging statements from primary method.
2018-11-08 21:33:26 -06:00
Nathaniel Nicandro
348541dfe7 Update documentation and commentary 2018-11-08 21:30:32 -06:00
Nathaniel Nicandro
5b65eb4f24 Move jupyter--debug to jupyter-base.el from jupyter-client.el
This is so that other parts of Jupyter can use it to emit debug statements.
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
2642450e82 jupyter-client.el: Add jupyter-verify-inhibited-handlers
* jupyter-client.el: Add the new function
(jupyter-send): Use it
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
2ae8c6a7c1 Associate pending requests with a client
Previously pending requests were associated with the ioloop process itself, but
pending requests are a particular feature of the client and used only for a
client's purpose.
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
22796ad4cd jupyter-client.el: Add jupyter-clients
* jupyter-client.el: Add the function

* jupyter-repl.el (jupyter-repl-available-repl-buffers): Use it. Ensure REPL
buffers are still live.
2018-11-08 21:15:22 -06:00
Nathaniel Nicandro
0a1ffa66a0 jupyter--ioloop: Complain if ZMQ does not have draft API 2018-11-05 00:00:11 -06:00
Nathaniel Nicandro
05bbe0414d Rename jupyter-startup-timeout to jupyter-long-timeout 2018-11-05 00:00:08 -06:00
Nathaniel Nicandro
57f262c2e3 Implement option to show a progress reporting message in jupyter-wait-until* functions 2018-11-01 19:20:25 -05:00
Nathaniel Nicandro
2f3f910598 Replace deprecated destructor method with jupyter-finalizer 2018-10-25 23:59:47 -05:00
Nathaniel Nicandro
4c710ed235 jupyter-load-language-support: Fix assertion 2018-10-25 23:59:47 -05:00
Nathaniel Nicandro
8896e88476 Move language support definitions to their own files
* Define `jupyter-load-language-support` which takes a client and loads the
  language support definitions of the client's kernel language.

* Call `jupyter-load-language-support` when initializing a REPL buffer in
  `jupyter-repl-mode`. Note this also takes care of loading the kernel support
  for a `jupyter-org-client' since a REPL buffer is setup before evaluating any
  `org-mode` source code blocks.

* Move language specific methods to their own files named `jupyter-LANGUAGE.el`
2018-10-25 23:59:46 -05:00
Nathaniel Nicandro
ecd6a3098b Move jupyter-eval from jupyter-repl.el to jupyter-client.el 2018-10-25 23:17:28 -05:00
Nathaniel Nicandro
67a3f997bd Allow jupyter-inhibit-handlers to be inverted
That is, give a way to only run handlers for the message types in the list
instead of inhibiting them.
2018-10-25 23:17:28 -05:00
Nathaniel Nicandro
842c920760 Be more robust when checking the jupyter-lang method specializer 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
56477b2eae jupyter-client.el: Add jupyter-startup-timeout 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
288fb17ece Update comments 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
673747dc03 Add kill-emacs-hook functions for cleaning up clients and managers
If `kill-emacs` is called while the kernel process or client channel processes
are still alive, the process sentinels do not run and thus the cleanup of the
clients and managers does not happen. Thus we need to explicitly do this
cleanup when `kill-emacs` is called.
2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
c3690eb2ea Use accept-process-output 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
a7023078cc jupyter-code-context: Update documentation 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
7d824f4915 Add new :input-request message type
This replaces the behavior of the `:input-reply` message
type. A kernel sends an `:input-request` to the frontend
and the client sends an `:input-reply`.
2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
84fce2cd08 Silence byte compiler about undefined variables 2018-10-25 23:17:26 -05:00