Commit graph

166 commits

Author SHA1 Message Date
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
785edbbff6 Fix missing function
`jupyter-server-make-instance` is from another branch.

* ob-jupyter.el: Remove `jupyter-server-make-instance` declaration.
(org-babel-jupyter-initiate-client): Replace its use with `jupyter-server`.
2020-04-17 14:07:06 -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
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
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
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
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