Add jupyter-read-connection

* jupyter-base.el (jupyter-read-connection): New function.

* jupyter-kernel-process-manager.el
(jupyter-start-kernel) [jupyter-command-kernel]: Use it.
This commit is contained in:
Nathaniel Nicandro 2020-04-05 19:23:26 -05:00
parent c36f6fd63a
commit 6be4f79ab3
2 changed files with 26 additions and 8 deletions

View file

@ -529,6 +529,23 @@ Note only SSH tunnels are currently supported."
(jupyter-make-ssh-tunnel lport maybe-rport server remoteip))) (jupyter-make-ssh-tunnel lport maybe-rport server remoteip)))
else collect maybe-rport))))) 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 ;;; Helper functions
(defun jupyter-canonicalize-language-string (str) (defun jupyter-canonicalize-language-string (str)

View file

@ -151,14 +151,15 @@ argument of the process."
:wait-form (and (process-live-p (oref kernel process)) :wait-form (and (process-live-p (oref kernel process))
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "Connection file: \\(.+\\)\n" nil t)) (re-search-forward "Connection file: \\(.+\\)\n" nil t))
(let* ((conn-file (match-string 1)) (oset kernel session
(remote (file-remote-p default-directory)) (let ((conn-info (jupyter-read-connection
(conn-info (if remote (jupyter-tunnel-connection (concat
(concat remote conn-file)) (save-match-data
(jupyter-read-plist conn-file)))) (file-remote-p default-directory))
(oset kernel session (jupyter-session (match-string 1)))))
:conn-info conn-info (jupyter-session
:key (plist-get conn-info :key)))))) :conn-info conn-info
:key (plist-get conn-info :key))))))
(defclass jupyter-spec-kernel (jupyter-kernel-process) (defclass jupyter-spec-kernel (jupyter-kernel-process)
() ()