Commit graph

48 commits

Author SHA1 Message Date
Nathaniel Nicandro
eebeef1293 Don't attempt to byte-compile a symbol whose function value is a subr
`(byte-compile #'cons)` will return `t` which is not a function.
Passing in the `subr` to `byte-compile` will just return the `subr` so
everything works out OK.  This is an attempt at fixing issues like
nnicandro/emacs-zmq#32.
2023-02-13 20:15:56 -06:00
Nathaniel Nicandro
16cbda7916 Fix incorrect number of arguments 2023-02-04 16:58:12 -06:00
Nathaniel Nicandro
14899664b6 Don't use zmq-recv-decoded and zmq-send-encoded
These functions no longer exist in newer versions of `emacs-zmq`.
Closes #433.
2023-02-03 20:12:32 -06:00
Nathaniel Nicandro
1fa6ed4e5f Remove the jupyter-ioloop-handler method
Replace it with a handler function passed to `jupyter-ioloop-start`.

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

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

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

* jupyter-ioloop.el: Do it. Update comments and doc.
(jupyter-ioloop--delete-process): Remove. It was used to perform
cleanup when the object used for dispatching to a handler method was
garbage collected. Since we no longer rely on having an object for
dispatching, preferring just a function to call, its not needed.

(jupyter-ioloop--make-filter): Fall back to calling handler function
instead of `jupyter-ioloop-handler`. Only handle ioloop start/stop
events internally. This means we can remove the check for those in
`jupyter-ioloop-comm`.

* test/jupyter-test.el: Update tests to take into account above
  changes.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
403c70c83c Bump version 2020-04-07 15:13:51 -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
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
96aaedf5b5 jupyter-ioloop--dump-message: Don't abbreviate printed lists 2019-08-13 19:50:53 -05:00
Nathaniel Nicandro
6650dd3588 Bump version 2019-07-24 16:03:22 -05:00
Nathaniel Nicandro
1e10e161b7 jupyter-ioloop-timeout: Add documentation 2019-07-24 14:40:55 -05:00
Nathaniel Nicandro
4f944d311c jupyter-send (jupyter-ioloop): Fix placement of setq 2019-07-08 17:27:29 -05:00
Nathaniel Nicandro
4daa09bb15 jupyter-send (jupyter-ioloop): Don't create a temporary buffer on every send 2019-07-08 16:56:36 -05:00
Nathaniel Nicandro
02a0b470d9 jupyter-ioloop: Fix for subprocess stdin buffering issue 2019-07-08 16:56:28 -05:00
Nathaniel Nicandro
8fc5f0bbee Make jupyter-channel-ioloop independent of zmq
This change localizes all `zmq` related functionality to `jupyter-ioloop` and
`jupyter-zmq-*` files.

* jupyter-channel-ioloop-comm.el: Add better commentary.
(jupyter-base): Require.
(jupyter-channel-ioloop-comm): Add `ioloop-class` slot
(initialize-instance [jupyter-channel-ioloop-comm]): Use it.

* jupyter-channel-ioloop.el (jupyter-base, jupyter-zmq-channel): Un-require.
(jupyter-ioloop-session, jupyter-ioloop-channels):
Rename to `jupyter-channel-ioloop-session` `jupyter-channel-ioloop-channels` and
update all callers.
(jupyter-channel-ioloop): Make into an abstract class.
(initialize-instance [jupyter-channel-ioloop]): Re-add
`jupyter-channel-ioloop-add-send-event`. Don't add to
`jupyter-ioloop-post-hook`.
(jupyter-channel-ioloop-recv-messages): Remove.
(jupyter-channel-ioloop--set-session, jupyter-ioloop-start)
(jupyter-channel-ioloop-add-send-event): Doc changes.
(jupyter-channel-ioloop-add-start-channel-event)
(jupyter-channel-ioloop-add-stop-channel-event):
Don't add/remove from the `jupyter-ioloop-poller`.
Now expected to be handled in the `jupyter-channel` subclass.
Update documentation. In addition, for the start-channel event,
do not attempt to add a channel if one doesn't already exist.

* jupyter-ioloop.el
(jupyter-ioloop-add-teardown):
Remove mention of `jupyter-channel-ioloop` behavior.
(jupyter-ioloop-add-arg-type): Update example variable.
(jupyter-ioloop-environment-p): New function.

* jupyter-kernel-manager.el (jupyter-channel): Require.
(jupyter-make-client): Require and use `jupyter-zmq-channel-ioloop`.
(jupyter-start-channels): Use `make-instance`.
(jupyter-interrupt-kernel): Remove `condition-case`. Not needed since
preventing socket blocking is now handled by `jupyter-recv`.

* jupyter-repl.el
(jupyter-connect-repl): Require and use `jupyter-zmq-channel-ioloop`.

* jupyter-zmq-channel-ioloop.el: New file.

* jupyter-zmq-channel.el (jupyter-ioloop-poller-remove)
(jupyter-ioloop-poller-add): New declares.
(jupyter-start-channel):
Add to `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`.
(jupyter-stop-channel):
Only disconnect the socket from its endpoint instead of closing it, leave that
up to garbage collection.
Remove from `jupyter-ioloop-poller` when in `jupyter-ioloop-environment-p`.
(jupyter-recv): Handle non-blocking.

* test/jupyter-test.el
(jupyter-zmq-channel): Use non-blocking `zmq-send` since socket is no longer
closed when calling `jupyter-stop-channel`.
(jupyter-ioloop-test-eval-ioloop): Rename to `jupyter-test-ioloop-eval-event`,
update all callers, and move to `test/test-helper.el`.
(jupyter-channel-ioloop-send-event, jupyter-channel-ioloop-stop-channel-event)
(jupyter-channel-ioloop-start-channel-event): Fix tests for variable name
changes. Use `jupyter-test-channel-ioloop`. Update `jupyter-ioloop-poller`,
addition/removal from poller is now done in the `jupyter-channel` subclass by
checking `jupyter-ioloop-environment-p`.

* test/test-helper.el (jupyter-zmq-channel-ioloop): Require.
(initialize-instance [jupyter-echo-client]): Use it.
(jupyter-test-channel-ioloop): New macro.
(jupyter-test-ioloop-eval-event): New function.
2019-06-30 12:22:26 -05:00
Nathaniel Nicandro
dca8dac257 Mention behavior of jupyter-ioloop-poller-(add|remove) in doc strings 2019-06-30 12:22:16 -05:00
Nathaniel Nicandro
b40b7de837 Do not depend strongly on zmq
Having the `jupyter-comm-layer` abstraction means we do not need to do so.

* jupyter-base.el (zmq): Un-require.
(jupyter-socket-types): Move to `jupyter-channels.el`.
(jupyter-session): Don't mention zmq in doc string.
(jupyter-available-local-ports, jupyter-make-ssh-tunnel): New functions.
(jupyter-tunnel-connection): Use them.

* jupyter-channel-ioloop-comm.el: New file.

* jupyter-channels.el (jupyter-messages): Un-require.
(jupyter-comm-layer, zmq): New requires.
(jupyter-socket-types): Moved from `jupyter-base.el`.
(jupyter-send, jupyter-recv):
Implementations for `jupyter-session` moved from `jupyter-messages.el`.
(jupyter-sync-channel-comm): `jupyter-comm-layer` implementation for
`jupyter-sync-channel` objects moved from `jupyter-comm-layer.el`.

* jupyter-comm-layer.el (jupyter-channel-ioloop): Un-require.
(jupyter-sync-channel-comm): Move implementation to `jupyter-channels.el`.
(jupyter-ioloop-comm): Move implementation to new file `jupyter-ioloop-comm.el`.
(jupyter-channel-ioloop-comm):
Move implementation to new file `jupyter-channel-ioloop-comm.el`.

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

* jupyter-ioloop.el (zmq): Require.

* jupyter-kernel-manager.el
(jupyter-make-client): Ensure `jupyter-channel-ioloop-comm` is required.

* jupyter-messages.el (jupyter-send)
(jupyter-recv): Moved to `jupyter-channels.el`

* jupyter-repl.el
(jupyter-connect-repl): Ensure `jupyter-channel-ioloop-comm` is required.

* test/jupyter-test.el (jupyter-available-local-ports): New test.

* test/test-helper.el (jupyter-channel-ioloop-comm): New require.
2019-06-29 10:29:55 -05:00
Nathaniel Nicandro
d7b8719126 jupyter-ioloop--make-filter: Handle important events always
Previously events like start or quit would only get handled if
`jupyter-ioloop-handler` was called, but those events need to get handled
regardless.
2019-06-22 22:01:00 -05:00
Nathaniel Nicandro
3580228b6b jupyter-ioloop-post-hook: Adhere to the documentation 2019-06-22 21:55:00 -05:00
Nathaniel Nicandro
5ea32a70f0 Change License to GPL3 2019-05-31 09:44:39 -05:00
Nathaniel Nicandro
361cee8f4a jupyter-ioloop--function: Avoid harmless message when debugging 2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
ab79985580 Fix initialize-instance method signature 2019-05-09 10:56:02 -05:00
Nathaniel Nicandro
112769e0c6
Bump version 2019-05-04 03:31:50 -05:00
Nathaniel Nicandro
f890238345 Handle Windows systems when using jupyter-ioloop
On Windows systems we can't poll the STDIN of the created subprocess when using
`jupyter-ioloop` since Windows does not allow polling file handles. To get
around this we create a (PUSH, PULL) socket pair that the parent Emacs process
uses to communicate with its subprocess. See dzop/emacs-zmq#10 and thanks to
@fleimgruber for investigating this issue.
2019-05-04 02:33:11 -05:00
Nathaniel Nicandro
1ff22c1827
jupyter-ioloop-last-event: Return nil when there is no process 2019-05-04 01:27:54 -05:00
Nathaniel Nicandro
67d7bce1e3
jupyter-ioloop-add-callback: Use jupyter-send 2019-05-04 01:27:54 -05:00
Nathaniel Nicandro
6606fc65e5 Move all debug printing into jupyter-client.el 2019-04-11 20:13:44 -05:00
Nathaniel Nicandro
a6e41c5b42
jupyter-ioloop--function: Don't set jupyter-ioloop-timeout to 0
This was too arbitrary. Leave the setting of `jupyter-ioloop-timeout` to users.
2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
29bc5f6c2d
jupyter-ioloop--function: Byte compile after setup
This accounts for changes in
dzop/emacs-zmq@b35b0b5fcd, in particular byte
compiling the form passed to `zmq-start-process` too early causes issues with
macro expansion if there are library dependencies.
2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
2cfdd6ecfb
Add jupyter-weak-ref(-resolve)? 2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
83af335166
Bump version 2019-03-14 09:29:11 -05:00
Nathaniel Nicandro
9c94cee8a2
jupyter-ioloop-handler: Simplify debug printing 2019-03-07 22:44:52 -06:00
Nathaniel Nicandro
d4969cbfcc CHANGELOG.org: Add function to change version numbers 2019-02-14 23:05:00 -06:00
Nathaniel Nicandro
63717b9e39
Bump version 2019-02-12 09:17:06 -06:00
Nathaniel Nicandro
37b80ddbcd
Fix some typos and formatting issues 2019-01-12 20:57:22 -06:00
Nathaniel Nicandro
081f329da1 v0.6.0 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
740ed190cc Document jupyter-ioloop 2018-11-16 00:27:47 -06:00
Nathaniel Nicandro
823ea8adde Fix checkdoc warnings 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
5e9a4d2e7a jupyter-ioloop-handler: Escape format characters when debugging messages 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
3372bb9211 Simplify ioloop process handling
* jupyter-ioloop.el (jupyter-ioloop): Inherit from jupyter-finalized-object.
Remove object slot.
(initialize-instance): New method addition.
(jupyter-ioloop--filter, jupyter-ioloop--sentinel): Remove.
(jupyter-ioloop-start): Pass closure as a filter function to the process.
(jupyter-ioloop-stop): No need to nil out process slot.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
2ef5f0acb3 Add jupyter-ioloop-alive-p
* jupyter-ioloop.el (jupyter-ioloop-alive-p): Do it.
(jupyter-ioloop-handler): Remember if a process was started or if it has
stopped already.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
965b405312 Small refactoring
* jupyter-ioloop.el (jupyter-ioloop-printer): Add documentation, move it.
(jupyter-ioloop-start): Give a default implementation.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
bdb12a7dff Convert the ioloop implementation into a class
This makes more sense since then we can initialize the `jupyter-channel-ioloop`
subclass in `initialize-instance`.
2018-11-15 23:03:21 -06:00
Nathaniel Nicandro
0c8edf9928 Update jupyter-ioloop-wait-until
It now takes the same arguments as `jupyter-wait-until` and behaves in much the
same way.

* jupyter-ioloop.el (jupyter-ioloop-wait-until): Add CB and PROGRESS-MSG
arguments. Use `jupyter-with-timeout`. Behave in the same way as
`jupyter-wait-until`, but for EVENT. Update all callers.
(jupyter-ioloop-last-event): New function.
(jupyter-ioloop-handler):
Add :before method that saves the last event.
Remove unnecessary methods.
Don't raise an error on built-in ioloop events in fall-back method.
2018-11-13 17:47:55 -06:00
Nathaniel Nicandro
82e0e2cda9 jupyter-ioloop-printer 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