Skip to content

Commit

Permalink
Add jupyter-read-connection
Browse files Browse the repository at this point in the history
* jupyter-base.el (jupyter-read-connection): New function.

* jupyter-kernel-process-manager.el
(jupyter-start-kernel) [jupyter-command-kernel]: Use it.
  • Loading branch information
nnicandro committed Apr 22, 2021
1 parent c36f6fd commit 6be4f79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 17 additions & 0 deletions jupyter-base.el
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,23 @@ Note only SSH tunnels are currently supported."
(jupyter-make-ssh-tunnel lport maybe-rport server remoteip)))
else collect maybe-rport)))))

(defun jupyter-read-connection (conn-file)
"Return the connection information in CONN-FILE.
Return a property list representation of the JSON in CONN-FILE, a
Jupyter connection file.
If CONN-FILE is a remote file, possibly create an SSH tunnel
between the localhost and the kernel on the remote host where
CONN-FILE lives. The returned connection info. will reflect
these changes.
See `jupyter-tunnel-connection' for more details on creating
tunnels. For more information on connection files, see
https://jupyter-client.readthedocs.io/en/stable/kernels.html#connection-files"
(if (file-remote-p conn-file)
(jupyter-tunnel-connection conn-file)
(jupyter-read-plist conn-file)))

;;; Helper functions

(defun jupyter-canonicalize-language-string (str)
Expand Down
17 changes: 9 additions & 8 deletions jupyter-kernel-process-manager.el
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ argument of the process."
:wait-form (and (process-live-p (oref kernel process))
(goto-char (point-min))
(re-search-forward "Connection file: \\(.+\\)\n" nil t))
(let* ((conn-file (match-string 1))
(remote (file-remote-p default-directory))
(conn-info (if remote (jupyter-tunnel-connection
(concat remote conn-file))
(jupyter-read-plist conn-file))))
(oset kernel session (jupyter-session
:conn-info conn-info
:key (plist-get conn-info :key))))))
(oset kernel session
(let ((conn-info (jupyter-read-connection
(concat
(save-match-data
(file-remote-p default-directory))
(match-string 1)))))
(jupyter-session
:conn-info conn-info
:key (plist-get conn-info :key))))))

(defclass jupyter-spec-kernel (jupyter-kernel-process)
()
Expand Down

0 comments on commit 6be4f79

Please sign in to comment.