Skip to content

Commit

Permalink
Add jupyter-refresh-kernelspecs command
Browse files Browse the repository at this point in the history
* jupyter-kernelspec.el (jupyter-kernelspecs): Mention REFRESH
argument in documentation.
(jupyter-do-refresh-kernelspecs): New method that does the work of
refreshing the kernelspecs.
(jupyter-refresh-kernelspecs): New interactive command that calls the method.

* ob-jupyter.el (jupyter-do-refresh-kernelspecs): New method
definition for Org specific contexts.

closes #507
  • Loading branch information
nnicandro committed Dec 4, 2023
1 parent e237ff0 commit 42626c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
18 changes: 17 additions & 1 deletion jupyter-kernelspec.el
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,28 @@ why it isn't returning valid JSON."))))
kernelspecs))

(cl-defgeneric jupyter-kernelspecs (host &optional refresh)
"Return a list of kernelspecs on HOST.")
"Return a list of kernelspecs on HOST.
If REFRESH is non-nil, then refresh the list of cached
kernelspecs first. Otherwise a cached version of the kernelspecs
may be returned.")

(cl-defmethod jupyter-kernelspecs ((host string) &optional refresh)
(let ((default-directory host))
(jupyter-available-kernelspecs refresh)))

(cl-defmethod jupyter-do-refresh-kernelspecs ()
(jupyter-kernelspecs default-directory 'refresh))

;;;###autoload
(defun jupyter-refresh-kernelspecs ()
"Refresh the list of available kernelspecs.
Execute this command if the kernelspecs seen by Emacs is out of
sync with those specified on your system or notebook server."
(interactive)
(message "Refreshing kernelspecs...")
(jupyter-do-refresh-kernelspecs)
(message "Refreshing kernelspecs...done"))

(defun jupyter-get-kernelspec (name &optional specs refresh)
"Get the kernelspec for a kernel named NAME.
If no kernelspec is found, return nil. Otherwise return the
Expand Down
13 changes: 12 additions & 1 deletion ob-jupyter.el
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ the host."
(setq session (org-babel-read session)))
(org-babel-jupyter-initiate-session-by-key session params)))

;;;; `org-babel-execute:jupyter'
;;;; Helper functions

;;;###autoload
(defun org-babel-jupyter-scratch-buffer ()
Expand All @@ -430,6 +430,17 @@ the host."
(if buffer (pop-to-buffer buffer)
(user-error "No source block at point"))))

(cl-defmethod jupyter-do-refresh-kernelspecs (&context (major-mode org-mode))
(or (jupyter-org-when-in-src-block
(let* ((info (org-babel-get-src-block-info 'light))
(params (nth 2 info))
(session (org-babel-read (alist-get :session params))))
(when (file-remote-p session)
(jupyter-kernelspecs session 'refresh))))
(cl-call-next-method)))

;;;; `org-babel-execute:jupyter'

(defvar org-bracket-link-regexp)

(defun org-babel-jupyter-cleanup-file-links ()
Expand Down

0 comments on commit 42626c8

Please sign in to comment.