Commit 60fa602b authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

servers: Take <connection> records.

* jupyter/servers.scm (connection-file->kernel): Rename to...
(connection->kernel): ... this, and take a CONNECTION instead of a
(connection-file->kernel): Rewrite as a composition.
parent 3edceba2
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
(define-module (jupyter servers) (define-module (jupyter servers)
#:use-module (jupyter kernels) #:use-module (jupyter kernels)
#:use-module (jupyter messages)
#:use-module (simple-zmq) #:use-module (simple-zmq)
#:use-module (json) #:use-module (json)
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:export (connection-file->kernel)) #:export (connection->kernel
;;; Commentary: ;;; Commentary:
;;; ;;;
...@@ -31,34 +33,38 @@ ...@@ -31,34 +33,38 @@
;;; ;;;
;;; Code: ;;; Code:
(define* (connection-file->kernel port #:key (name "guix")) (define* (connection->kernel connection
"Read the contents of a Jupyter \"connection file\" from PORT and return a #:key
<kernel> record." (name "guix")
;; See <>. (context (zmq-create-context)))
(let* ((table (json->scm port)) "Return a <kernel> for a server connected to CONNECTION."
(ip (assoc-ref table "ip")) (define (port->uri port)
(scheme (assoc-ref table "transport")) (string-append (connection-transport connection) "://"
(key (assoc-ref table "key")) (connection-ip connection) ":"
(context (zmq-create-context))) (number->string port)))
(define (port->uri port)
(string-append scheme "://" ip ":" (define (make-socket type port)
(number->string port))) (let* ((uri (port->uri port))
(socket (zmq-create-socket context type)))
(zmq-bind-socket socket uri)
(define (make-socket type port) (kernel name (getpid)
(let* ((uri (port->uri port)) #:key (string->utf8 (connection-key connection))
(socket (zmq-create-socket context type))) #:control
(zmq-bind-socket socket uri) (make-socket ZMQ_ROUTER (connection-control-port connection))
socket)) #:shell
(make-socket ZMQ_ROUTER (connection-shell-port connection))
(make-socket ZMQ_ROUTER (connection-stdin-port connection))
(make-socket ZMQ_REP (connection-heartbeat-port connection))
(make-socket ZMQ_PUB (connection-iopub-port connection))))
(define connection-file->kernel
;; Read the contents of a Jupyter \"connection file\" from PORT and return a
;; <kernel> record.
;; See <>.
(compose connection->kernel json->connection json->scm))
(kernel name (getpid)
#:key (string->utf8 key)
(make-socket ZMQ_ROUTER (assoc-ref table "control_port"))
(make-socket ZMQ_ROUTER (assoc-ref table "shell_port"))
(make-socket ZMQ_ROUTER (assoc-ref table "stdin_port"))
(make-socket ZMQ_REP (assoc-ref table "hb_port"))
(make-socket ZMQ_PUB (assoc-ref table "iopub_port")))))
Markdown is supported
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