Commit 9bc905e1 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Simplify 'exec-kernel' and friends.

* guix-kernel/jupyter-server.scm (get-argv-from-file): Rename to...
(kernel-arguments): ... this; rewrite.
(exec-kernel): Simplify.
parent 2212fb1c
......@@ -97,20 +97,14 @@ could not be found."
(test-bind socket (+ port 1)))
(else #f))))))
(define (get-argv-from-file name kernel-file conn-file)
(define (subsitute-conn-file argv)
(cond
((null? argv) '())
((equal? (car argv) "{connection_file}")
(cons conn-file
(subsitute-conn-file (cdr argv))))
(else
(cons (car argv)
(subsitute-conn-file (cdr argv))))))
(let* ((table (call-with-input-file kernel-file json->scm))
(argv (hash-ref table "argv")))
(subsitute-conn-file argv)))
(define (kernel-arguments kernel-file connection-file)
"Return the argument list read from KERNEL-FILE, substituting references to
'connection-file' with CONNECTION-FILE."
(let ((table (call-with-input-file kernel-file json->scm)))
(map (match-lambda
("{connection_file}" connection-file)
(x x))
(hash-ref table "argv"))))
(define search-path->list
(let ((not-colon (char-set-complement (char-set #\:))))
......@@ -119,28 +113,26 @@ could not be found."
((? string? str)
(string-tokenize str not-colon)))))
(define (exec-kernel name conn-file)
(define (execk argv)
(let ((pid (primitive-fork)))
(if (zero? pid)
(apply execl (car argv) argv)
pid)))
(define (get-argv)
(cond
((equal? name "ipython")
;; IPython does not provide a 'kernel.json' file like other kernels
;; do; instead, we need to execute 'ipython' from $PATH.
(let ((ipython (search-path (search-path->list (getenv "PATH"))
"ipython")))
(list ipython "kernel" "--quiet" "-f" conn-file)))
(else
(let ((argv (get-argv-from-file name
(find-kernel-by-name name)
conn-file)))
argv))))
(execk (get-argv)))
(define (exec-kernel kernel connection-file)
"Execute KERNEL as a separate process, passing it CONNECTION-FILE, and
return its PID."
(define arguments
(cond ((string=? kernel "ipython")
;; IPython does not provide a 'kernel.json' file like other
;; kernels do; instead, we need to execute 'ipython' from $PATH.
(let ((ipython (search-path (search-path->list (getenv "PATH"))
"ipython")))
(list ipython "kernel" "--quiet" "-f" connection-file)))
(else
(kernel-arguments (find-kernel-by-name kernel)
connection-file))))
(let ((pid (primitive-fork)))
(if (zero? pid)
(match arguments
((command . _)
(apply execl command arguments)))
pid)))
(define (run-kernel context name uuid key)
(let* ((socket-control (zmq-create-socket context ZMQ_DEALER))
......
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