Commit 4c8895dd authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernels: Define <kernel-specs>.

* jupyter/kernels.scm (<kernel-specs>): New record type.
(kernel-arguments): Use 'json->kernel-specs' and 'kernel-specs-arguments'.
parent e581457e
;;; Guix-kernel -- Guix kernel for Jupyter ;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> ;;; Copyright (C) 2018, 2019 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
;;; Copyright (C) 2018, 2019 Ludovic Courtès <ludovic.courtes@inria.fr> ;;; Copyright (C) 2018, 2019 Ludovic Courtès <ludovic.courtes@inria.fr>
;;; ;;;
;;; This program is free software: you can redistribute it and/or modify ;;; This program is free software: you can redistribute it and/or modify
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
(define-module (jupyter kernels) (define-module (jupyter kernels)
#:use-module (jupyter messages) #:use-module (jupyter messages)
#:use-module (jupyter json)
#:use-module (guix build utils) #:use-module (guix build utils)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (ice-9 match) #:use-module (ice-9 match)
...@@ -29,6 +30,12 @@ ...@@ -29,6 +30,12 @@
#:export (find-kernel-by-name #:export (find-kernel-by-name
run-kernel run-kernel
kernel-specs?
kernel-specs-arguments
kernel-specs-display-name
kernel-specs-language
json->kernel-specs
kernel kernel
kernel? kernel?
kernel-name kernel-name
...@@ -78,6 +85,16 @@ ...@@ -78,6 +85,16 @@
(define-syntax kernel-iopub (identifier-syntax kernel-iosub)) (define-syntax kernel-iopub (identifier-syntax kernel-iosub))
;; Kernel metadata taken from a 'kernel.json' file.
;; <https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernel-specs>
(define-json-mapping <kernel-specs>
kernel-specs kernel-specs?
json->kernel-specs
(arguments kernel-specs-arguments "argv"
vector->list)
(display-name kernel-specs-display-name "display_name")
(language kernel-specs-language))
(define* (kernel name pid #:key key control shell (define* (kernel name pid #:key key control shell
standard-input heartbeat iosub) standard-input heartbeat iosub)
(%kernel name pid key (%kernel name pid key
...@@ -166,11 +183,11 @@ sockets." ...@@ -166,11 +183,11 @@ sockets."
(define (kernel-arguments kernel-file connection-file) (define (kernel-arguments kernel-file connection-file)
"Return the argument list read from KERNEL-FILE, substituting references to "Return the argument list read from KERNEL-FILE, substituting references to
'connection-file' with CONNECTION-FILE." 'connection-file' with CONNECTION-FILE."
(let ((alist (call-with-input-file kernel-file json->scm))) (let ((specs (call-with-input-file kernel-file json->kernel-specs)))
(map (match-lambda (map (match-lambda
("{connection_file}" connection-file) ("{connection_file}" connection-file)
(x x)) (x x))
(vector->list (assoc-ref alist "argv"))))) (kernel-specs-arguments specs))))
(define search-path->list (define search-path->list
(let ((not-colon (char-set-complement (char-set #\:)))) (let ((not-colon (char-set-complement (char-set #\:))))
......
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