mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 07:41:37 -05:00
jupyter-start-kernel (jupyter-command-kernel): Directly use Jupyter's python
instead of relying on the `jupyter kernel` command
This commit is contained in:
parent
258d1edfdb
commit
099d2b6511
2 changed files with 34 additions and 1 deletions
|
@ -689,6 +689,33 @@ the ROUTING-ID of the socket. Return the created socket."
|
|||
(let ((json-object-type 'plist))
|
||||
(json-read-from-string string)))
|
||||
|
||||
(defun jupyter-locate-python ()
|
||||
"Return the path to the python executable in use by Jupyter.
|
||||
Examines the data paths of \"jupyter --paths\" in the order
|
||||
specified."
|
||||
(let* ((remote (file-remote-p default-directory))
|
||||
(paths (mapcar (lambda (x) (concat remote x))
|
||||
(or (plist-get
|
||||
(jupyter-read-plist-from-string
|
||||
(jupyter-command "--paths" "--json"))
|
||||
:data)
|
||||
(error "Can't get search paths"))))
|
||||
(path nil))
|
||||
(cl-loop
|
||||
with programs = '("bin/python3" "bin/python"
|
||||
;; Need to also check Windows since paths can be
|
||||
;; pointing to local or remote files.
|
||||
"python3.exe" "python.exe")
|
||||
with pred = (lambda (dir)
|
||||
(cl-loop
|
||||
for program in programs
|
||||
for spath = (expand-file-name program dir)
|
||||
thereis (setq path (and (file-exists-p spath) spath))))
|
||||
for path in paths
|
||||
thereis (locate-dominating-file path pred)
|
||||
finally (error "No `python' found in search paths"))
|
||||
path))
|
||||
|
||||
(defun jupyter-normalize-data (plist &optional metadata)
|
||||
"Return a list (DATA META) from PLIST.
|
||||
DATA is a property list of mimetype data extracted from PLIST. If
|
||||
|
|
|
@ -175,8 +175,14 @@ fatal signal."
|
|||
The --kernel argument of \"jupyter kernel\" is filled in with the
|
||||
`jupyter-kernel-name' of KERNEL and passed as the first
|
||||
argument of the process."
|
||||
;; NOTE: On Windows, apparently the "jupyter kernel" command also launches a
|
||||
;; new process to start the kernel using something like an exec command, but
|
||||
;; exec like commands on Windows launch a new process instead of replacing
|
||||
;; the current one which results in the process we start here returning after
|
||||
;; the new process is launched. We call python directly to avoid this.
|
||||
(apply #'cl-call-next-method
|
||||
kernel "jupyter" "kernel"
|
||||
kernel (jupyter-locate-python)
|
||||
"-c" "from jupyter_client.kernelapp import main; main()"
|
||||
(format "--kernel=%s" (jupyter-kernel-name kernel))
|
||||
args))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue