unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Luciana Lima Brito <lubrito@posteo.net>
To: Christopher Baines <mail@cbaines.net>
Cc: guix-devel@gnu.org
Subject: Re: Outreachy - Guix Data Service: implementing basic json output for derivation comparison page
Date: Fri, 16 Apr 2021 22:47:35 +0000	[thread overview]
Message-ID: <20210416194735.0f4ccaed@lubrito> (raw)
In-Reply-To: <87a6pyxcme.fsf@cbaines.net>

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

On Fri, 16 Apr 2021 20:17:45 +0100
Christopher Baines <mail@cbaines.net> wrote:

Hi,

I hope the patch is correct this time.
I considered all you said, so I separated the
functions to get outputs, inputs and sources. I also implemented
everything inside the case of the json/application.

> While a flatter list is what you want when building an HTML table, I
> think you were looking to get a JSON object separating the common,
> base and target elements, right? If so, then map, rather than
> append-map should be more useful to you here. Since above you're
> passing in two lists of three things, if the procedure passed to map
> returns a pair with a string in the first position, you'll end up
> producing the scheme version of a JSON object (an alist).

You were right about that, I'm using map now.

Please, let me know if I missed something.
Thanks in advance, I'm learning a great deal! :)
-- 
Best Regards,

Luciana Lima Brito
MSc. in Computer Science
Federal University of Uberlândia

[-- Attachment #2: 0001-Implement-basic-json-output-for-the-derivation-compa.patch --]
[-- Type: text/x-patch, Size: 7404 bytes --]

From b51dd007180e69f7da479a857afd48dfa60e32e7 Mon Sep 17 00:00:00 2001
From: Luciana Brito <lubrito@posteo.net>
Date: Sun, 11 Apr 2021 11:06:06 -0300
Subject: [PATCH] Implement basic json output for the derivation comparison
 page

---
 guix-data-service/web/compare/controller.scm | 122 ++++++++++++++++++-
 1 file changed, 119 insertions(+), 3 deletions(-)

diff --git a/guix-data-service/web/compare/controller.scm b/guix-data-service/web/compare/controller.scm
index a6aa198..1b0fc2f 100644
--- a/guix-data-service/web/compare/controller.scm
+++ b/guix-data-service/web/compare/controller.scm
@@ -588,9 +588,125 @@
                  '(application/json text/html)
                  mime-types)
             ((application/json)
-             (render-json
-              '((error . "unimplemented")) ; TODO
-              #:extra-headers http-headers-for-unchanging-content))
+             (let* ((outputs (assq-ref data 'outputs))
+                    (matched-outputs
+                     (map
+                      (lambda (label items)
+                        (cons label
+                              (map
+                               (match-lambda
+                                 ((name path hash-alg hash recursive)
+                                  `(,@(if (null? name)
+                                          '()
+                                          `((name . ,name)))
+                                    ,@(if (null? path)
+                                          '()
+                                          `((path . ,path))
+                                          )
+                                    ,@(if (or (null? hash-alg) (not (string? hash-alg)))
+                                          '()
+                                          `((hash-algorithm . ,hash-alg))
+                                          )
+                                    ,@(if (or (null? hash) (not (string? hash)))
+                                          '()
+                                          `((hash . ,hash))
+                                          )
+                                    ,@(if (null? recursive)
+                                          '()
+                                          `((recursive . ,(string=? recursive "t")))))))
+                               (or items '()))))
+                      (list "base" "target" "common")
+                      (list (assq-ref outputs 'base)
+                            (assq-ref outputs 'target)
+                            (assq-ref outputs 'common))))
+                    (base-outputs (list->vector (cdr (first matched-outputs))))
+                    (target-outputs (list->vector (cdr (second matched-outputs))))
+                    (common-outputs (list->vector (cdr (third matched-outputs))))
+
+                    (inputs  (assq-ref data 'inputs))
+                    (matched-inputs
+                     (map
+                      (lambda (label items)
+                        (cons label
+                              (map 
+                               (match-lambda
+                                 ((derivation output)
+                                  `(,@(if (null? derivation)
+                                          '()
+                                          `((derivation . ,derivation)))
+                                    ,@(if (null? output)
+                                          '()
+                                          `((output . ,output))))))
+                               (or items '()))))
+                      (list "base" "target" "common")
+                      (list (assq-ref inputs 'base)
+                            (assq-ref inputs 'target))))
+                    (base-inputs (list->vector (cdr (first matched-inputs))))
+                    (target-inputs (list->vector (cdr (second matched-inputs))))
+                    
+                    (sources (assq-ref data 'sources))
+                    (matched-sources
+                     (map
+                      (lambda (label items)
+                        (cons label
+                              (map
+                               (match-lambda
+                                 ((derivation)
+                                  `(,@(if (null? derivation)
+                                          '()
+                                          `((derivation . ,derivation))))))
+                               (or items '())))) 
+                      (list "base" "target" "common")
+                      (list (assq-ref sources 'base)
+                            (assq-ref sources 'target)
+                            (assq-ref sources 'common))))
+                    (base-sources (list->vector (cdr (first matched-sources))))
+                    (target-sources (list->vector (cdr (second matched-sources))))
+                    (common-sources (list->vector (cdr (third matched-sources))))
+                    
+                    (system  (assq-ref data 'system))
+                    (base-system (assq-ref system 'base))
+                    (target-system (assq-ref system 'target))
+                    (common-system (assq-ref system 'common))
+                    
+                    (builder (assq-ref data 'builder))
+                    (base-builder (assq-ref builder 'base))
+                    (target-builder (assq-ref builder 'target))
+                    (common-builder (assq-ref builder 'common))
+                    
+                    (args    (assq-ref data 'arguments))
+                    (base-args (assq-ref args 'base))
+                    (target-args (assq-ref args 'target))
+                    (common-args (assq-ref args 'common))
+                    (environment-variables (assq-ref data 'environment-variables)))
+               
+               (render-json
+                `((base
+                   . ((derivation . ,base-derivation)))
+                  (target
+                   . ((derivation . ,target-derivation)))
+                  (outputs
+                   . ((,(first (first matched-outputs)) . ,base-outputs)
+                      (,(first (second matched-outputs)) . ,target-outputs)
+                      (,(first (third matched-outputs)) . ,common-outputs)))
+                  (inputs
+                   . ((,(first (first matched-inputs)) . ,base-inputs)
+                      (,(first (second matched-inputs)) . ,target-inputs)))
+                  (sources                   
+                   . ((,(first (first matched-sources)) . ,base-sources)
+                      (,(first (second matched-sources)) . ,target-sources)
+                      (,(first (third matched-sources)) . ,common-sources)))
+                  (system
+                   . ((common . ,common-system)))
+                  (builder-and-arguments
+                   . ((builder . ,common-builder)
+                      (arguments
+                       . ((base . ,(list->vector
+                                    base-args))
+                          (target . ,(list->vector
+                                      target-args))))))
+                  (environment-variables . ,environment-variables))
+                #:extra-headers http-headers-for-unchanging-content)))
             (else
              (render-html
               #:sxml (compare/derivation
-- 
2.30.2


  reply	other threads:[~2021-04-16 22:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 19:48 Outreachy - Guix Data Service: implementing basic json output for derivation comparison page Luciana Lima Brito
2021-04-15  8:46 ` Christopher Baines
2021-04-15 16:09   ` Luciana Lima Brito
2021-04-15 23:19     ` Christopher Baines
2021-04-16 15:07       ` Luciana Lima Brito
2021-04-16 15:47         ` Christopher Baines
2021-04-16 18:46           ` Luciana Lima Brito
2021-04-16 19:17             ` Christopher Baines
2021-04-16 22:47               ` Luciana Lima Brito [this message]
2021-04-17  8:40                 ` Christopher Baines
2021-04-17 12:48                   ` Luciana Lima Brito
2021-04-17 13:11                     ` Christopher Baines
2021-04-17 14:08                       ` Luciana Lima Brito
2021-04-17 17:45                         ` Christopher Baines
2021-04-18 13:12                           ` Luciana Lima Brito
2021-04-18 13:19                             ` Luciana Lima Brito
2021-04-18 16:34                             ` Christopher Baines
2021-04-18 19:12                               ` Luciana Lima Brito
2021-04-19  8:26                                 ` Christopher Baines
2021-04-19 14:04                                   ` Luciana Lima Brito
2021-04-19 20:20                                     ` Christopher Baines
2021-04-19 20:56                                       ` Luciana Lima Brito

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416194735.0f4ccaed@lubrito \
    --to=lubrito@posteo.net \
    --cc=guix-devel@gnu.org \
    --cc=mail@cbaines.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).