Commit graph

975 commits

Author SHA1 Message Date
Nathaniel Nicandro
3c05232a90 Add Cask file 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
75abea913d Update tests 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
a4e7fbf7ba Use defsubst for some message functions
* jupyter-messages.el (jupyter-message-id, jupyter-message-parent-id):
(jupyter-message-type, jupyter-message-session, jupyter-message-parent-type):
(jupyter-message-get, jupyter-message-data, jupyter-message-status-idle-p): Do it.
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
0052d9b30f jupyter-insert: Only fontify the docstring region for Python inspect requests
* jupyter-python.el (jupyter-insert): Do it.
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
1fa522a4cd Simplify heartbeat channel logic 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
53b00de7c8 Remove subprocess lock tests
This did not prove useful since after carefully reading the documentation and
with my own tests, the lock files remained most of the time after Emacs
crashes.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
75bba80404 Remove old uses of jupyter-finalize
This was an old method before `make-finalizer` started to be used internally.
2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
7be19f7528 Update tests to take into account changes in jupyter-ioloop 2018-11-15 23:04:27 -06:00
Nathaniel Nicandro
66c2ee40cb jupyter-insert: Allow for passing in message property lists
* jupyter-mime.el (jupyter-insert): Do it.
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
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
325bd09e1d Add section headers 2018-11-15 23:03:21 -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
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
3d45427eee jupyter-start-kernel: Use with-temp-file 2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
9309e6c477 jupyter-start-channels: Simplify kernel manager method
* jupyter-kernel-manager: (jupyter-start-channels): Do it.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
8f0acca6df Move output buffer related functions to jupyter-base.el
* jupyter-repl.el (jupyter-output-buffer-marker, jupyter-output-buffer-request-id):
(jupyter--reset-output-buffer-p, jupyter-with-output-buffer): Do it.
(jupyter-repl-get-special-buffer): Do it and rename to jupyter-get-buffer-create.

* jupyter-client.el: See above.
2018-11-13 18:17:44 -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
10d1e18ffa jupyter-hb--send-ping: Refactor for readability 2018-11-13 17:47:55 -06:00
Nathaniel Nicandro
ff2feaab69 jupyter-shutdown-kernel: Report progress when shutting down 2018-11-13 17:47:55 -06:00
Nathaniel Nicandro
9aff88331a jupyter-start-new-kernel: Simplify
Remove the need to wrap in a progn. Un-pause heartbeat after waiting so that we
know for sure the kernel can be communicated with.
2018-11-13 17:47:55 -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
84695e98d0 jupyter-start-channel: Don't un-pause the heartbeat channel
Starting a channel means that it is open for communication. It is already
un-paused by jupyter-start-new-kernel, so it is ok to make this change here.
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
d083ff5746 jupyter-hb-unpause: Simplify 2018-11-13 17:46:19 -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
19868e3ec9 Use jupyter-channel-alive-p instead of testing socket directly
* jupyter-channels (jupyter-hb-pause, jupyter-channel--reset-socket): Do it.
(jupyter-start-channel): Always reset the socket.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
bd5d4d3eea jupyter-repl-append-output: Revert usage of with-silent-modifications
Font locking is actually still needed when appending output. It's not enough to
temporarily disable it and insert since the text we inserted doesn't get font
locked properly. This is most notable when inserting markdown text.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
4dc229935b jupyter-messages.el: Update commentary 2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
1371947785 jupyter-message-type-as-keyword: Simplify loop
* jupyter-messages.el (jupyter-message-type-as-keyword): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
d3dc23d2b1 jupyter--decode: Simplify post processing of :msg_type key
* jupyter-messages.el (jupyter--decode): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
0fb39492e3 jupyter-encode-message: Refactor
* jupyter-messages.el (jupyter-encode-message): Do it.
(jupyter--message-header): Require MSG-ID argument. Given by
`jupyter-encode-message'.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
344e7b72ce jupyter--split-identities: Simplify loop
* jupyter-messages.el (jupyter--split-identities): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
d124ea2d64 jupyter-decode-message: Remove unnecessary quoting
* jupyter-messages.el (jupyter-decode-message): Do it.
2018-11-13 17:46:07 -06:00