Skip to content

Commit ef69521

Browse files
committed
Update documentation and comments
1 parent 32bee0b commit ef69521

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

jupyter-client.el

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,16 @@ buffer.")
139139

140140
(defun jupyter-initialize-connection (client &optional file-or-plist)
141141
"Initialize CLIENT with a connection FILE-OR-PLIST.
142-
When FILE-OR-PLIST is a file name, read the JSON connection
143-
information from the file and initialize CLIENT's connection and
144-
channels from the file's contents. When FILE-OR-PLIST is a plist,
145-
initialize CLIENT's connection and channels from the plist. When
146-
FILE-OR-PLIST is nil, then the `conn-info' slot of CLIENT is used
147-
to initialize the connection. The necessary keys to initialize a
148-
connection can be found at
142+
If FILE-OR-PLIST is the name of a file, assume the file to be a
143+
kernel connection file and initialize CLIENT from its contents.
144+
If FILE-OR-PLIST is a property list, initialize CLIENT using its
145+
properties. If FILE-OR-PLIST is nil, initialize CLIENT's
146+
connection using CLIENT's `conn-info' slot. The necessary keys
147+
and values to initialize a connection can be found at
149148
http://jupyter-client.readthedocs.io/en/latest/kernels.html#connection-files.
150149
151150
As a side effect, if CLIENT is already connected to a kernel its
152-
connection is terminated before initializing."
151+
connection is terminated before initializing a new one."
153152
(cl-check-type client jupyter-kernel-client)
154153
(let ((conn-info (if file-or-plist
155154
(oset client conn-info

jupyter-kernel-manager.el

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ SLOTS are the slots used to initialize the client with.")
107107
CLASS should be a subclass of `jupyter-kernel-client', a new
108108
instance of CLASS initialized with SLOTS and configured to
109109
connect to MANAGER's kernel. The returned `jupyter-kernel-client'
110-
will have MANAGER set as its parent-instance slot, see
110+
will have MANAGER set as its `parent-instance' slot, see
111111
`jupyter-connection'."
112112
(unless (child-of-class-p class 'jupyter-kernel-client)
113113
(signal 'wrong-type-argument (list '(subclass jupyter-kernel-client) class)))
@@ -242,7 +242,10 @@ kernel. Starting a kernel involves the following steps:
242242
(oset manager conn-file (expand-file-name
243243
(format "kernel-%d.json" (process-id proc))
244244
jupyter-runtime-directory))
245-
(rename-file conn-file (oref manager conn-file))
245+
;; Gaurd against a kernel that dies after starting. For example,
246+
;; the Julia kernel JuliaLang/IJulia.jl/issues/596 on Julia 0.6.0
247+
(when (process-live-p proc)
248+
(rename-file conn-file (oref manager conn-file)))
246249
(jupyter-start-channels manager)
247250
(progress-reporter-done reporter)
248251
manager))))))
@@ -334,19 +337,19 @@ subprocess."
334337
"Start a managed Jupyter kernel.
335338
KERNEL-NAME is the name of the kernel to start. It can also be
336339
the prefix of a valid kernel name, in which case the first kernel
337-
in `jupyter-available-kernelspecs' that has a kernel name with
338-
KERNEL-NAME as prefix will be used. Optional argument
339-
CLIENT-CLASS should be a subclass of `jupyer-kernel-client' which
340-
will be used to initialize a new client connected to the new
341-
kernel. CLIENT-CLASS defaults to `jupyter-kernel-client'.
340+
in `jupyter-available-kernelspecs' that has KERNEL-NAME as a
341+
prefix will be used. Optional argument CLIENT-CLASS is a subclass
342+
of `jupyer-kernel-client' and will be used to initialize a new
343+
client connected to the kernel. CLIENT-CLASS defaults to
344+
`jupyter-kernel-client'.
342345
343346
Return a cons cell (KM . KC) where KM is the
344347
`jupyter-kernel-manager' that manages the lifetime of the kernel
345-
subprocess. KC is a new client connected to the kernel and whose
348+
subprocess. KC is a new client connected to the kernel whose
346349
class is CLIENT-CLASS. The client is connected to the kernel with
347350
all channels listening for messages and the heartbeat channel
348-
un-paused. Note that the client's parent-instance slot will also
349-
be set to the kernel manager instance, see
351+
un-paused. Note that the client's `parent-instance' slot will
352+
also be set to the kernel manager instance, see
350353
`jupyter-make-client'."
351354
(setq client-class (or client-class 'jupyter-kernel-client))
352355
(unless (child-of-class-p client-class 'jupyter-kernel-client)

jupyter-repl-client.el

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
:group 'jupyter-repl)
7878

7979
(defcustom jupyter-repl-maximum-is-complete-timeout 2
80-
"Maximum number of seconds to wait for a is-complete reply."
80+
"Maximum number of seconds to wait for an is-complete reply.
81+
When no is-complete reply is received from the kernel within this
82+
timeout, the built-in is-complete handler is used."
8183
:group 'jupyter-repl)
8284

8385
(defcustom jupyter-repl-history-maximum-length 100
@@ -1194,7 +1196,7 @@ kernel that the REPL buffer is connected to."
11941196
(not (and (eq major-mode 'jupyter-repl-mode)
11951197
;; TODO: Handle case when multiple clients are connected, i.e. do
11961198
;; we want to also delete a kernel if this is the last client
1197-
;; connected. See eieio instance tracker.
1199+
;; connected. See `eieio-instance-tracker'.
11981200
(or (and (jupyter-repl-client-has-manager-p)
11991201
(jupyter-kernel-alive-p
12001202
(oref jupyter-repl-current-client parent-instance)))
@@ -1381,9 +1383,9 @@ CODE and POS are the code to send and the position within the
13811383
code, respectively.
13821384
13831385
If BUFFER is non-nil then it should be the buffer in which to
1384-
insert the inspection text returned from kernel. After the
1385-
inspection text is inserted into BUFFER, BUFFER is returned. If
1386-
BUFFER is nil, then return the inspection text. In both cases the
1386+
insert the inspection text returned from the kernel. After the
1387+
inserting the text into BUFFER, BUFFER is returned. If BUFFER is
1388+
nil, just return the inspection text. In both cases the
13871389
inspection text is already in a form suitable for display.
13881390
13891391
TIMEOUT is how long to wait (in seconds) for the kernel to

ob-jupyter.el

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ See `org-babel-jupyter-file-name'."
6565

6666
(defun org-babel-variable-assignments:jupyter (params &optional lang)
6767
"Assign variables in PARAMS according to the Jupyter kernel language.
68-
Use `org-babel-jupyter-src-block-lang' to get the kernel language
69-
of the src-block ELEMENT and call the variable assignment
70-
function for the language. ELEMENT defaults to the
71-
`org-element-at-point'. So if LANG is the kernel language, then
72-
call
68+
LANG is the kernel language of the source block. If LANG is nil,
69+
get the kernel language from the current source block.
7370
74-
org-babel-variable-assignments:LANG
75-
76-
If the above function doesn't exist or if no kernel langauge can
77-
be found, fall back to `org-babel-variable-assignments:python'."
71+
The variables are assigned by looking for the function
72+
`org-babel-variable-assignments:LANG'. If this function does not
73+
exist or if LANG cannot be determined, assign variables using
74+
`org-babel-variable-assignments:python'."
7875
(let* ((lang (or lang
7976
(save-excursion
8077
(when (re-search-backward
@@ -91,18 +88,16 @@ be found, fall back to `org-babel-variable-assignments:python'."
9188
BODY is the code to expand, PARAMS should be the header arguments
9289
of the src block with BODY as its code, and VAR-LINES should be
9390
the list of strings containing the variables to evaluate before
94-
executing body.
91+
executing body. LANG is the kernel language of the source block.
9592
9693
This function is similar to
97-
`org-babel-variable-assignments:jupyter' in that it finds the
98-
kernel language of the src-block ELEMENT, defaulting to the
99-
`org-element-at-point', to find get the kernel language of BODY.
100-
So if LANG is the kernel language, call the function
101-
102-
org-babel-expand-body:LANG
94+
`org-babel-variable-assignments:jupyter' in that it attempts to
95+
find the kernel language of the source block if LANG is not
96+
provided.
10397
104-
to expand BODY. If the above function doesn't exist or if no
105-
kernel langauge can be found fall back to
98+
BODY is expanded by calling the function
99+
`org-babel-expand-body:LANG'. If this function doesn't exist or
100+
if LANG cannot be determined, fall back to
106101
`org-babel-expand-body:generic'."
107102
(let* ((lang (or lang
108103
(save-excursion
@@ -132,7 +127,8 @@ the header variables in PARAMS."
132127
(when var-lines
133128
(jupyter-repl-replace-cell-code
134129
(mapconcat #'identity var-lines "\n"))
135-
;; For `org-babel-load-session:jupyter'
130+
;; For `org-babel-load-session:jupyter', ensure that the loaded code
131+
;; starts on a new line.
136132
(when no-execute
137133
(insert "\n")))
138134
(unless no-execute
@@ -353,7 +349,7 @@ removal."
353349
For example, call `org-babel-python-table-or-string' on the
354350
results when rendering scalar data for a python code block.
355351
356-
RENDER-RESULT should be the cons cell returned by
352+
RENDER-RESULT is the cons cell returned by
357353
`org-babel-jupyter-prepare-result' and KERNEL-LANG is the kernel
358354
language."
359355
(cl-destructuring-bind (render-param . result) render-result
@@ -364,23 +360,26 @@ language."
364360

365361
(defun org-babel-jupyter-insert-results (results params kernel-lang)
366362
"Insert RESULTS at the current source block location.
367-
RESULTS is either a a single pair or a list of pairs with the form
363+
RESULTS is either a single pair or a list of pairs, each pair
364+
having the form
368365
369366
(RENDER-PARAM . RESULT)
370367
371368
i.e. the pairs returned by `org-babel-jupyter-prepare-result'.
372-
PARAMS should be the parameters passed to
373-
`org-babel-execute:jupyter'. KERNEL-LANG is the language of the
374-
kernel for the current source block. If optional argument APPEND
375-
is non-nil, then append RESULTS to the current results. The
376-
results will also be appended, regardless of the value of APPEND,
377-
if RESULTS is a list."
369+
PARAMS are the parameters passed to `org-babel-execute:jupyter'.
370+
KERNEL-LANG is the language of the kernel that produced RESULTS.
371+
372+
Note that for a list of results, the result which will appear
373+
will be the last one in the list unless the source block has an
374+
\"append\" or \"prepend\" parameter or some other way that
375+
prevents `org-babel-insert-result' from clearing a result when
376+
inserting a new one."
378377
;; Unless this is a list of results
379378
(unless (car-safe (car results))
380379
(setq results (list results)))
381380
(cl-loop
382-
;; FIXME: This is a hack that relies on `org-babel-insert-result' only caring
383-
;; about the parameters of the info and not anything else.
381+
;; FIXME: This is a hack that relies on `org-babel-insert-result' only
382+
;; caring about the parameters of the info and not anything else.
384383
with info = (list nil nil params)
385384
with result-params = (alist-get :result-params params)
386385
for (render-param . result) in
@@ -439,6 +438,7 @@ PARAMS."
439438
(org-babel-jupyter--inject-render-param "append" params))
440439
(org-babel-jupyter-insert-results result params kernel-lang))
441440
(push result results)))))
441+
;; TODO: Handle stream output and errors similar to ob-ipython
442442
(jupyter-add-callback req
443443
:stream
444444
(lambda (msg)
@@ -494,10 +494,9 @@ PARAMS."
494494

495495
(defun org-babel-jupyter-make-language-alias (kernel lang)
496496
"Simimilar to `org-babel-make-language-alias' but for Jupyter src-blocks.
497-
KERNEL should be the name of a the default kernel using for the
498-
kernel LANG. All necessary org-babel functions for a language
499-
with the name jupyter-LANG will be aliased to the jupyter
500-
functions."
497+
KERNEL should be the name of the default kernel to use for kernel
498+
LANG. All necessary org-babel functions for a language with the
499+
name jupyter-LANG will be aliased to the jupyter functions."
501500
(dolist (fn '("execute" "expand-body" "prep-session" "edit-prep"
502501
"variable-assignments" "load-session"))
503502
(let ((sym (intern-soft (concat "org-babel-" fn ":jupyter"))))
@@ -523,8 +522,7 @@ Optional argument REFRESH has the same meaning as in
523522
(cl-loop
524523
for (kernel . (_dir . spec)) in (jupyter-available-kernelspecs refresh)
525524
for lang = (plist-get spec :language)
526-
;; Only make aliases the first time a new language appears
527-
unless (functionp (intern (concat "org-babel-execute:jupyter-" lang)))
525+
unless (member lang languages) collect lang into languages and
528526
do (org-babel-jupyter-make-language-alias kernel lang)
529527
;; (add-to-list 'org-babel-tangle-lang-exts
530528
;; (cons (concat "jupyter-" lang) file_extension))

0 commit comments

Comments
 (0)