Commit graph

1764 commits

Author SHA1 Message Date
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
90e0c06f2e Use and in one place
* jupyter-org-client.el (jupyter-org--append-stream-result-p): Do it.
2020-04-14 12:25:28 -05:00
Nathaniel Nicandro
7d61c82567 Do not delete a character that isn't expected
* jupyter-org-client.el (jupyter-org--append-to-example-block): Do it.
2020-04-14 12:25:08 -05:00
Nathaniel Nicandro
adcc853183 Use pcase in one place
* jupyter-org-client.el (jupyter-org--find-mime-types): Do it.
2020-04-14 12:24:42 -05:00
Nathaniel Nicandro
4a0617132f Use cl-callf2 in a few places
* jupyter-comm-layer
(jupyter-comm-add-handler, jupyter-comm-remove-handler): Do it.
2020-04-14 12:24:11 -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
82f8fe691e Set back to dev 2020-04-07 15:43:10 -05:00
Nathaniel Nicandro
403c70c83c Bump version 2020-04-07 15:13:51 -05:00
Nathaniel Nicandro
4c9e616690 ob-jupyter.el: Add more documentation
* ob-jupyter.el: Do it.
2020-04-07 12:24:34 -05:00
Nathaniel Nicandro
a997e34001 Move kludge outside of org-babel-jupyter-make-language-alias
That function should just create the function aliases and define the necessary
variables if not already defined.  It should not also set the :kernel header
argument if it isn't present in the org-babel-default-header-args:jupyter-LANG
variable.

* ob-jupyter.el (org-babel-jupyter-make-language-alias): Remove setting of :kernel.
(org-babel-jupyter-aliases-from-kernelspecs): Set :kernel after creating a
language alias.
2020-04-07 12:11:59 -05:00
Nathaniel Nicandro
16ea58e59e Use pcase-let to reduce verbosity
* ob-jupyter.el
(org-babel-jupyter-initiate-client) [org-babel-jupyter-remote-session]: Do it.
2020-04-07 09:00:35 -05:00
Nathaniel Nicandro
8c840d42d3 Fix typo
* ob-jupyter.el (org-babel-jupyter-initiate-client): Do it.
2020-04-06 12:36:36 -05:00
Nathaniel Nicandro
dc8fc6767f Silence byte compiler 2020-04-04 21:17:37 -05:00
Nathaniel Nicandro
0c2531402e Fix wrong number of arguments
* ob-jupyter.el (org-babel-prep-session:jupyter)
(org-babel-load-session:jupyter): Fix number of arguments to
`org-babel-jupyter--insert-variable-assignments`.
2020-04-04 21:17:37 -05:00
Nathaniel Nicandro
d336cdcace Unify code waiting for kernel processes to be ready
* jupyter-kernel-process-manager.el
(jupyter--after-kernel-process-ready): New macro.
(jupyter-start-kernel [jupyter-command-kernel, jupyter-spec-kernel]): Use it.
(jupyter--block-until-conn-file-access): Remove.
2020-04-04 21:17:37 -05:00
Nathaniel Nicandro
02231066e1 Relocate jupyter-write-connection-file
The function writes to `jupyter-runtime-directory` and does not depend on
anything in`jupyter-kernel-process-manager.el` so it is more appropriate in
`jupyter-env.el`.

* jupyter-env.el (jupyter-write-connection-file): New function.

* jupyter-kernel-process-manager.el (jupyter-write-connection-file): Remove.
2020-04-04 20:54:02 -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
0281704e4d org-babel-jupyter-parse-session: Handle .json suffix more smoothly
If a Jupyter TRAMP remote file contains a .json suffix do not treat it as a
kernel connection file.  The connection information is already contained in the
TRAMP method!

* ob-jupyter.el (org-babel-jupyter-parse-session): Do it.
2020-04-04 08:52:15 -05:00
Nathaniel Nicandro
4ed5b2644f Fix typo
* ob-jupyter.el (org-babel-jupyter-parse-session): `:connect-repl` -> `:connect-repl-p`
2020-04-04 08:39:48 -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
db5d06faa6 Remove jupyter-repl-insert
It's main purpose was to not forget to add the `read-only` property to text
that needed it.  The code base is stable enough to where this is not an issue
anymore.

* jupyter-repl.el (jupyter-repl-insert): Remove. Update all callers.

* jupyter-python.el (jupyter-handle-error): Ditto.
2020-04-04 08:39:45 -05:00
Nathaniel Nicandro
4399d25cdb ob-jupyter.el: Update documentation
* ob-jupyter.el (org-babel-jupyter-session-clients)
(org-babel-jupyter-session-key)
(org-babel-edit-prep:jupyter)
(org-babel-jupyter-aliases-from-kernelspecs): Do it.
2020-04-03 18:53:11 -05:00
Nathaniel Nicandro
51b7ddc57a ob-jupyter.el: Remove stale declarations
* ob-jupyter.el: Do it.
2020-04-03 18:53:11 -05:00
Nathaniel Nicandro
ce08af0932 Refactor Org Babel :session handling
Introduce the `org-babel-jupyter-initiate-client` generic. Method
implementations return a `jupyter-org-client` depending on the type of :session
as returned by `org-babel-jupyter-parse-session`.

* ob-jupyter.el
(org-babel-jupyter--run-repl)
(org-babel-jupyter--server-repl): Remove.
(org-babel-jupyter-session, org-babel-jupyter-remote-session)
(org-babel-jupyter-server-session): New struct types.
(org-babel-jupyter-parse-session): New function.
(org-babel-jupyter-initiate-client): New generic.  Implement a method for each
new struct type based on the removed functions, with some tidying up.
(org-babel-jupyter-initiate-session-by-key): Replace client setting logic with
a call to `org-babel-jupyter-initiate-client`.  Move REPL buffer rename code to
an :around method of `org-babel-jupyter-initiate-client`.
2020-04-03 18:53:00 -05:00
Nathaniel Nicandro
4ce54a056b Add jupyter-server-has-kernelspec-p
* jupyter-server.el (jupyter-server-has-kernelspec-p): New method.

* ob-jupyter.el (org-babel-jupyter--server-repl): Use it.
2020-04-03 18:43:53 -05:00
Nathaniel Nicandro
44adef4bc0 org-babel-prep-session:jupyter: Remove optional argument
* ob-jupyter.el
(org-babel-jupyter--insert-variable-assignments): New function.
(org-babel-prep-session:jupyter, org-babel-load-session:jupyter): Use it.
(org-babel-prep-session:jupyter): Remove DELAY-EVAL argument.
2020-04-03 18:43:53 -05:00
Nathaniel Nicandro
6420e20646 org-babel-execute:jupyter: Update two comments
* ob-jupyter.el (org-babel-execute:jupyter): Do it.
2020-04-03 15:28:23 -05:00
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