Commit 1201d247 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Add (guix jupyter inner-proxy).

* guix-jupyter-container.scm: Rename to...
* guix/jupyter/inner-proxy.scm: ... this, and turn into a module.
* Makefile.am (SOURCES): Add 'inner-proxy.scm' and remove
'guix-jupyter-container.scm'.
* guix-jupyter-kernel.scm (container-path): Remove.
(start-container)[spawn]: Use (guix jupyter inner-proxy).
parent 24c8abfd
......@@ -23,6 +23,7 @@ godir=@guileobjectdir@
SOURCES = \
guix/jupyter/containers.scm \
guix/jupyter/environment.scm \
guix/jupyter/inner-proxy.scm \
guix/jupyter/kernel.scm \
guix/jupyter/logging.scm \
guix/jupyter/magic.scm \
......@@ -31,8 +32,7 @@ SOURCES = \
jupyter/messages.scm \
jupyter/kernels.scm \
jupyter/servers.scm \
guix-jupyter-kernel.scm \
guix-jupyter-container.scm
guix-jupyter-kernel.scm
assetsdir = $(datadir)/jupyter/kernels/guix/
nobase_nodist_assets_DATA = kernel.json
......
......@@ -56,10 +56,6 @@
(define container-context (zmq-create-context))
(define container-path
(string-replace (car (command-line)) "guix-jupyter-container.scm"
(+ (string-rindex (car (command-line)) #\/) 1)))
;;
;; HTML.
......@@ -214,16 +210,14 @@ that container."
(with-imported-modules (source-module-closure
'((guix profiles)
(guix search-paths)
(guix jupyter proxy)
(guix jupyter magic)
(guix jupyter logging)
(jupyter messages)
(jupyter kernels)
(jupyter servers))
(guix jupyter inner-proxy)
(jupyter kernels))
#:select? module-to-import?)
#~(begin
(use-modules (guix profiles)
(guix search-paths)
(guix jupyter inner-proxy)
(jupyter kernels) ;json->connection
(ice-9 match))
(format (current-error-port)
......@@ -246,11 +240,9 @@ that container."
value)))
(profile-search-paths #$profile))
(load #$(local-file container-path))
(run-inner-proxy #$name
#$(number->string session-id)
#$(scm->json-string
(connection->json connection)))))))
(let ((str #$(scm->json-string (connection->json connection))))
(run-inner-proxy #$(number->string session-id)
(json->connection str)))))))
(define-values (connection kernel)
(allocate-connection context "tcp" "127.0.0.1"
......
......@@ -16,23 +16,40 @@
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(use-modules (json)
(simple-zmq)
(srfi srfi-1)
(srfi srfi-13)
(srfi srfi-71)
(rnrs bytevectors)
(gcrypt base16)
(ice-9 match)
(sxml simple)
(jupyter messages)
(jupyter kernels)
(jupyter servers)
(guix jupyter logging)
(guix jupyter proxy)
(guix jupyter magic))
(define-module (guix jupyter inner-proxy)
#:use-module (json)
#:use-module (simple-zmq)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-13)
#:use-module (srfi srfi-71)
#:use-module (rnrs bytevectors)
#:use-module (gcrypt base16)
#:use-module (ice-9 match)
#:use-module (sxml simple)
#:use-module (jupyter messages)
#:use-module (jupyter kernels)
#:use-module (jupyter servers)
#:use-module (guix jupyter logging)
#:use-module (guix jupyter proxy)
#:use-module (guix jupyter magic)
#:export (run-inner-proxy))
;;; Commentary:
;;;
;;; This module implements the "inner kernel proxy". The inner proxy runs
;;; isolated in a container and its client is the Guix kernel.
;;;
;;; The inner proxy may spawn other Jupyter kernels as a result of a ";;guix
;;; kernel" magic line; it then forwards requests coming from the Guix kernel
;;; to the kernels that it launched.
;;;
;;; Alternately, lacking a ";;guix kernel" magic, the inner proxy evaluates
;;; Guile code directly, thereby acting as a Guile kernel.
;;;
;;; Code:
;; ZeroMQ context.
;; FIXME: Avoid doing that at the top level.
(define %context (zmq-create-context))
;;
......@@ -217,9 +234,9 @@ stripped."
;; Run.
;;
(define (run-inner-proxy name session-id connection)
(let* ((connection (json->connection (json-string->scm connection)))
(kernel (connection->kernel connection
(define (run-inner-proxy session-id connection)
"Run an inner for SESSION-ID, with its client at CONNECTION."
(let* ((kernel (connection->kernel connection
#:context %context))
(state (proxy-state kernel)))
(format/log "started proxy as PID ~a~%" (getpid))
......
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