all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#33448] [PATCH] describe: Fix 'format' option.
@ 2018-11-20 22:26 Oleg Pykhalov
  2018-11-21  7:00 ` [bug#33448] [PATCH] describe: Add json format Oleg Pykhalov
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-20 22:26 UTC (permalink / raw)
  To: 33448

Fix ‘guix describe’ ignores ‘--format=FORMAT’ option.

* guix/scripts/describe.scm (%options): Fix 'format' option.
---
 guix/scripts/describe.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index e59502076..d3203e992 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -40,7 +40,7 @@
                 (lambda (opt name arg result)
                   (unless (member arg '("human" "channels"))
                     (leave (G_ "~a: unsupported output format~%") arg))
-                  (alist-cons 'format 'channels result)))
+                  (alist-cons 'format (string->symbol arg) result)))
         (option '(#\h "help") #f #f
                 (lambda args
                   (show-help)
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Add json format.
  2018-11-20 22:26 [bug#33448] [PATCH] describe: Fix 'format' option Oleg Pykhalov
@ 2018-11-21  7:00 ` Oleg Pykhalov
  2018-11-21 10:53   ` Ludovic Courtès
  2018-11-21 10:47 ` [bug#33448] [PATCH] describe: Fix 'format' option Ludovic Courtès
  2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
  2 siblings, 1 reply; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21  7:00 UTC (permalink / raw)
  To: 33448

* guix/scripts/describe.scm: Add json format.
---
 guix/scripts/describe.scm | 69 +++++++++++++++++++++++++--------------
 1 file changed, 44 insertions(+), 25 deletions(-)

diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index d3203e992..53195b423 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -23,6 +23,7 @@
   #:use-module (guix profiles)
   #:use-module ((guix scripts pull) #:select (display-profile-content))
   #:use-module (git)
+  #:use-module (json)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-37)
   #:use-module (ice-9 match)
@@ -38,7 +39,7 @@
   ;; Specifications of the command-line options.
   (list (option '(#\f "format") #t #f
                 (lambda (opt name arg result)
-                  (unless (member arg '("human" "channels"))
+                  (unless (member arg '("human" "channels" "json"))
                     (leave (G_ "~a: unsupported output format~%") arg))
                   (alist-cons 'format (string->symbol arg) result)))
         (option '(#\h "help") #f #f
@@ -101,7 +102,12 @@ within a Git checkout."
        (pretty-print `(list (channel
                              (name 'guix)
                              (url ,(dirname directory))
-                             (commit ,commit))))))
+                             (commit ,commit)))))
+      ('json
+       (display (scm->json-string `((name . guix)
+                                    (url . ,(dirname directory))
+                                    (commit . ,commit))))
+       (newline)))
     (display-package-search-path fmt)))
 
 (define (display-profile-info profile fmt)
@@ -110,34 +116,47 @@ in the format specified by FMT."
   (define number
     (generation-number profile))
 
+  (define (channels format)
+    (map (lambda (entry)
+           (match (assq 'source (manifest-entry-properties entry))
+             (('source ('repository ('version 0)
+                                    ('url url)
+                                    ('branch branch)
+                                    ('commit commit)
+                                    _ ...))
+              (case format
+                ((scm)
+                 `(channel (name ',(string->symbol
+                                    (manifest-entry-name entry)))
+                           (url ,url)
+                           (commit ,commit)))
+                ((json)
+                 `((name . ,(string->symbol
+                             (manifest-entry-name entry)))
+                   (url . ,url)
+                   (commit . ,commit)))))
+
+             ;; Pre-0.15.0 Guix does not provide that information,
+             ;; so there's not much we can do in that case.
+             (_ '???)))
+
+         ;; Show most recently installed packages last.
+         (reverse
+          (manifest-entries
+           (profile-manifest
+            (if (zero? number)
+                profile
+                (generation-file-name profile number)))))))
+
   (match fmt
     ('human
      (display-profile-content profile number))
     ('channels
      (pretty-print
-      `(list ,@(map (lambda (entry)
-                      (match (assq 'source (manifest-entry-properties entry))
-                        (('source ('repository ('version 0)
-                                               ('url url)
-                                               ('branch branch)
-                                               ('commit commit)
-                                               _ ...))
-                         `(channel (name ',(string->symbol
-                                            (manifest-entry-name entry)))
-                                   (url ,url)
-                                   (commit ,commit)))
-
-                        ;; Pre-0.15.0 Guix does not provide that information,
-                        ;; so there's not much we can do in that case.
-                        (_ '???)))
-
-                    ;; Show most recently installed packages last.
-                    (reverse
-                     (manifest-entries
-                      (profile-manifest
-                       (if (zero? number)
-                           profile
-                           (generation-file-name profile number))))))))))
+      `(list ,@(channels 'scm))))
+    ('json
+     (display (scm->json-string (channels 'json)))
+     (newline)))
   (display-package-search-path fmt))
 
 \f
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Fix 'format' option.
  2018-11-20 22:26 [bug#33448] [PATCH] describe: Fix 'format' option Oleg Pykhalov
  2018-11-21  7:00 ` [bug#33448] [PATCH] describe: Add json format Oleg Pykhalov
@ 2018-11-21 10:47 ` Ludovic Courtès
  2018-11-21 11:46   ` Oleg Pykhalov
  2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
  2 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 10:47 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> Fix ‘guix describe’ ignores ‘--format=FORMAT’ option.
>
> * guix/scripts/describe.scm (%options): Fix 'format' option.

Oops, good catch.  LGTM!

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Add json format.
  2018-11-21  7:00 ` [bug#33448] [PATCH] describe: Add json format Oleg Pykhalov
@ 2018-11-21 10:53   ` Ludovic Courtès
  2018-11-21 14:10     ` Oleg Pykhalov
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 10:53 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> * guix/scripts/describe.scm: Add json format.

Please describe the modified and added variables/procedures.

> +  (define (channels format)
> +    (map (lambda (entry)
> +           (match (assq 'source (manifest-entry-properties entry))
> +             (('source ('repository ('version 0)
> +                                    ('url url)
> +                                    ('branch branch)
> +                                    ('commit commit)
> +                                    _ ...))
> +              (case format
> +                ((scm)
> +                 `(channel (name ',(string->symbol
> +                                    (manifest-entry-name entry)))
> +                           (url ,url)
> +                           (commit ,commit)))
> +                ((json)
> +                 `((name . ,(string->symbol
> +                             (manifest-entry-name entry)))
> +                   (url . ,url)
> +                   (commit . ,commit)))))
> +
> +             ;; Pre-0.15.0 Guix does not provide that information,
> +             ;; so there's not much we can do in that case.
> +             (_ '???)))
> +
> +         ;; Show most recently installed packages last.
> +         (reverse
> +          (manifest-entries
> +           (profile-manifest
> +            (if (zero? number)
> +                profile
> +                (generation-file-name profile number)))))))

How about turning this into a list of <channel> objects, and then,
separately have ‘channels->sexp’ and ‘channels->json’?  That would avoid
having dealing with the format in two different places.

Also, could you mention the new format in the manual?

Last question: what use case do you have in mind regarding the JSON
format?  I’m asking because we don’t have tools that can consume it so
far.

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Fix 'format' option.
  2018-11-21 10:47 ` [bug#33448] [PATCH] describe: Fix 'format' option Ludovic Courtès
@ 2018-11-21 11:46   ` Oleg Pykhalov
  0 siblings, 0 replies; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21 11:46 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33448

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

ludo@gnu.org (Ludovic Courtès) writes:

> Oleg Pykhalov <go.wigust@gmail.com> skribis:
>
>> Fix ‘guix describe’ ignores ‘--format=FORMAT’ option.
>>
>> * guix/scripts/describe.scm (%options): Fix 'format' option.
>
> Oops, good catch.  LGTM!

Pushed as 3dd28aa37cc3f3a6bbb5f7f8d9fb49cc457b0c10

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Add json format.
  2018-11-21 10:53   ` Ludovic Courtès
@ 2018-11-21 14:10     ` Oleg Pykhalov
  2018-11-21 21:36       ` Ludovic Courtès
  0 siblings, 1 reply; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21 14:10 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33448

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

Hello Ludovic,

Apologies for created previously separate bug reports of same patch
series.

ludo@gnu.org (Ludovic Courtès) writes:

> Oleg Pykhalov <go.wigust@gmail.com> skribis:
>
>> * guix/scripts/describe.scm: Add json format.
>
> Please describe the modified and added variables/procedures.
>
>> +  (define (channels format)
>> +    (map (lambda (entry)
>> +       …
>> +                (generation-file-name profile number)))))))

Ups, I'll do this in followign patch series.

> How about turning this into a list of <channel> objects, and then,
> separately have ‘channels->sexp’ and ‘channels->json’?  That would avoid
> having dealing with the format in two different places.
>
> Also, could you mention the new format in the manual?
>
> Last question: what use case do you have in mind regarding the JSON
> format?  I’m asking because we don’t have tools that can consume it so
> far.

Well, I wanted to get a command line way to select things in ‘guix
channel’ output, e.g. to get a current ‘guix’ channel commit:
--8<---------------cut here---------------start------------->8---
./pre-inst-env guix describe --profile=$HOME/.config/guix/current --format=json | jq --raw-output 'map(select(.name == "guix"))'[0].commit
--8<---------------cut here---------------end--------------->8---

I didn't think that ‘recsel’ actually could be used in the same way:
--8<---------------cut here---------------start------------->8---
./pre-inst-env guix describe --profile=$HOME/.config/guix/current --format=recutils | recsel -e 'name = "guix"' -P commit
--8<---------------cut here---------------end--------------->8---

I'll send new patch series following current message.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 1/3] describe: Use a procedure to format output.
  2018-11-20 22:26 [bug#33448] [PATCH] describe: Fix 'format' option Oleg Pykhalov
  2018-11-21  7:00 ` [bug#33448] [PATCH] describe: Add json format Oleg Pykhalov
  2018-11-21 10:47 ` [bug#33448] [PATCH] describe: Fix 'format' option Ludovic Courtès
@ 2018-11-21 14:17 ` Oleg Pykhalov
  2018-11-21 14:17   ` [bug#33448] [PATCH 2/3] describe: Add json format Oleg Pykhalov
                     ` (2 more replies)
  2 siblings, 3 replies; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21 14:17 UTC (permalink / raw)
  To: 33448

* guix/channels.scm (channel->sexp): New procedure.
* guix/scripts/describe.scm (display-checkout-info, display-profile-info): Use
this.
---
 guix/channels.scm         |  9 +++++++
 guix/scripts/describe.scm | 57 ++++++++++++++++++++-------------------
 2 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/guix/channels.scm b/guix/channels.scm
index 82389eb58..bfdbf470b 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -39,6 +39,7 @@
             channel-commit
             channel-location
 
+            channel->sexp
             %default-channels
 
             channel-instance?
@@ -85,6 +86,14 @@
   "Return true if CHANNEL is the 'guix' channel."
   (eq? 'guix (channel-name channel)))
 
+(define channel->sexp
+  (match-lambda
+    (($ <channel> name url branch commit location)
+     `(channel
+       (name ,name)
+       (url ,url)
+       (commit ,commit)))))
+
 (define-record-type <channel-instance>
   (channel-instance channel commit checkout)
   channel-instance?
diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index d817d7f7c..6a30d19b1 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -18,6 +18,7 @@
 
 (define-module (guix scripts describe)
   #:use-module ((guix ui) #:hide (display-profile-content))
+  #:use-module (guix channels)
   #:use-module (guix scripts)
   #:use-module (guix describe)
   #:use-module (guix profiles)
@@ -104,10 +105,9 @@ within a Git checkout."
        (format #t (G_ "  branch: ~a~%") (reference-shorthand head))
        (format #t (G_ "  commit: ~a~%") commit))
       ('channels
-       (pretty-print `(list (channel
-                             (name 'guix)
-                             (url ,(dirname directory))
-                             (commit ,commit))))))
+       (pretty-print (channel->sexp (channel (name 'guix)
+                                             (url (dirname directory))
+                                             (commit commit))))))
     (display-package-search-path fmt)))
 
 (define (display-profile-info profile fmt)
@@ -116,34 +116,35 @@ in the format specified by FMT."
   (define number
     (generation-number profile))
 
+  (define (channels)
+    (map (lambda (entry)
+           (match (assq 'source (manifest-entry-properties entry))
+             (('source ('repository ('version 0)
+                                    ('url url)
+                                    ('branch branch)
+                                    ('commit commit)
+                                    _ ...))
+              (channel (name (string->symbol (manifest-entry-name entry)))
+                       (url url)
+                       (commit commit)))
+
+             ;; Pre-0.15.0 Guix does not provide that information,
+             ;; so there's not much we can do in that case.
+             (_ '???)))
+
+         ;; Show most recently installed packages last.
+         (reverse
+          (manifest-entries
+           (profile-manifest
+            (if (zero? number)
+                profile
+                (generation-file-name profile number)))))))
+
   (match fmt
     ('human
      (display-profile-content profile number))
     ('channels
-     (pretty-print
-      `(list ,@(map (lambda (entry)
-                      (match (assq 'source (manifest-entry-properties entry))
-                        (('source ('repository ('version 0)
-                                               ('url url)
-                                               ('branch branch)
-                                               ('commit commit)
-                                               _ ...))
-                         `(channel (name ',(string->symbol
-                                            (manifest-entry-name entry)))
-                                   (url ,url)
-                                   (commit ,commit)))
-
-                        ;; Pre-0.15.0 Guix does not provide that information,
-                        ;; so there's not much we can do in that case.
-                        (_ '???)))
-
-                    ;; Show most recently installed packages last.
-                    (reverse
-                     (manifest-entries
-                      (profile-manifest
-                       (if (zero? number)
-                           profile
-                           (generation-file-name profile number))))))))))
+     (pretty-print (map channel->sexp (channels)))))
   (display-package-search-path fmt))
 
 \f
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 2/3] describe: Add json format.
  2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
@ 2018-11-21 14:17   ` Oleg Pykhalov
  2018-11-21 21:33     ` Ludovic Courtès
  2018-11-21 14:17   ` [bug#33448] [PATCH 3/3] describe: Add recutils format Oleg Pykhalov
  2018-11-21 21:31   ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Ludovic Courtès
  2 siblings, 1 reply; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21 14:17 UTC (permalink / raw)
  To: 33448

* guix/channels.scm (channel->json): New procedure.
* guix/scripts/describe.scm (%options): Add 'json' option.
(display-checkout-info, display-profile-info): Use 'channel->json'.
* doc/guix.texi (Invoking guix describe): Document this.
---
 doc/guix.texi             |  5 ++++-
 guix/channels.scm         | 12 ++++++++++++
 guix/scripts/describe.scm | 13 ++++++++++---
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 082e81bf7..3413eb30f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -3273,7 +3273,10 @@ produce human-readable output;
 @item channels
 produce a list of channel specifications that can be passed to @command{guix
 pull -C} or installed as @file{~/.config/guix/channels.scm} (@pxref{Invoking
-guix pull}).
+guix pull});
+@item json
+@cindex JSON
+produce a list of channel specifications in JSON format.
 @end table
 
 @item --profile=@var{profile}
diff --git a/guix/channels.scm b/guix/channels.scm
index bfdbf470b..9f2c9103e 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -26,6 +26,7 @@
   #:use-module (guix derivations)
   #:use-module (guix store)
   #:use-module (guix i18n)
+  #:use-module (json)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-11)
@@ -39,7 +40,9 @@
             channel-commit
             channel-location
 
+            channel->json
             channel->sexp
+
             %default-channels
 
             channel-instance?
@@ -94,6 +97,15 @@
        (url ,url)
        (commit ,commit)))))
 
+(define channel->json
+  (match-lambda
+    (($ <channel> name url branch commit location)
+     (scm->json-string
+      (list
+       (cons 'name name)
+       (cons 'url url)
+       (cons 'commit commit))))))
+
 (define-record-type <channel-instance>
   (channel-instance channel commit checkout)
   channel-instance?
diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index 6a30d19b1..d7e276769 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -39,7 +39,7 @@
   ;; Specifications of the command-line options.
   (list (option '(#\f "format") #t #f
                 (lambda (opt name arg result)
-                  (unless (member arg '("human" "channels"))
+                  (unless (member arg '("human" "channels" "json"))
                     (leave (G_ "~a: unsupported output format~%") arg))
                   (alist-cons 'format (string->symbol arg) result)))
         (option '(#\p "profile") #t #f
@@ -107,7 +107,12 @@ within a Git checkout."
       ('channels
        (pretty-print (channel->sexp (channel (name 'guix)
                                              (url (dirname directory))
-                                             (commit commit))))))
+                                             (commit commit)))))
+      ('json
+       (display (channel->json (channel (name 'guix)
+                                        (url (dirname directory))
+                                        (commit commit))))
+       (newline)))
     (display-package-search-path fmt)))
 
 (define (display-profile-info profile fmt)
@@ -144,7 +149,9 @@ in the format specified by FMT."
     ('human
      (display-profile-content profile number))
     ('channels
-     (pretty-print (map channel->sexp (channels)))))
+     (pretty-print (map channel->sexp (channels))))
+    ('json
+     (format #t "[~a]~%" (string-join (map channel->json (channels)) ","))))
   (display-package-search-path fmt))
 
 \f
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 3/3] describe: Add recutils format.
  2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
  2018-11-21 14:17   ` [bug#33448] [PATCH 2/3] describe: Add json format Oleg Pykhalov
@ 2018-11-21 14:17   ` Oleg Pykhalov
  2018-11-21 21:34     ` Ludovic Courtès
  2018-11-21 21:31   ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Ludovic Courtès
  2 siblings, 1 reply; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-21 14:17 UTC (permalink / raw)
  To: 33448

* guix/channels.scm (channel->recutils): New procedure.
* guix/scripts/describe.scm (%options): Add 'recutils' option.
(display-checkout-info, display-profile-info): Use 'channel->recutils'.
* doc/guix.texi (Invoking guix describe): Document this.
---
 doc/guix.texi             |  4 +++-
 guix/channels.scm         |  8 ++++++++
 guix/scripts/describe.scm | 18 +++++++++++++++---
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3413eb30f..44594d168 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -3276,7 +3276,9 @@ pull -C} or installed as @file{~/.config/guix/channels.scm} (@pxref{Invoking
 guix pull});
 @item json
 @cindex JSON
-produce a list of channel specifications in JSON format.
+produce a list of channel specifications in JSON format;
+@item recutils
+produce a list of channel specifications in Recutils format.
 @end table
 
 @item --profile=@var{profile}
diff --git a/guix/channels.scm b/guix/channels.scm
index 9f2c9103e..ed9bc67c3 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -41,6 +41,7 @@
             channel-location
 
             channel->json
+            channel->recutils
             channel->sexp
 
             %default-channels
@@ -106,6 +107,13 @@
        (cons 'url url)
        (cons 'commit commit))))))
 
+(define (channel->recutils c port)
+  (match c
+    (($ <channel> name url branch commit location)
+     (format port "name: ~a~%" name)
+     (format port "url: ~a~%" url)
+     (format port "commit: ~a~%" commit))))
+
 (define-record-type <channel-instance>
   (channel-instance channel commit checkout)
   channel-instance?
diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index d7e276769..90365b7ae 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -39,7 +39,7 @@
   ;; Specifications of the command-line options.
   (list (option '(#\f "format") #t #f
                 (lambda (opt name arg result)
-                  (unless (member arg '("human" "channels" "json"))
+                  (unless (member arg '("human" "channels" "json" "recutils"))
                     (leave (G_ "~a: unsupported output format~%") arg))
                   (alist-cons 'format (string->symbol arg) result)))
         (option '(#\p "profile") #t #f
@@ -112,7 +112,12 @@ within a Git checkout."
        (display (channel->json (channel (name 'guix)
                                         (url (dirname directory))
                                         (commit commit))))
-       (newline)))
+       (newline))
+      ('recutils
+       (channel->recutils (channel (name 'guix)
+                                   (url (dirname directory))
+                                   (commit commit))
+                          #t)))
     (display-package-search-path fmt)))
 
 (define (display-profile-info profile fmt)
@@ -151,7 +156,14 @@ in the format specified by FMT."
     ('channels
      (pretty-print (map channel->sexp (channels))))
     ('json
-     (format #t "[~a]~%" (string-join (map channel->json (channels)) ","))))
+     (format #t "[~a]~%" (string-join (map channel->json (channels)) ",")))
+    ('recutils
+     (format #t "~{~a~%~}"
+             (map (lambda (channel)
+                    (with-output-to-string
+                      (lambda ()
+                        (channel->recutils channel (current-output-port)))))
+                  (channels)))))
   (display-package-search-path fmt))
 
 \f
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 1/3] describe: Use a procedure to format output.
  2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
  2018-11-21 14:17   ` [bug#33448] [PATCH 2/3] describe: Add json format Oleg Pykhalov
  2018-11-21 14:17   ` [bug#33448] [PATCH 3/3] describe: Add recutils format Oleg Pykhalov
@ 2018-11-21 21:31   ` Ludovic Courtès
  2018-11-22 12:54     ` Oleg Pykhalov
  2 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 21:31 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Hi,

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> * guix/channels.scm (channel->sexp): New procedure.
> * guix/scripts/describe.scm (display-checkout-info, display-profile-info): Use
> this.

[...]

> +  (define (channels)

s/define (channels)/define channels/  :-)

> +    (map (lambda (entry)
> +           (match (assq 'source (manifest-entry-properties entry))
> +             (('source ('repository ('version 0)
> +                                    ('url url)
> +                                    ('branch branch)
> +                                    ('commit commit)
> +                                    _ ...))
> +              (channel (name (string->symbol (manifest-entry-name entry)))
> +                       (url url)
> +                       (commit commit)))
> +
> +             ;; Pre-0.15.0 Guix does not provide that information,
> +             ;; so there's not much we can do in that case.
> +             (_ '???)))

Maybe return, say: (channel (name 'guix)(url "?")(commit "?")).
This would avoid weird type errors.

> +     (pretty-print (map channel->sexp (channels)))))

I think it should be:

  (pretty-print `(list ,@(map channel->sexp channels)))

right?

OK with these changes, thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 2/3] describe: Add json format.
  2018-11-21 14:17   ` [bug#33448] [PATCH 2/3] describe: Add json format Oleg Pykhalov
@ 2018-11-21 21:33     ` Ludovic Courtès
  2018-11-22 12:54       ` Oleg Pykhalov
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 21:33 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> * guix/channels.scm (channel->json): New procedure.
> * guix/scripts/describe.scm (%options): Add 'json' option.
> (display-checkout-info, display-profile-info): Use 'channel->json'.
> * doc/guix.texi (Invoking guix describe): Document this.

[...]

> +(define channel->json
> +  (match-lambda
> +    (($ <channel> name url branch commit location)
> +     (scm->json-string
> +      (list
> +       (cons 'name name)
> +       (cons 'url url)
> +       (cons 'commit commit))))))

Since this is not a core feature of channels and add a dependency on
(json), what about moving this procedure to (guix scripts describe)?

(‘channel->sexp’ could got to (guix scripts describe) as well maybe; no
big deal.)

Otherwise LGTM!

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 3/3] describe: Add recutils format.
  2018-11-21 14:17   ` [bug#33448] [PATCH 3/3] describe: Add recutils format Oleg Pykhalov
@ 2018-11-21 21:34     ` Ludovic Courtès
  0 siblings, 0 replies; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 21:34 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> * guix/channels.scm (channel->recutils): New procedure.
> * guix/scripts/describe.scm (%options): Add 'recutils' option.
> (display-checkout-info, display-profile-info): Use 'channel->recutils'.
> * doc/guix.texi (Invoking guix describe): Document this.

[...]

> +(define (channel->recutils c port)
> +  (match c
> +    (($ <channel> name url branch commit location)
> +     (format port "name: ~a~%" name)
> +     (format port "url: ~a~%" url)
> +     (format port "commit: ~a~%" commit))))

Same thing here: I’d have a preference for moving it to (guix scripts
describe).

Otherwise LGTM, thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH] describe: Add json format.
  2018-11-21 14:10     ` Oleg Pykhalov
@ 2018-11-21 21:36       ` Ludovic Courtès
  0 siblings, 0 replies; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-21 21:36 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:

[...]

>> Last question: what use case do you have in mind regarding the JSON
>> format?  I’m asking because we don’t have tools that can consume it so
>> far.
>
> Well, I wanted to get a command line way to select things in ‘guix
> channel’ output, e.g. to get a current ‘guix’ channel commit:
>
> ./pre-inst-env guix describe --profile=$HOME/.config/guix/current --format=json | jq --raw-output 'map(select(.name == "guix"))'[0].commit
>
>
> I didn't think that ‘recsel’ actually could be used in the same way:
>
> ./pre-inst-env guix describe --profile=$HOME/.config/guix/current --format=recutils | recsel -e 'name = "guix"' -P commit

I see, that makes sense.  It’s OK to have both JSON and recutils.

Thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 1/3] describe: Use a procedure to format output.
  2018-11-21 21:31   ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Ludovic Courtès
@ 2018-11-22 12:54     ` Oleg Pykhalov
  0 siblings, 0 replies; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-22 12:54 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33448

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

Hi,

ludo@gnu.org (Ludovic Courtès) writes:

> Oleg Pykhalov <go.wigust@gmail.com> skribis:
>
>> * guix/channels.scm (channel->sexp): New procedure.
>> * guix/scripts/describe.scm (display-checkout-info, display-profile-info): Use
>> this.

[…]

>> +     (pretty-print (map channel->sexp (channels)))))
>
> I think it should be:
>
>   (pretty-print `(list ,@(map channel->sexp channels)))

Ouch, ‘list’ in in 'display-checkout-info' should be too.  Apologies.

Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 2/3] describe: Add json format.
  2018-11-21 21:33     ` Ludovic Courtès
@ 2018-11-22 12:54       ` Oleg Pykhalov
  2018-11-22 16:53         ` Ludovic Courtès
  0 siblings, 1 reply; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-22 12:54 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33448

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

Hi Ludovic,

Almost done with current patch series and only one question.

ludo@gnu.org (Ludovic Courtès) writes:

> Oleg Pykhalov <go.wigust@gmail.com> skribis:
>
>> * guix/channels.scm (channel->json): New procedure.
>> * guix/scripts/describe.scm (%options): Add 'json' option.
>> (display-checkout-info, display-profile-info): Use 'channel->json'.
>> * doc/guix.texi (Invoking guix describe): Document this.
>
> [...]
>
>> +(define channel->json
>> +  (match-lambda
>> +    (($ <channel> name url branch commit location)
>> +     (scm->json-string
>> +      (list
>> +       (cons 'name name)
>> +       (cons 'url url)
>> +       (cons 'commit commit))))))
>
> Since this is not a core feature of channels and add a dependency on
> (json), what about moving this procedure to (guix scripts describe)?

<channel> should be exported in (guix channels) in this case.  Is it OK?

[…]

Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 2/3] describe: Add json format.
  2018-11-22 12:54       ` Oleg Pykhalov
@ 2018-11-22 16:53         ` Ludovic Courtès
  2018-11-22 18:23           ` Oleg Pykhalov
  0 siblings, 1 reply; 17+ messages in thread
From: Ludovic Courtès @ 2018-11-22 16:53 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 33448

Hi Oleg,

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> Almost done with current patch series and only one question.
>
> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Oleg Pykhalov <go.wigust@gmail.com> skribis:
>>
>>> * guix/channels.scm (channel->json): New procedure.
>>> * guix/scripts/describe.scm (%options): Add 'json' option.
>>> (display-checkout-info, display-profile-info): Use 'channel->json'.
>>> * doc/guix.texi (Invoking guix describe): Document this.
>>
>> [...]
>>
>>> +(define channel->json
>>> +  (match-lambda
>>> +    (($ <channel> name url branch commit location)
>>> +     (scm->json-string
>>> +      (list
>>> +       (cons 'name name)
>>> +       (cons 'url url)
>>> +       (cons 'commit commit))))))
>>
>> Since this is not a core feature of channels and add a dependency on
>> (json), what about moving this procedure to (guix scripts describe)?
>
> <channel> should be exported in (guix channels) in this case.  Is it OK?

No I think we should avoid exporting <channel>, but anyway we can write
this procedure as:

  (lambda (channel)
    (scm->json-string `((name . ,(channel-name channel)) …)))

Ludo’.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [bug#33448] [PATCH 2/3] describe: Add json format.
  2018-11-22 16:53         ` Ludovic Courtès
@ 2018-11-22 18:23           ` Oleg Pykhalov
  0 siblings, 0 replies; 17+ messages in thread
From: Oleg Pykhalov @ 2018-11-22 18:23 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 33448, 33448-done

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

ludo@gnu.org (Ludovic Courtès) writes:

[…]

>> <channel> should be exported in (guix channels) in this case.  Is it OK?
>
> No I think we should avoid exporting <channel>, but anyway we can write
> this procedure as:
>
>   (lambda (channel)
>     (scm->json-string `((name . ,(channel-name channel)) …)))

Oh, sure.  Thank you for a reminder.

Pushed as:
--8<---------------cut here---------------start------------->8---
85e9c4b91990008f2b6b07c5de6f14427d7c3a06 describe: Add recutils format.
81a40ee0cb925bc39e3044bddcfdd38ddb04f04d describe: Add json format.
8548f995494d8d6358e6a8d7bc3b3bb5a0cbecb5 describe: Use a procedure to format output.
--8<---------------cut here---------------end--------------->8---

Thanks,
Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-11-22 18:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 22:26 [bug#33448] [PATCH] describe: Fix 'format' option Oleg Pykhalov
2018-11-21  7:00 ` [bug#33448] [PATCH] describe: Add json format Oleg Pykhalov
2018-11-21 10:53   ` Ludovic Courtès
2018-11-21 14:10     ` Oleg Pykhalov
2018-11-21 21:36       ` Ludovic Courtès
2018-11-21 10:47 ` [bug#33448] [PATCH] describe: Fix 'format' option Ludovic Courtès
2018-11-21 11:46   ` Oleg Pykhalov
2018-11-21 14:17 ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Oleg Pykhalov
2018-11-21 14:17   ` [bug#33448] [PATCH 2/3] describe: Add json format Oleg Pykhalov
2018-11-21 21:33     ` Ludovic Courtès
2018-11-22 12:54       ` Oleg Pykhalov
2018-11-22 16:53         ` Ludovic Courtès
2018-11-22 18:23           ` Oleg Pykhalov
2018-11-21 14:17   ` [bug#33448] [PATCH 3/3] describe: Add recutils format Oleg Pykhalov
2018-11-21 21:34     ` Ludovic Courtès
2018-11-21 21:31   ` [bug#33448] [PATCH 1/3] describe: Use a procedure to format output Ludovic Courtès
2018-11-22 12:54     ` Oleg Pykhalov

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.