Commit 2212fb1c authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Don't rely on $JUPYTER_PATH when searching for kernels.

Fixes a regression introduced in
cd370ab1 whereby kernels other than
ipython would not be found because JUPYTER_PATH was unset.

* guix-kernel/jupyter-server.scm (jupyter-kernel-path): New procedure.
(find-kernel-by-name): Rewrite and search in (jupyter-kernel-path) by
* guix-kernel/environ.scm (env-profile->str): Remove.
(make-new-environment): Set 'GUIX_PROFILE'.
parent 9754f37a
......@@ -117,9 +117,6 @@
(string-append (string-upcase name) "="
(if (not value) "" value)))
(define (env-profile->str name profile suffix)
(env->str name (string-append profile suffix)))
(define (make-new-environment environ name packages)
(let* ((home (env->str "HOME" (getenv "HOME")))
(user (env->str "USER" (getenv "USER")))
......@@ -137,6 +134,7 @@
(paths (profile-search-paths profile)))
;; List of environment variables.
(cons* home user logname term pwd pager shell ps1 jenv
(string-append "GUIX_PROFILE=" profile)
(map (match-lambda
((spec . value)
(env->str (search-path-specification-variable spec)
......@@ -24,6 +24,8 @@
#:use-module (ice-9 match)
#:use-module (simple-zmq)
#:use-module (json)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (find-kernel-by-name
......@@ -31,25 +33,27 @@
;; Kernel execution.
(define (find-kernel-by-name name)
(define (multi-path lst)
((null? lst) #f)
((file-exists? (string-append (car lst)
"/kernels/" name
(string-append (car lst) "/kernels/" name
(else (multi-path (cdr lst)))))
(let ((jpath (getenv "JUPYTER_PATH")))
((not (string? name)) #f)
((not (string? jpath)) #f)
(let* ((jpath-lst (string-split jpath #\:)))
(multi-path jpath-lst))))))
(define (jupyter-kernel-path)
"Return the default search path for Jupyter kernels."
;; Note: In container environments, 'JUPYTER_PATH' is typically unset
;; (because Jupyter itself is not in the environment) but 'GUIX_PROFILE' is
;; set.
(or (and=> (getenv "JUPYTER_PATH")
(cut string-split <> #\:))
(and=> (getenv "GUIX_PROFILE")
(lambda (profile)
(list (string-append profile "/share/jupyter"))))))
(define* (find-kernel-by-name kernel
#:optional (path (jupyter-kernel-path)))
"Return the absolute file name of the 'kernel.json' file for Jupyter kernel
KERNEL, searched for in PATH, a list of directories. Return #f if KERNEL
could not be found."
(any (lambda (directory)
(let ((json (string-append directory "/kernels/"
kernel "/kernel.json")))
(and (file-exists? json) json)))
;; Running procedure.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment