Commit graph

1834 commits

Author SHA1 Message Date
Nathaniel Nicandro
a7769c78ed org-babel-execute:jupyter: Isolate use of org-babel-jupyter--remove-file-param
The :file result-parameter of source block interferes with how async result
insertion works, namely how an indicator is inserted to signify that the
results are pending.  The parameter is removed in cases where it would
interfere.

* ob-jupyter.el (org-babel-execute:jupyter): Do it.
2020-04-03 15:28:23 -05:00
Nathaniel Nicandro
5c2469dbe4 Don't set org-babel-jupyter-current-src-block-params
This variable is `let` bound by `org-babel-execute:jupyter` and its value reset
after that function has completed and therefore does not need to be set to
`nil` by `jupyter-drop-request`.

fixes #234
fixes #235

* jupyter-org-client.el: Remove duplicated `defvar` of
`org-babel-jupyter-current-src-block-params`.
(jupyter-drop-request): Remove use of
`org-babel-jupyter-current-src-block-params`.
2020-04-02 15:31:08 -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
3322ce7b31 Fix ordering of slot access
* jupyter-server-ioloop-comm.el
(jupyter-server-kernel-connected-p): Do it.
2020-04-01 00:21:38 -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
8883a6631a Don't require ZMQ in Makefile targets
* Makefile: Do it.
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
5725215268 Implement a jupyter-comm-layer using a websocket
The `jupyter-server-kernel-comm` class is re-purposed for this, as mentioned in
the previous commit.

* jupyter-server.el (jupyter-server--ws-on-message): New function.
(jupyter-comm-start, jupyter-comm-stop, jupyter-comm-alive-p, jupyter-send)
[jupyter-server-kernel-comm]: New methods.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
3b3e358933 Split ZMQ related code from jupyter-server.el
In the following, accept means moved from `jupyter-server.el` and move means
moved to `jupyter-server-ioloop-comm.el`.  A label like [class] means the
references that appear before the label are actually methods of class.

  * jupyter-server.el: Move all `jupyter-event-handler` methods.
  (jupyter-server-kernel-comm): Add `ws` slot. The class has
  been repurposed for communication using a websocket in the current Emacs
  instance.  The old behavior has been assigned to the
  `jupyter-server-ioloop-kernel-comm` class.
  (jupyter-comm-id, jupyter-server-name-client-kernel)
  (jupyter-channel-alive-p, jupyter-channels-running-p)
  (jupyter-server-kernel-manager, jupyter-current-server): Rename
  `jupyter-server-kernel-comm` to `jupyter-server-abstract-kcomm`.
  (jupyter-server-kernel-connected-p): Redefine as a generic function.  Move the
  method body.
  (jupyter-comm-start, jupyter-connect-client)
  (jupyter-disconnect-client) [jupyter-server]: Move.
  (jupyter-comm-start, jupyter-comm-stop)
  (jupyter-send, jupyter-comm-alive-p) [jupyter-server-kernel-comm]: Move.

  * jupyter-server-ioloop-comm.el: Accept moved `jupyter-event-handler`
    methods.  Rename `jupyter-server` to `jupyter-server-ioloop-comm`.  Rename
    `jupyter-server-kernel-comm` to `jupyter-server-ioloop-kernel-comm`.
  (jupyter-server-kernel-connected-p)
  (jupyter-comm-start, jupyter-connect-client)
  (jupyter-disconnect-client) [jupyter-server]: Accept.
  (jupyter-comm-start, jupyter-comm-stop)
  (jupyter-comm-alive-p, jupyter-send) [jupyter-server-kernel-comm]: Accept.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
a5f8d991b0 Introduce new file and custom variable
* jupyter-server-ioloop-comm.el: New file.

* jupyter-server.el (jupyter-server-use-zmq): New variable.
(jupyter-server-abstract-kcomm): New class.
(jupyter-server-kernel-comm): Inherit from it. This is in preparation of
re-purposing the class in a future commit.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
1a739feec7 Add section on jupyter-comm-layer in README
* README.org: Do it.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
4115ff5f73 Rework "Waiting for messages" section in README
* README.org: Do it.
2020-03-30 23:31:14 -05:00
Nathaniel Nicandro
b691d38483 Allow modification hooks when suppressing continuation prompts
* jupyter-repl.el
(jupyter-repl-inhibit-continuation-prompts): New variable.
(jupyter-repl-without-continuation-prompts)
(jupyter-repl-insert-continuation-prompts): Use it.
2020-03-29 03:28:54 -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
b66ddf50eb Fix missing argument in call to tramp-run-real-handler
* jupyter-tramp.el (jupyter-tramp-expand-file-name): Do it.
2020-03-17 17:39:54 -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
045f2b8b42 Fix recursive loading caused by autoload in jupyter-tramp.el
fixes #172
fixes #215

* jupyter-tramp.el (jupyter-tramp-file-name-p): Change to `defsubst`.
2020-03-14 14:39:35 -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
be8ee2c482 Remove unused function
That also happens to use a ZMQ function.

* jupyter-rest-api.el (jupyter-api-upload-large-file): Do it.

* jupyter-tramp.el: Remove mention of `jupyter-api-upload-large-file` in a
  comment.
2020-03-13 19:14:32 -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
5883bad935 Remove extra quote in jupyter-repl-interaction-modes :lighter
* jupyter-repl.el (jupyter-repl-interaction-mode): Do it.
2020-03-12 23:56:13 -05:00
Nathaniel Nicandro
bb50dfb830 Use org-element-create 2020-03-12 23:56:13 -05:00
Nathaniel Nicandro
cff20a5a6a Avoid an unnecessary error condition in jupyter-wait-until-idle
`jupyter-wait-until-idle` can return immediately if an idle message has already
been received, but the function `jupyter-wait-until` will eventually raise an
error in that case. Avoid the error by checking
`jupyter-request-idle-received-p` before calling `jupyter-wait-until`.

* jupyter-client.el (jupyter-wait-until-idle): Do it.

* ob-jupyter.el (org-babel-execute:jupyter): Account for changes in
  `jupyter-wait-until-idle`.
2020-03-12 23:56:13 -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
Nathaniel Nicandro
7ffc27ed2e jupyter-widgets-client.el: Refactor jupyter-handle-comm-open
* jupyter-widget-client.el (jupyter-widgets-start-websocket-server)
(jupyter-widgets--initialize-client): New functions.
(jupyter-handle-comm-open): Use them.
2020-03-12 23:22:57 -05:00
Nathaniel Nicandro
0e68f0f2f4 Remove a call to cons
* jupyter-widget-client.el (jupyter-widgets-on-message): Do it.
2020-03-12 23:22:57 -05:00
Nathaniel Nicandro
68afaab9b5 jupyter-widgets-sanitize-comm-msg -> jupyter-widgets-normalize-comm-msg
* jupyter-widget-client.el (jupyter-widgets-sanitize-comm-msg): Do it. Update
  all callers.
2020-03-12 23:22:56 -05:00
Nathaniel Nicandro
16176b197a Remove some code duplication
* jupyter-widget-client.el (jupyter-widgets--send-deferred): New function.
(jupyter-widgets-on-message, jupyter-widgets-send-message) Use it.
2020-03-12 23:22:56 -05:00
Nathaniel Nicandro
a4683d1a14 Deactivate REPL interaction buffers in kill-buffer-hook
* jupyter-repl.el (jupyter-repl--deactivate-interaction-buffers): New function.
(jupyter-repl-kill-buffer-query-function): Extract code that deactivates
`jupyter-repl-interaction-mode` in connected buffers to the new function.
(jupyter-repl-mode): Add the new function to `kill-buffer-hook`.
2020-03-12 23:13:58 -05:00
Nathaniel Nicandro
c26978baf8 Simplify doc of org-babel-jupyter-current-src-block-params
* ob-jupyter.el (org-babel-jupyter-current-src-block-params): Do it.
2020-03-12 23:13:58 -05:00
Nathaniel Nicandro
e6e9694f94 Do more cleanup after finishing Org src-block requests
* jupyter-org-client.el (jupyter-drop-request): Reset
  `org-babel-jupyter-current-src-block-params` if its value matches the dropped
  request's `block-params`.
2020-03-12 23:13:58 -05:00
Nathaniel Nicandro
4a899deddc jupyter-repl.el: Prefer evaluate to run in documentation 2020-03-12 23:13:58 -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
conao3
6426e12578 ignore .cask folder 2020-03-10 23:39:35 -05:00
astoff
d4b06c54d3 jupyter-repl-traceback face: use a light background on light themes
The previous value of this face used a dark background even on light themes, making
error messages hard to read.
2020-03-05 18:42:07 -06:00
Arthur Colombini Gusmão
9e3c163358 fix: show pop-up buffer when REPL not visible
The described behavior for when `jupyter-repl-echo-eval-p` is `t` and the REPL buffer is not visible was not working, i.e., no pop-up buffer was being show.
2019-10-19 10:19:58 -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
Arthur Colombini Gusmão
7d5f978328 Move whitespace to overlay prefix
Move the whitespace that was originally concatenated to the prefix variable `jupyter-eval-overlay-prefix` to the variable itself, so that it can be easily customized. For instance, in the case where one does not want any prefix, with the changes, it can be easily removed by setting the prefix variable to the empty string. Originally one would have to also modify the function `jupyter-eval-ov--propertize` to achieve the same result.
2019-10-16 13:03:56 -05:00
Jack Kamm
7f82e5db8c ob-jupyter: fixes #185 relative path to remote :session json 2019-10-16 13:03:02 -05:00
Nathaniel Nicandro
53da538b66 jupyter-org-hydra/body: Add scratch buffer binding 2019-09-23 20:43:39 -05:00
Nathaniel Nicandro
e92d265869 jupyter-server-kernel-list-mode: Sort list by activity
* jupyter-server.el (jupyter-server--kernel-list-entries):
Add missing jupyter-time text property to activity string.
(jupyter-server-list-kernels): Set `tabulated-list-sort-key`.
2019-09-23 20:40:39 -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
198c036f51 jupyter-org-indent-inserted-region: Reduce verbosity of doc 2019-09-22 13:33:42 -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
470521dac5 jupyter-current-server: Signal an error for non-existent servers
Only do so when asking the user for a URL and no server exists at the URL
provided. See #183.

* jupyter-server.el (jupyter-server-non-existent): New error.
(jupyter-current-server): Signal `jupyter-server-non-existent` when asking the
user for a server URL and a server doesn't exist at URL.
2019-09-15 20:26:54 -05:00
Nathaniel Nicandro
29b3a3d79f .travis.yml: Use nix-emacs-ci instead of evm 2019-09-15 19:01:16 -05:00
Nathaniel Nicandro
8fd5d8d95e Fix error handling in TRAMP functions for Emacs >= 27
TRAMP sets its own value of `signal-hook-function` which interferes with
`signal` data when handling errors in `condition-case` so unbind
`signal-hook-function` until we have a chance to look at `signal` data.

* jupyter-server.el (jupyter-kernel-alive-p): Use `nth`

* jupyter-tramp.el (jupyter-tramp--get-directory-or-file-model)
(jupyter-tramp-delete-directory): Unbind `signal-hook-function`.
2019-09-15 19:00:18 -05:00