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

Add ";;guix pin" magic.

* guix-jupyter-kernel.scm (channels->shtml, reply-for-channels)
(reply-for-channel-failure): New procedures.
(reply-execute-request): Handle ";;guix pin".
(reply-complete-request): Complete ";;guix pin".
* guix-kernel-demo.ipynb: Add ";;guix pin" example.
parent aa57c901
......@@ -18,6 +18,7 @@
(use-modules (json)
(git) ;for 'git-error-message'
(srfi srfi-1)
(srfi srfi-13)
(srfi srfi-19)
......@@ -33,6 +34,7 @@
(guix build utils)
(guix gexp)
(guix store)
(guix channels)
(guix derivations)
(guix inferior)
(guix monads)
......@@ -164,6 +166,34 @@ NAME with MANIFEST."
("execution_count" . ,count))))
#:kernel-socket kernel-iopub))
(define (channels->shtml channels)
"Return SHTML representing CHANNELS."
(bold "Switched to these Guix channels:")
(p (table
,@(map (lambda (channel)
`(tr (tc (a (@ (href ,(channel-url channel)))
(code ,(channel-name channel))))
(tc (code ,(or (channel-commit channel)
(channel-branch channel))))))
(define* (reply-for-channels kernel message channels
#:key (count 0))
"Reply to MESSAGE, which comes from KERNEL, that we successfully switch to
(reply-html kernel message
(sxml->html-string (channels->shtml channels))
(define* (reply-for-channel-failure kernel message channels error
#:key (count 0))
"Send KERNEL a reply saying we failed to switch to CHANNELS."
(reply-html kernel message
(string-append "Failed to switch to channels: "
(git-error-message error) ".")
(define* (create-environment name specs state
#:key kernel message)
"Spawn a new execution environment called NAME and containing SPECS, a list
......@@ -286,6 +316,29 @@ stripped."
(send-message proxy (execute-request-sans-magic message))
(let ((state (increment-execution-count state)))
(set-proxy-state-default-environment state name)))))
((";;guix" "pin" commit)
(let ((count (proxy-state-execution-count state))
(channels (map (lambda (ch)
(if (guix-channel? ch)
(channel (inherit ch)
(commit commit))
(format/log "pinning to these channels: ~s~%" channels)
;; TODO: Send a message showing that something's happening.
(catch 'git-error
(lambda ()
(let ((inferior (inferior-for-channels channels)))
;; TODO: Obtain the <channel-instance> records so the message
;; can provide more info.
(reply-for-channels kernel message channels
#:count count)
(set-proxy-state-inferior (increment-execution-count state)
(lambda (key error . rest)
(reply-for-channel-failure kernel message channels error
#:count count)
((";;guix" _ ...)
(reply-html kernel message
......@@ -349,7 +402,7 @@ Return STATE."
;; This is a completion request on a ";;guix" magic.
(match (string-split (string-take first cursor) #\space)
((";;guix" command)
(send-completion-reply '("environment")
(send-completion-reply '("environment" "pin")
(- cursor (string-length command))
......@@ -27,6 +27,15 @@
"Create an environment called `guile-kernel` containing the Guile kernel for Jupyter:"
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
";;guix pin 36cc160e721a764c16f53c6f7fbd9d09c581717e"
"cell_type": "code",
"execution_count": null,
......@@ -212,7 +221,7 @@
"x = random.sample(range(1, 5000), 1000)\n",
"num_bins = 100\n",
"n, bins, patches = plt.hist(x, num_bins, facecolor='green', alpha=0.5)\n",
" \n",
"plt.title('Histogram Example')\n",
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