Commit 81d3619b authored by ROUBY Pierre-Antoine's avatar ROUBY Pierre-Antoine
Browse files

guix-kernel: Add modules jupyter-client.

* guix-kernel/jupyter-client.scm: New file.
* guix-jupyter-container.scm: Use module 'guix-kernel jupyter-client'.
* guix-jupyter-kernel.scm: Use module 'guix-kernel jupyter-client'.
* Makefile.am: Add 'guix-kernel/jupyter-client.scm' to SOURCE.
parent 180ff53e
......@@ -24,6 +24,7 @@ SOURCES = \
guix-kernel/hmac.scm \
guix-kernel/tools.scm \
guix-kernel/magic.scm \
guix-kernel/jupyter-client.scm \
guix-jupyter-kernel.scm \
guix-jupyter-container.scm
......
......@@ -22,38 +22,20 @@
(srfi srfi-13)
(guix-kernel tools)
(guix-kernel hmac)
(guix-kernel magic))
(guix-kernel magic)
(guix-kernel jupyter-client))
;;
;; Kernel information.
;;
(define guile-version (effective-version))
(define DELIM "<IDS|MSG>")
(define KERNEL-INFO `(("protocol_version" . "5.3.0")
("implementation" . "Guix Jupyter kernel")
("implementation_version" . "0.0.2")
("language_info" .
(("name" . "guile")
("version" . ,guile-version)
("mimetype" . "application/x-scheme")
("file_extension" . ".scm")
("pygments_lexer" . "scheme")
("codemirror_mode" . "scheme")))
("banner" . "Guix kernel")
("help_links" .
(("Gitlab Inria" .
"https://gitlab.inria.fr/guix-hpc/guix-kernel")))))
(define name
(list-ref (command-line) (- (length (command-line)) 2)))
(define full-name
(string-append name "-" (number->string (getpid))))
(define notebook-info-key
(define notebook-key
(car (last-pair (command-line))))
;;
......@@ -75,31 +57,6 @@
(zmq-connect socket-shell addr-shell)
;;
;; Send.
;;
(define (send socket uuid header parent-header metadata content)
(let ((signature (get-signature notebook-info-key
(string-append header
parent-header
metadata
content))))
(zmq-send-msg-parts socket
(list uuid DELIM signature
header parent-header
metadata content))))
(define (pub header- state parent-header)
(send socket-shell "" (header- "status") parent-header "{}"
(scm->json-string `(("execution_state" . ,state)))))
(define (pub-busy header- parent-header)
(pub header- "busy" parent-header))
(define (pub-idle header- parent-header)
(pub header- "idle" parent-header))
;;
;; Handler.
;;
......@@ -171,10 +128,11 @@
stacktrace result))))))
(let ((send- (lambda (socket msg-type content)
(send socket uuid
(header- msg-type)
parent-header metadata
(scm->json-string content)))))
(send-to-jupyter socket uuid
(header- msg-type)
parent-header metadata
(scm->json-string content)
notebook-key))))
(send- socket
"execute_input" `(("code" . ,code)
("execution_count" . ,counter)))
......
......@@ -25,30 +25,8 @@
(guix-kernel tools)
(guix-kernel hmac)
(guix-kernel magic)
(guix-kernel environ))
;;
;; Kernel information.
;;
(define guile-version (effective-version))
(define DELIM "<IDS|MSG>")
(define KERNEL-INFO `(("protocol_version" . "5.3.0")
("implementation" . "Guix Jupyter kernel")
("implementation_version" . "0.0.2")
("language_info" .
(("name" . "guile")
("version" . ,guile-version)
("mimetype" . "application/x-scheme")
("file_extension" . ".scm")
("pygments_lexer" . "scheme")
("codemirror_mode" . "scheme")))
("banner" . "Guix kernel")
("help_links" .
(("Gitlab Inria" .
"https://gitlab.inria.fr/guix-hpc/guix-kernel")))))
(guix-kernel environ)
(guix-kernel jupyter-client))
;;
;; Notebook information.
......@@ -160,27 +138,6 @@
(define (send-to-container containers socket name parts)
(zmq-send-msg-parts socket (append (list name) parts)))
(define (send socket uuid header parent-header metadata content)
(let ((signature (get-signature notebook-info-key
(string-append header
parent-header
metadata
content))))
(zmq-send-msg-parts socket
(list uuid DELIM signature
header parent-header
metadata content))))
(define (pub header- state parent-header)
(send socket-iopub "" (header- "status") parent-header "{}"
(scm->json-string `(("execution_state" . ,state)))))
(define (pub-busy header- parent-header)
(pub header- "busy" parent-header))
(define (pub-idle header- parent-header)
(pub header- "idle" parent-header))
(define (proxy-exec-container containers name parts count)
(let ((socket (container-socket-by-name containers name)))
;; Send Jupyter command tu default container.
......@@ -223,13 +180,15 @@
(msg-session (hash-ref wire-header "session"))
(msg-version (hash-ref wire-header "version"))
(header- (make-header msg-username msg-session msg-version)))
(pub-busy header- (scm->json-string wire-header))
(pub-busy socket-iopub header- (scm->json-string wire-header)
notebook-info-key)
(let-values (((containers count) ((dispatch msg-type) socket wire-uuid
header- wire-parent-header
(scm->json-string wire-metadata)
wire-content parts
containers count)))
(pub-idle header- (scm->json-string wire-header))
(pub-idle socket-iopub header- (scm->json-string wire-header)
notebook-info-key)
(general-handler socket containers count))))
;; Unknown request type, ignore it.
......@@ -242,8 +201,9 @@
(define (reply-kernel-info-request socket uuid header- parent-header
metadata content parts containers
count)
(send socket uuid (header- "kernel_info_reply")
parent-header metadata (scm->json-string KERNEL-INFO))
(send-to-jupyter socket uuid (header- "kernel_info_reply")
parent-header metadata (scm->json-string KERNEL-INFO)
notebook-info-key)
(values containers
count))
......
;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(define-module (guix-kernel jupyter-client)
#:use-module (guix-kernel hmac)
#:use-module (simple-zmq)
#:use-module (json)
#:export (guile-version
DELIM
KERNEL-INFO
send-to-jupyter
pub-busy
pub-idle))
;;
;; Kernel information.
;;
(define guile-version (effective-version))
(define DELIM "<IDS|MSG>")
(define KERNEL-INFO
`(("protocol_version" . "5.3.0")
("implementation" . "Guix Jupyter kernel")
("implementation_version" . "0.0.2")
("language_info" .
(("name" . "guile")
("version" . ,guile-version)
("mimetype" . "application/x-scheme")
("file_extension" . ".scm")
("pygments_lexer" . "scheme")
("codemirror_mode" . "scheme")))
("banner" . "Guix kernel")
("help_links" .
(("Gitlab Inria" .
"https://gitlab.inria.fr/guix-hpc/guix-kernel")))))
;;
;; Send procedures.
;;
(define (send-to-jupyter socket uuid header parent-header
metadata content key)
(let ((signature (get-signature key
(string-append header
parent-header
metadata
content))))
(zmq-send-msg-parts socket
(list uuid DELIM signature
header parent-header
metadata content))))
(define (pub socket header- state parent-header key)
(send-to-jupyter socket "" (header- "status") parent-header "{}"
(scm->json-string `(("execution_state" . ,state)))
key))
(define (pub-busy socket header- parent-header key)
(pub socket header- "busy" parent-header key))
(define (pub-idle socket header- parent-header key)
(pub socket header- "idle" parent-header key))
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