Commit graph

178 commits

Author SHA1 Message Date
Nathaniel Nicandro
8d45a0242d Refactor notebook server related tests
* Start notebook on-demand during tests

* Do cleanup of sockets/processes when killing Emacs

  * This should work around intermittent core dumps on Travis due to epoll
    reconnect attempts.

* Simplify tests by creating and using setup/teardown macros
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
248dc34117 Define jupyter-api-request-(headers|method|data)
So as to make it easier to transition away from `url-retrieve` if necessary in
the future.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
e35981d147 jupyter-rest-api.el: Refactor login and authentication 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
a4aaa7d1db jupyter-api-request: Refactor
* jupyter-rest-api.el (jupyter-api-url): Remove.
(jupyter-api--request): Remove. Work moved into `jupyter-api-request`.
(jupyter-api--url-request): Rename to `jupyter-api-url-request`.
Update all callers.
(jupyter-api-add-websocket-headers)
(jupyter-api-construct-endpoint): New functions.
(jupyter-api-request): Use them.
Don't assume "api" prefixes endpoint, update all callers.
(jupyter-api-get-file-model)
(jupyter-api-get-kernel-ws):
Update to account for how query parameters are
passed in `jupyter-api-request`.

* jupyter-server-test: Update tests for changes to `jupyter-api-request`.
(jupyter-api-add-websocket-headers)
(jupyter-api-construct-endpoint): New tests.

squash! jupyter-api-request: Refactor
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
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
194df39643 Separate tests that use a notebook server from the main tests 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
1d282c948a Support kernel servers via org-mode source blocks 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
Nathaniel Nicandro
9df340bd0f Add REST API
* jupyter-rest-api.el: New file.

* test/jupyter-test.el (jupyter-rest-api):
(jupyter-api--copy-cookies, jupyter-api--password-login):
(jupyter-api-kernel-ws): New tests.

* test/test-helper.el (jupyter-test-rest-api): New macro.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
6650dd3588 Bump version 2019-07-24 16:03:22 -05:00
Nathaniel Nicandro
1b1a55ef3f Add jupyter-org-request-at-point
* jupyter-org-client.el (jupyter-org-request-at-point): Do it.
(org-babel-jupyter-src-block-session): New declare.

* ob-jupyter.el (org-babel-jupyter-session-clients): Add doc about keys.

* test/jupyter-test.el (jupyter-org-request-at-point): New test.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
259e8c5b86 Add jupyter-map-pending-requests
* jupyter-client.el (jupyter-map-pending-requests): Do it.

* test/jupyter-test.el (jupyter-map-pending-requests): New test.
2019-07-14 17:20:41 -05:00
Nathaniel Nicandro
d5492c54fb jupyter-runtime-directory: Use an existing directory
Set `default-directory` to one that should exist otherwise tests fail on
Appveyor.
2019-07-09 13:50:27 -05:00
Nathaniel Nicandro
7b78ca7013 jupyter-runtime-directory: Don't call shell commands at load time
* jupyter-env.el (jupyter-runtime-directory): Remove custom status.
New function definition.

* jupyter-kernel-manager.el (jupyter-write-connection-file):
Use new function.

* ob-jupyter.el (org-babel-jupyter--run-repl):
Remove setting of `jupyter-runtime-directory`.

* test/jupyter-test.el (jupyter-runtime-directory): New test.
2019-07-08 20:23:23 -05:00
Nathaniel Nicandro
02a0b470d9 jupyter-ioloop: Fix for subprocess stdin buffering issue 2019-07-08 16:56:28 -05:00
Nathaniel Nicandro
4c3168d53f Add jupyter-server-mode-set-client
This is an attempt at associating a REPL client with a buffer which was created
by emacsclient.
2019-06-30 12:36:41 -05:00
Nathaniel Nicandro
7bce62e2ae jupyter-create-connection-info -> jupyter-local-tcp-conn-info
Also use `jupyter-available-local-ports` to get ports for use.
2019-06-30 12:22:26 -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
58b715a4e8 Break up jupyter-channels.el to further decouple zmq
* jupyter-channel-ioloop.el (jupyter-zmq-channel): Require.
(jupyter-channel-ioloop-add-start-channel-event): `sync` -> `zmq`

* jupyter-comm-layer (jupyter-comm--channel): Moved from `jupyter-channels.el`.

* jupyter-kernel-manager.el: `sync` -> `zmq`

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

* jupyter-channels.el: Mostly renamed to jupyter-zmq-channel.el. The
`jupyter-channel` class was moved to `jupyter-channel.el`. All that remains are
those classes dependent on `zmq`.

* test/jupyter-test.el: `sync` -> `zmq` where appropriate.

Extract `jupyter-channel` class from `jupyter-zmq-channel.el` into its own file
2019-06-29 14:11:04 -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
9dd8e8d9ec Localize functions defined in jupyter-base.el to their call sites
Fixes #137

* jupyter-base.el (jupyter-kernelspec): Un-require.
(jupyter-command, jupyter-locate-python)
(jupyter-runtime-directory): Move to new file `jupyter-env.el`
(jupyter-include-other-output, jupyter-iopub-message-hook)
(jupyter-shell-message-hook)
(jupyter-stdin-message-hook): Move to `jupyter-client.el`
(jupyter-sha256, jupyter-hmac-sha256):
(jupytern-new-uuid): Move to `jupyter-messages.el`. Add declaration of
`jupyter-new-uuid` to account for its removal.
(jupyter-create-connection-info)
(jupyter-write-connection-file): Move to `jupyter-kernel-manager.el`
(jupyter-connect-endpoint, jupyter-connect-channel): Move to `jupyter-channels.el`

* jupyter-channels.el: Accept moved functions.

* jupyter-client.el: Accept moved variables.

* jupyter-kernel-manager.el: Accept moved functions.
(jupyter-env, jupyter-kernelspec): New requires.

* jupyter-kernelspec (jupyter-env): New require.
(jupyter-command): Remove declaration.
(jupyter-read-plist-from-string): New declaration.

* jupyter-messages.el: Accept moved functions.
(hmac-def, json): New requires.

* jupyter-org-extensions.el (jupyter-kernelspec): New require.

* jupyter-repl.el (jupyter-kernelspec): New require.

* jupyter-env.el: New file.

* ob-jupyter.el (jupyter-env, jupyter-kernelspec): New requires.

* test/jupyter-test.el (jupyter-env): New require.
2019-06-29 10:29:55 -05:00
Nathaniel Nicandro
030c3e2d0c Fix issues with undo in the REPL
Related to let binding `buffer-undo-list` improperly and making text read-only
when it shouldn't be.

Fixes #139

* jupyter-repl.el (jupyter-repl-with-single-undo)
(jupyter-repl-inhibit-undo-when): New macros.
(jupyter-repl-insert): Inhibit undo only when insertions are `read-only`
(jupyter-repl-insert-prompt): Don't make continuation prompts `read-only`
(jupyter-repl-replace-cell-code): Allow the argument to be a `buffer`. Use
`replace-buffer-contents` in this case. Avoids unnecessary undo information.
(jupyter-handle-is-complete-reply): Don't insert a `read-only` newline on
incomplete cell code.
(jupyter-repl-indent-line): Pass buffer to `jupyter-repl-replace-cell-code`
(jupyter-repl-insert-continuation-prompts): Don't inhibit undo

* test/jupyter-test.el (jupyter-repl-undo): Add more tests.
2019-06-29 10:29:55 -05:00
Nathaniel Nicandro
d0518be10c Add jupyter-line-count-greater-p
Speeds up the line count test associated with
`jupyter-eval-short-result-max-lines` by an order of magnitude for somewhat
large strings. The byte compiled versions are not that different.
2019-06-28 20:13:24 -05:00
Nathaniel Nicandro
74a6cfd541 Add test for jupyter-org-define-key 2019-06-13 10:46:19 -05:00
Nathaniel Nicandro
f3b94bab39 jupyter-start-kernel: Do nothing if kernel is already alive 2019-06-12 23:03:05 -05:00
Nathaniel Nicandro
23ad05fd64 jupyter-kill-kernel: Don't unbind the session slot of a kernel
Not really sure why this was done in the first place, but a kernel can be
forcibly killed and then asked to started up again, e.g. when restarting the
kernel.
2019-06-12 23:02:45 -05:00
Nathaniel Nicandro
e7d80cf399 Add test for #126 2019-06-12 21:10:26 -05:00
Nathaniel Nicandro
fda5f0b414 jupyter-org-font-lock-ansi-escapes: Fix regexp for fixed-width blocks 2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
9f15db7133 jupyter-org--append-to-example-block: Fix edge case
Fix the case when appending to a line without inserting a newline and adding
indentation.

Also add tests for `jupyter-org--append-to-example-block`
2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
66f806f478 Add test for jupyter-org-indent-inserted-region 2019-06-11 22:12:58 -05:00
Nathaniel Nicandro
878b323594 jupyter-org--append-to-fixed-width: Fix edge case 2019-06-11 20:17:06 -05:00
Nathaniel Nicandro
40ee1ac8b9 Add new customizable variable jupyter-repl-echo-eval-p
Closes #71
2019-06-08 13:47:13 -05:00
Nathaniel Nicandro
5ea32a70f0 Change License to GPL3 2019-05-31 09:44:39 -05:00
Nathaniel Nicandro
15dc560b14 jupyter-kernel-client: Remove pending-requests slot
There is no need for this slot and is a remnant of an older implementation. A
request is pending if it isn't idle, that is all that we need to know.
2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
0b49588096 jupyter-disconnect-client: Don't close comm by default
But do so for `jupyter-channel-ioloop-comm` as only a single client is meant to
be connected anyways.
2019-05-30 23:02:40 -05:00
Nathaniel Nicandro
24b6dbadac Add test for `jupyter-locate-python' 2019-05-20 18:17:51 -05:00
Nathaniel Nicandro
edf3097b04 org-babel-jupyter-override-src-block: Be more robust
Fixes #118
2019-05-20 14:52:26 -05:00
Nathaniel Nicandro
d7757d6de4 jupyter-repl-history--rotate: Handle an empty history 2019-05-19 19:34:07 -05:00
poppyschmo
b7b0162572 Add prev/next-matching REPL-input-history commands (#108) 2019-05-19 19:13:14 -05:00
Nathaniel Nicandro
111d105b51 Add jupyter-repl-history-add tests 2019-05-18 20:35:28 -05:00
Nathaniel Nicandro
107fa8042d Generalize jupyter-repl-history navigation functions 2019-05-18 20:35:28 -05:00
Nathaniel Nicandro
497ba05aa5 Skip jupyter-write-connect-file test on Windows 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
18f108f144 Use jupyter-ert-info in jupyter-repl-prompts test 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
d01dd82713 Once again increase timeouts during tests 2019-05-13 12:23:02 -05:00
Nathaniel Nicandro
b6d221c835 Be more diligent with processes used during testing 2019-05-13 12:21:59 -05:00
Nathaniel Nicandro
0f06ea1407 Add jupyter-kernel-lifetime test 2019-05-10 17:28:04 -05:00
Nathaniel Nicandro
f7b0ab2bc1 Rework jupyter-requests-pending-p test
Getting failures on Appveyor
2019-05-09 20:10:49 -05:00