Commit graph

164 commits

Author SHA1 Message Date
Nathaniel Nicandro
d08d4fce61 Rename internal functions for clarity
The following changes are made:

jupyter--run-handler-p -> jupyter--request-allows-handler-p
jupyter--handler-dispatch -> jupyter--run-handler

* jupyter-client.el: Do it.

* test/jupyter-test.el: Do it.
2020-04-12 08:35:14 -05:00
Nathaniel Nicandro
d14aa94c1f Fix jupyter-tunnel-connection
* .travis.yml: Add setup for testing SSH components.

* jupyter-base.el (jupyter-tunnel-connection): Document behavior more
  completely.  Refactor for readability. Ensure that the :ip field of the
  returned property list is set to 127.0.0.1 since it represents the connection
  info of the remote system but with local ports and should not have a remote
  IP address.

* test/jupyter-test.el (jupyter-tunnel-connection): New test.

* test/test-helper.el (jupyter-test-with-kernel): New macro.
2020-04-12 08:35:14 -05:00
Nathaniel Nicandro
587ed4e029 Keep uppercase characters in kernel language names
Converting to lowercase was done arbitrarily.  So that one could write
`(jupyter-lang wolfram-language)` instead of
`(jupyter-lang Wolfram-Language)`.

fixes #241

* CHANGELOG.org: Add note.

* README.org: Update relevant sections.

* jupyter-base.el (jupyter-canonicalize-language-string): Do it.

* ob-jupyter.el (org-babel-jupyter-aliases-from-kernelspecs):
2020-04-09 11:33:57 -05:00
Nathaniel Nicandro
403c70c83c Bump version 2020-04-07 15:13:51 -05:00
Nathaniel Nicandro
187cb479c2 Run test only on Emacs versions where a bug can be detected
The test for #219 isn't really testing the root cause of the bug, only a
symptom.  And it doesn't catch anything on Emacs < 27.

* test/jupyter-test.el (jupyter-repl-issue-219): Skip on Emacs < 27
2020-04-04 12:27:44 -05:00
Nathaniel Nicandro
3aa523ddf2 Add test for org-babel-jupyter-parse-session
* test/jupyter-test.el (org-babel-jupyter-parse-session): New test.
2020-04-04 08:52:15 -05:00
Nathaniel Nicandro
e9899c65cd Add test to catch a symptom of #219
* test/jupyter-test.el: Do it.
2020-04-04 08:39:48 -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
ae5dad9796 Split ZMQ dependent tests into test/jupyter-zmq-test.el
* test/jupyter-test.el: Move all zmq related tests (and code) to
  `test/jupyter-zmq-test.el`, add a `zmq` tag to the tests.

* test/test-helper.el (zmq, jupyter-zmq-channel-ioloop)
(jupyter-zmq-channel-ioloop-comm): Remove requires.
(jupyter-test-ioloop-eval-event, jupyter-test-channel-ioloop)
(initialize-instance) [jupyter-echo-client]: Remove uses of ZMQ by using
a `jupyter-mock-comm-layer` for the `kcomm` slot.
(jupyter-test-zmq-sockets): Move to `test/jupyter-zmq-test.el` along with all
related code.

* test/jupyter-zmq-test.el: Add tests moved from `test/jupyter-test.el` and all
  related code.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
0e202a02fa Ensure tests independent of ZMQ don't load it
* test/jupyter-server-test.el (jupyter-server): Replace test with one that
takes into account a `jupyter-server`s changed implementation.  Before, in
addition to talking to a kernel via the REST API, it managed a set of websocket
connections in a separate process.  Now, those websocket connections live in
the current Emacs process.

Ensure that `jupyter-test-with-notebook` uses a `jupyter-server` object by
let binding `jupyter-server-use-zmq` around its call.

(jupyter-server-ioloop-comm): New test with the same body as `jupyter-server`
had before this commit.  Skip the test unless `jupyter-server-use-zmq` is
non-nil.  Rename `jupyter-server-kernel-comm` to
`jupyter-server-ioloop-kernel-comm`.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
989e17c706 Remove unnecessary Version headers in test files
* test/jupyter-server-test.el: Do it.

* test/jupyter-test.el: Do it.

* test/jupyter-tramp-test.el: Do it.

* test/test-helper.el: Do it.
2020-03-29 03:08:53 -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
Nathaniel Nicandro
de7af256a9 Add missing half of test
* test/jupyter-test.el (org-babel-jupyter-inline-blocks): Do it.
2020-03-16 01:00:23 -05:00
Nathaniel Nicandro
2e0b74c588 Remove unnecessary uses of ZMQ
* test/test-helper.el (jupyter-test-conn-info-plist)
(jupyter-test-ensure-notebook-server): Do it.
2020-03-14 14:39:35 -05:00
Nathaniel Nicandro
308a4779d8 Handle variations in kernelspec language names more smoothly
* README.org: Add notes on behavior when a kernel's language name has spaces
  and uppercase characters.

* jupyter-base.el (jupyter-canonicalize-language-string): New function.

* jupyter-client.el (jupyter-kernel-info): Use it.

* jupyter-kernelspec.el (jupyter-available-kernelspecs): Use it.

* ob-jupyter.el (org-babel-jupyter-aliases-from-kernelspecs): Use it.

* test/jupyter-test.el (jupyter-canonicalize-language-string): New test.
2020-03-13 00:09:28 -05:00
Nathaniel Nicandro
226a14b232 Handle inline results similar to non-inline
fixes #204

* jupyter-org-client.el (jupyter-handle-execute-result): Call
`jupyter-org-result` on DATA when a code block is being evaluated inline.
2020-03-12 23:56:13 -05:00
Kevin Foley
8fdc3ae95b Preserve content in current cell when set to echo eval (#188)
* Preserve content in current cell when set to echo eval
2019-10-17 10:37:13 -05:00
Nathaniel Nicandro
dcf80d51db Remove jupyter-comm--channel
Since we are using keyword to represent channels on the client level, use a
plist of channels on the comm layer level instead of channel slots. This allows
us to remove `jupyter-comm-channel` and simplify the relevant code somewhat.
2019-09-17 11:42:21 -05:00
Nathaniel Nicandro
8cca30aea3 Fix ert--print-backtrace being undefined during tests on Emacs >= 27
This is a workaround until `ert-runner` supports Emacs 27
2019-09-15 16:33:24 -05:00
Nathaniel Nicandro
a149107e2a Don't depend on libjpeg being installed during tests 2019-09-15 16:29:57 -05:00
Nathaniel Nicandro
797ce5e0e6 jupyter-api-delete-cookies: Fix cookie expiration in test 2019-08-24 17:19:42 -05:00
Nathaniel Nicandro
4b97a72cdd Don't overwrite default url-cookie-file during tests
This is now easier to do since the value of `url-cookie-file` is propagated to
websocket subprocesses.
2019-08-11 14:22:28 -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
8c711dd3ce jupyter-repl-client-has-manager-p -> jupyter-client-has-manager-p
* jupyter-client.el (jupyter-client-has-manager-p): New function.

* jupyter-repl.el (jupyter-repl-client-has-manager-p): Remove function.
(jupyter-repl-connected-p, jupyter-repl-kill-buffer-query-function):
(jupyter-repl-restart-kernel, jupyter-repl-display-kernel-buffer):
Rename calls to `jupyter-repl-client-has-manager-p` to
`jupyter-client-has-manager-p`.

* test/jupyter-test.el (jupyter-repl-client-predicates):
Rename calls to `jupyter-repl-client-has-manager-p` to
`jupyter-client-has-manager-p`.
2019-08-08 21:55:22 -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
98adac6d31 Fix definitions of jupyter-tramp-file-name(-method)?-p
Fixes #155.

* jupyter-tramp.el (jupyter-tramp-file-name-method-p):
(jupyter-tramp-file-name-p): Adhere to documentation.

* test/jupyter-tramp-test.el (jupyter-tramp-file-name-p): Add test.
2019-07-27 12:22:47 -05:00
Nathaniel Nicandro
dd4b4e3a82 jupyter-server-mode-set-client: Increase timeout in test
There are often failures on Appveyor.
2019-07-25 10:23:23 -05:00
Nathaniel Nicandro
11b293438d jupyter-generate-request (jupyter-org-client): Consider babel-call org elements
Fixes #154.
2019-07-25 03:48:18 -05:00
Nathaniel Nicandro
66c794964c org-babel-jupyter-src-block-session: Consider babel-call org elements 2019-07-25 03:48:18 -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
239715919f Move server slot of jupyter-server-kernel-manager to the kernel object 2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
9fe99744fd jupyter-api-construct-endpoint: No need to encode components of endpoint
This is already handled by `url-encode-url` when creating the HTTP request.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
fa3f7c8b31 Handle encoding when making REST API requests
* jupyter-rest-api.el: Ensure strings are encoded before making HTTP request.
(jupyter-api-http-request): Encode JSON as utf-8.
(jupyter-api-xsrf-header-from-cookies): Ensure header isn't multibyte.
(jupyter-api-authenticate): For the token method, ensure token isn't multibyte.
(jupyter-api-copy-file): Encode string before encoding to base64 for binary content.
(jupyter-api-read-file-content): Decode content as utf-8 when necessary.

* jupyter-tramp.el
(jupyter-tramp-write-region): Ensure only `utf-8` or `binary` coding systems
are used since Jupyter only supports those.

* test/jupyter-tramp-test.el: Update for above changes.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
933e5c65a6 Cache file model contents in a buffer
* jupyter-rest-api.el (jupyter-api-content-buffer): New function.
(jupyter-api-insert-model-content): Use it.

* jupyter-tramp.el (jupyter-tramp-file-local-copy): Use it.
2019-07-24 16:59:04 -05:00
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