Commit graph

152 commits

Author SHA1 Message Date
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
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
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
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
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
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
Jack Kamm
7f82e5db8c ob-jupyter: fixes #185 relative path to remote :session json 2019-10-16 13:03:02 -05:00
Nathaniel Nicandro
2245d66b0f org-babel-execute:jupyter: Use "???" as a placeholder when inline results are pending
Closes #175.
2019-09-14 18:20:28 -05:00
Nathaniel Nicandro
79ddd9357e Add org-babel-jupyter-current-src-block-params
This is needed because `org-mode` merges many sources of source block params so
its not enough to just re-compute the parameters in `jupyter-generate-request`
using `org-babel-get-src-block-info` or `org-babel-log-get-info`.
2019-09-01 11:43:46 -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
4b55a29726 org-babel-jupyter--server-repl: Associate session name with kernel ID
So that `M-x jupyter-server-list-kernels` will show which kernel corresponds to
an Org mode source block session.
2019-07-24 16:59:04 -05:00
Nathaniel Nicandro
3aa889b25c org-babel-jupyter--server-repl: Make language aliases if necessary
* ob-jupyter.el (org-babel-jupyter--server-repl): Do it.
(org-babel-jupyter-make-language-alias): Set `org-babel-tangle-lang-exts` and
`org-src-lang-modes` also.
(org-babel-jupyter-aliases-from-kernelspecs): Accept an optional `specs`
argument. Move setting of `org-babel-tangle-lang-exts` and `org-src-lang-modes`
to `org-babel-jupyter-make-language-alias`.
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
6650dd3588 Bump version 2019-07-24 16:03:22 -05:00
Nathaniel Nicandro
6b86fedb10 org-babel-jupyter-make-language-alias: Make sure variable is bound 2019-07-18 17:21:53 -05:00
Nathaniel Nicandro
f8796aa13f Partially revert "0f01a2a2ed36ffc676d1d5f39e2c3f562ad2ca03"
The normal way of loading `ob-jupyter` is through `org-babel-do-load-languages`
so a users `exec-path` should be enabled by that time and so there is a higher
chance that it is setup correctly. See #151.
2019-07-18 15:38:23 -05:00
Nathaniel Nicandro
857f5e5071 org-babel-jupyter-make-language-alias: Don't overwrite variables that already exist
Also, set the :kernel header argument in the default header arguments for a
language if not already present.
2019-07-18 15:35:15 -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
31b551bdc1 org-babel-jupyter--run-repl: Make language aliases for remote kernelspecs 2019-07-09 13:50:20 -05:00
Nathaniel Nicandro
0f01a2a2ed ob-jupyter.el: Don't make language aliases at load time 2019-07-09 13:47:17 -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
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
25ff5dd871 jupyter-org-client: Remove unnecessary block-params slot 2019-06-23 16:11:27 -05:00
Nathaniel Nicandro
1913da83fa org-babel-jupyter-scratch-buffer: Don't switch buffers when inside edit buffer 2019-06-12 23:22:20 -05:00
Nathaniel Nicandro
5ea32a70f0 Change License to GPL3 2019-05-31 09:44:39 -05:00
Nathaniel Nicandro
e05ef4f8d5 org-babel-jupyter-initiate-session-by-key: Support remote kernel starts 2019-05-20 22:46:46 -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
240dc7ab08 org-babel-expand-body:jupyter: Correct arguments to language specific expander
The language specific expander only expects (BODY PARAMS)
2019-05-19 23:16:46 -05:00
Nathaniel Nicandro
d0000e8382 org-babel-jupyter-aliases-from-kernelspecs: Use symbols in org-src-lang-modes
This avoids a bug in `org-mode`. Although the documentation of
`org-src-lang-modes` says the mode can be a symbol or a string, the
customization type only specifies symbol so having a string causes errors when
`custom-initialize-reset` is called after
`org-babel-jupyter-aliases-from-kernelspecs`.
2019-05-08 23:26:07 -05:00
Nathaniel Nicandro
5cd1e55616 org-babel-jupyter-strip-ansi-escapes: Handle blocks without results
Fixes #112.
2019-05-08 10:36:38 -05:00
Nathaniel Nicandro
2091a01b52 org-babel-jupyter-strip-ansi-escapes: Avoid when-let* 2019-05-07 00:38:01 -05:00
Ning Xu
59275f655a Fix two org-src-lang-modes calc issues (#107)
For assoc lang org-src-lang-modes may return symbol sh, (inter 'sh) will
return an error.

For some languages like C++, the corresponding language mode shall be c++
2019-05-06 23:53:29 -05:00
Nathaniel Nicandro
112769e0c6
Bump version 2019-05-04 03:31:50 -05:00
Nathaniel Nicandro
3f382a8fe8
Require ob-python when its needed 2019-05-03 14:02:01 -05:00
Nathaniel Nicandro
e08d451f2a
Don't use most-positive-fixnum as a timeout
There are sometimes intermittent failures which seem to originate from this.
2019-04-08 12:44:48 -05:00
Nathaniel Nicandro
580776bf58 Add org-babel-jupyter-src-block-session 2019-03-28 23:29:02 -05:00
Nathaniel Nicandro
7fec895c03 Before export, remove ANSI escapes from source block results 2019-03-20 21:08:53 -05:00
Nathaniel Nicandro
33bae1762d
org-babel-execute:jupyter: Remove export sync hook before waiting 2019-03-18 10:41:44 -05:00
Nathaniel Nicandro
3b6b60d803 jupyter-org-insert-async-id -> jupyter-org-pending-async-results 2019-03-17 02:06:00 -05:00
Nathaniel Nicandro
c0d13396bb org-babel-execute:jupyter: Make all blocks synchronous during export 2019-03-17 02:04:00 -05:00
Nathaniel Nicandro
129f53f7a8 Add org-babel-jupyter-language-p 2019-03-17 02:03:00 -05:00
Nathaniel Nicandro
3adf0dc336
Add TODO on supporting ":results link" in org-mode source blocks 2019-03-15 14:41:22 -05:00