[PATCH 0/1] guix package, show: Support multiple queries.

DoneSubmitted by zimoun.
Details
2 participants
  • Ludovic Courtès
  • zimoun
Owner
unassigned
Severity
normal
Z
Z
zimoun wrote on 11 May 2020 01:37
(address . guix-patches@gnu.org)(name . zimoun)(address . zimon.toutoune@gmail.com)
20200510233747.13155-1-zimon.toutoune@gmail.com
Dear,

This patch adds the feature:

guix package --show=emacs --show=hello

and therefore, it allows to pipe:

guix graph emacs --path libffi | xargs guix show


Note that:

1. "guix package" processes from right to left.
2. "guix show" processes from left to right.

It is how "guix packages" is implemented. However, it appears more natural to
display in order; that's why "guix show" reverses the order.

3. Because dealing with multiple different queries does not seems "keep it
simple", "guix package" starts with the last query (the most of left) and
then processes all the queries corresponding to this one.


For example,

a) guix package --show=emacs --search=hello --show=libffi
will show the packages 'emacs' and 'libffi', skipping 'search'.

b) guix package --show=emacs --show=libffi --search=hello
will search the package 'hello', skipping 'show'.

It is already how '--search' works and has been extended to '--show'. Does it
need to be documented in the manua?



All the best,
simon




zimoun (1):
guix package, show: Support multiple queries.

guix/scripts/package.scm | 7 ++++++-
guix/scripts/show.scm | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)

--
2.26.1
Z
Z
zimoun wrote on 11 May 2020 01:40
[PATCH] guix package, show: Support multiple queries.
(address . 41183@debbugs.gnu.org)(name . zimoun)(address . zimon.toutoune@gmail.com)
20200510234044.14251-1-zimon.toutoune@gmail.com
* guix/scripts/package.scm (process-query): Show multiple queries.
* guix/scripts/show.scm (guix-show): Reverse to display in order.
---
guix/scripts/package.scm | 33 +++++++++++++++++++++------------
guix/scripts/show.scm | 2 +-
2 files changed, 22 insertions(+), 13 deletions(-)

Toggle diff (63 lines)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index dce9256bf5..a69efa365e 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -787,18 +788,26 @@ processed, #f otherwise."
           (display-search-results matches (current-output-port)))
          #t))
 
-      (('show requested-name)
-       (let-values (((name version)
-                     (package-name->name+version requested-name)))
-         (match (remove package-superseded
-                        (find-packages-by-name name version))
-           (()
-            (leave (G_ "~a~@[@~a~]: package not found~%") name version))
-           (packages
-            (leave-on-EPIPE
-             (for-each (cute package->recutils <> (current-output-port))
-                       packages))))
-         #t))
+      (('show _)
+       (let ((requested-names
+              (filter-map (match-lambda
+                            (('query 'show requested-name) requested-name)
+                            (_                            #f))
+                          opts)))
+         (for-each
+          (lambda (requested-name)
+            (let-values (((name version)
+                          (package-name->name+version requested-name)))
+              (match (remove package-superseded
+                             (find-packages-by-name name version))
+                (()
+                 (leave (G_ "~a~@[@~a~]: package not found~%") name version))
+                (packages
+                 (leave-on-EPIPE
+                  (for-each (cute package->recutils <> (current-output-port))
+                            packages))))))
+          requested-names))
+       #t)
 
       (('search-paths kind)
        (let* ((manifests (map profile-manifest profiles))
diff --git a/guix/scripts/show.scm b/guix/scripts/show.scm
index ef64b5755b..a2b0030a63 100644
--- a/guix/scripts/show.scm
+++ b/guix/scripts/show.scm
@@ -73,4 +73,4 @@ This is an alias for 'guix package --show='.\n"))
   (unless (assoc-ref opts 'query)
     (leave (G_ "missing arguments: no package to show~%")))
 
-  (guix-package* opts))
+  (guix-package* (reverse opts)))
-- 
2.26.1
L
L
Ludovic Courtès wrote on 11 May 2020 22:25
(name . zimoun)(address . zimon.toutoune@gmail.com)(address . 41183-done@debbugs.gnu.org)
87ftc6fcc6.fsf@gnu.org
Hello,

zimoun <zimon.toutoune@gmail.com> skribis:

Toggle quote (3 lines)
> * guix/scripts/package.scm (process-query): Show multiple queries.
> * guix/scripts/show.scm (guix-show): Reverse to display in order.

Yay, applied!

Toggle quote (24 lines)
> Note that:
>
> 1. "guix package" processes from right to left.
> 2. "guix show" processes from left to right.
>
> It is how "guix packages" is implemented. However, it appears more natural to
> display in order; that's why "guix show" reverses the order.
>
> 3. Because dealing with multiple different queries does not seems "keep it
> simple", "guix package" starts with the last query (the most of left) and
> then processes all the queries corresponding to this one.
>
>
> For example,
>
> a) guix package --show=emacs --search=hello --show=libffi
> will show the packages 'emacs' and 'libffi', skipping 'search'.
>
> b) guix package --show=emacs --show=libffi --search=hello
> will search the package 'hello', skipping 'show'.
>
> It is already how '--search' works and has been extended to '--show'. Does it
> need to be documented in the manua?

Weirdness. I think we should improve all that rather than document it,
addressing also some of the issues raised in

Thanks,
Ludo’.
Closed
Z
Z
zimoun wrote on 11 May 2020 23:48
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 41183-done@debbugs.gnu.org)
CAJ3okZ1SqUC-GEWFh6PYys_1vo_W0RxTPk55ZM4HwJN21FdR0g@mail.gmail.com
Hi Ludo,

On Mon, 11 May 2020 at 22:25, Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (2 lines)
> Yay, applied!

Thank you!


Toggle quote (7 lines)
> > It is already how '--search' works and has been extended to '--show'. Does it
> > need to be documented in the manua?
>
> Weirdness. I think we should improve all that rather than document it,
> addressing also some of the issues raised in
> <https://issues.guix.gnu.org/issue/40549>.

Expected weirdness. :-)
It is because of the use of 'assoc-ref' on 'opts' which returns the
first match, so the first in the alist, so the last in the
command-line. This behaviour is a feature. ;-)

Well, thanks for the reminder on #40549. Now I have a better
understanding (e.g., query vs action), I am going to revisit it.


Cheers,
simon
Closed
?
Your comment

This issue is archived.

To comment on this conversation send email to 41183@debbugs.gnu.org