Commit graph

178 commits

Author SHA1 Message Date
Tomasz Mieszkowski
7d20c0aee2 Sort available kernelspecs; guess with ^; use guessing in jupyter-run-repl 2022-04-19 13:52:23 -05:00
Nathaniel Nicandro
c702f1e90f Add some helper functions for Org tests 2021-11-30 10:47:53 -06:00
Nathaniel Nicandro
113acb239d Use default-directory as :dir when executing a source block
`default-directory` is already set according to :dir when executing a
source block. This prevents `org-babel-expand-body:jupyter` from
attempting to re-expand the value of the :dir header argument.
See #302.
2021-11-30 10:47:53 -06:00
Nathaniel Nicandro
db450a9f44 Ignore ANSI escapes when testing some Org source blocks 2021-11-30 10:47:53 -06:00
Nathaniel Nicandro
a2cbebdfda Use a raw string in :dir handling code for Python source blocks 2021-11-30 10:47:53 -06:00
Nathaniel Nicandro
4729e21184 Fix output order when using pandoc conversion
Fixes #351.
2021-11-30 10:46:52 -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
026c3fac61 Use :extra methods for org-babel-jupyter-parse-session
* ob-jupyter.el
(org-babel-jupyter-server-session)
(org-babel-jupyter-parse-session): Convert to method and re-implement
with :extra methods.

* test/jupyter-server-test.el
(org-babel-jupyter-server-session): New test.

* test/jupyter-test.el
(org-babel-jupyter-parse-session): Move test of server based sessions
to the new test.
2021-04-22 09:51:36 -05:00
Nathaniel Nicandro
c3fae7d7df jupyter-request-idle-received-p -> jupyter-request-idle-p
but first...

* jupyter-base.el: ...idle-received-p -> idle-p for jupyter-request objects

* jupyter-client.el: ...then, do it.

* test/jupyter-test.el: Do it.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
7ca3344c1b Add syncing functions
These will be used in future commits.

* jupyter-client.el (jupyter-idle-sync)
(jupyter-add-idle-sync-hook): New functions.

* test/jupyter-test.el (jupyter-idle-sync): New test.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
d6aced9e71 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.
2021-04-03 12:22:58 -05:00
Nathaniel Nicandro
a9ae0bcef5 Replace jupyter-repl-cell-cond with jupyter-repl-map-cells
* jupyter-repl.el
(jupyter-repl-map-cells): New function.
(jupyter-repl-cell-cond): Remove. Update callers with new function.

* jupyter-julia.el: Ditto.

* test/jupyter-test.el
(jupyter-repl-map-cells): New test.
(jupyter-repl-cell-cond): Remove.
2020-04-14 17:18:38 -05:00
Nathaniel Nicandro
a7dbff9aa3 Refactor source block overriding mechanism
This commit adds the function `org-babel-jupyter--babel-map` and some
auxiliary functions to simplify the code for source block
overriding. The old implementation was very hard to follow, these
changes should hopefully make the code more readable.

* ob-jupyter.el (org-babel-jupyter--override-restore-header-args)
(org-babel-jupyter--override-restore-src-block): Remove.
(org-babel-jupyter--babel-vars): New variable.
(org-babel-jupyter--babel-op-symbol)
(org-babel-jupyter--babel-var-symbol)
(org-babel-jupyter--babel-map): New functions.
(org-babel-jupyter-override-src-block)
(org-babel-jupyter-restore-src-block)
(org-babel-jupyter-make-language-alias): Use them.
2020-04-14 17:05:28 -05:00
Nathaniel Nicandro
e400266ce1 Replace the jupyter-loop-over-mime macro
It is replaced with `jupyter-map-mime-bundle` which is a function.

* jupyter-base.el (jupyter-loop-over-mime): Remove.
(jupyter-map-mime-bundle): New function. Update call sites of the
removed function, with calls to this function.
(jupyter-normalize-data): Return a mime bundle, a property list with
:data and :metadata keys.  Update all callers.

* jupyter-mime.el (jupyter-insert): Updated to take into account the
  previously mentioned changes.

* jupyter-org-client.el (jupyter-org-result): Ditto.

* test/jupyter-test.el (jupyter-loop-over-mime): Rename to
  `jupyter-map-mime-bundle` and update the test to consider it.
2020-04-14 15:46:38 -05:00
Nathaniel Nicandro
91ca722b63 Remove unused code
The `jupyter-zmq-channel-comm.el` file was more of an experiment and
is unused.  It also causes failures on Emacs 27 due to missing
`thread-alive-p` function in 27.

* jupyter-zmq-channel-comm.el: Remove.

* test/jupyter-test.el: Remove the related `require`.  Re-work tests
  that used `jupyter-zmq-channel-comm` to not use it.
2020-04-14 12:23:51 -05:00
Nathaniel Nicandro
97c421a698 Fix regression
In `org-babel-jupyter-initiate-session-by-key`, the function to
disassociate a client from a :session was added to the
`current-buffer`s value of `kill-buffer-hook` but it should be added
to the REPL buffer's value of that hook.

fixes #240

* ob-jupyter.el
(org-babel-jupyter-initiate-session-by-key): Add to the local value of
`kill-buffer-hook` in the REPL's buffer.

* test/jupyter-test.el
(org-babel-jupyter-initiate-session-by-key): New test.
2020-04-14 11:36:40 -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