Commit ce48e279 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Strip magic commands before forwarding "execute_request" messages.

* guix-jupyter-kernel.scm (execute-request-sans-magic): New procedure.
(reply-execute-request): In ";;guix environment NAME" requests, call it.
parent c98bb877
......@@ -212,6 +212,20 @@ to KERNEL as a reply to MESSAGE, and return STATE suitably adjusted."
;; TODO: Send "error".
state))))
(define (execute-request-sans-magic message)
"Return MESSAGE, an 'execute_request' message, with its \";;guix\" magic
stripped."
(let* ((content (json-string->scm (message-content message)))
(code (assoc-ref content "code"))
(stripped (string-drop code
(or (string-index code #\newline)
(string-length code)))))
(set-message-content message
(scm->json-string
`(("code" . ,stripped)
,@(alist-delete "code" content))))))
(define (reply-execute-request kernel kind message state)
(let* ((content (message-content message))
(code (assoc-ref (json-string->scm content) "code"))
......@@ -248,7 +262,7 @@ to KERNEL as a reply to MESSAGE, and return STATE suitably adjusted."
((? kernel? proxy)
(format/log "evaluating code in container ~s (PID ~s)~%"
name (kernel-pid proxy))
(send-message proxy message)
(send-message proxy (execute-request-sans-magic message))
(let ((state (increment-execution-count state)))
(set-proxy-state-default-environment state name)))))
((";;guix" _ ...)
......
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