all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] scripts: environment: Allow lists of packages in expressions.
@ 2015-10-31  1:09 David Thompson
  2015-10-31 10:25 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: David Thompson @ 2015-10-31  1:09 UTC (permalink / raw)
  To: guix-devel

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

Thanks to avoine on freenode for motivating me to finally add this
feature.  I've wanted it for awhile, but not badly enough to actually
implement it until now.  This is a cool feature because you can do stuff
like this now:

    guix environment --ad-hoc -e '(@ (gnu) %base-packages)'

Pretty cool!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-scripts-environment-Allow-lists-of-packages-in-expre.patch --]
[-- Type: text/x-patch, Size: 4528 bytes --]

From c9c282cea04ec5a3ee7bd17e6ad8846600220feb Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Fri, 30 Oct 2015 21:02:51 -0400
Subject: [PATCH] scripts: environment: Allow lists of packages in expressions.

* guix/scripts/environment.scm (options/resolve-packages): Match against
  lists of packages when evaluating expressions.
* tests/guix-environment.sh: Add test.
* doc/guix.texi ("invoking guix environment"): Add docs.
---
 doc/guix.texi                | 15 ++++++++++++---
 guix/scripts/environment.scm | 24 +++++++++++++++---------
 tests/guix-environment.sh    | 11 +++++++++++
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index a164608..84f194b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4730,7 +4730,8 @@ The available options are summarized below.
 @table @code
 @item --expression=@var{expr}
 @itemx -e @var{expr}
-Create an environment for the package that @var{expr} evaluates to.
+Create an environment for the package or list of packages that
+@var{expr} evaluates to.
 
 For example, running:
 
@@ -4741,10 +4742,18 @@ guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
 starts a shell with the environment for this specific variant of the
 PETSc package.
 
+Running:
+
+@example
+guix environment --ad-hoc -e '(@ (gnu) %base-packages)'
+@end example
+
+starts a shell with all the GuixSD base packages available.
+
 @item --load=@var{file}
 @itemx -l @var{file}
-Create an environment for the package that the code within @var{file}
-evaluates to.
+Create an environment for the package or list of packages that the code
+within @var{file} evaluates to.
 
 As an example, @var{file} might contain a definition like this
 (@pxref{Defining Packages}):
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 1888385..f9ab9a4 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -253,6 +253,18 @@ COMMAND or an interactive shell in that environment.\n"))
 (define (options/resolve-packages opts)
   "Return OPTS with package specification strings replaced by actual
 packages."
+  (define (package->outputs package mode)
+    (map (lambda (output)
+           (list mode package output))
+         (package-outputs package)))
+
+  (define (packages->outputs packages mode)
+    (match packages
+      ((? package? package)
+       (package->outputs package mode))
+      (((? package? packages) ...)
+       (append-map (cut package->outputs <> mode) packages))))
+
   (compact
    (append-map (match-lambda
                  (('package mode (? string? spec))
@@ -261,17 +273,11 @@ packages."
                     (list (list mode package output))))
                  (('expression mode str)
                   ;; Add all the outputs of the package STR evaluates to.
-                  (match (read/eval str)
-                    ((? package? package)
-                     (map (lambda (output)
-                            (list mode package output))
-                          (package-outputs package)))))
+                  (packages->outputs (read/eval str) mode))
                  (('load mode file)
                   ;; Add all the outputs of the package defined in FILE.
-                  (let ((package (load* file (make-user-module '()))))
-                    (map (lambda (output)
-                           (list mode package output))
-                         (package-outputs package))))
+                  (let ((module (make-user-module '())))
+                    (packages->outputs (load* file module) mode)))
                  (_ '(#f)))
                opts)))
 
diff --git a/tests/guix-environment.sh b/tests/guix-environment.sh
index 49b3b1c..f7b0259 100644
--- a/tests/guix-environment.sh
+++ b/tests/guix-environment.sh
@@ -111,4 +111,15 @@ then
     grep -E '^export CPATH=.*-gcc-bootstrap-0/include'      "$tmpdir/a"
     grep -E '^export CPATH=.*-glibc-bootstrap-0/include'    "$tmpdir/a"
     grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
+
+    # Make sure a package list can be used with -e.
+    expr_list_test_code="
+(list (@@ (gnu packages commencement) gnu-make-boot0)
+      (@ (gnu packages bootstrap) %bootstrap-guile))"
+
+    guix environment --ad-hoc --no-substitutes --search-paths --pure \
+         -e "$expr_list_test_code" > "$tmpdir/a"
+
+    grep -E '^export PATH=.*-make-boot0-4.1/bin'      "$tmpdir/a"
+    grep -E '^export PATH=.*-guile-bootstrap-2.0/bin' "$tmpdir/a"
 fi
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
David Thompson
GPG Key: 0FF1D807

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

* Re: [PATCH] scripts: environment: Allow lists of packages in expressions.
  2015-10-31  1:09 [PATCH] scripts: environment: Allow lists of packages in expressions David Thompson
@ 2015-10-31 10:25 ` Ludovic Courtès
  2015-10-31 11:40   ` Thompson, David
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2015-10-31 10:25 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> Thanks to avoine on freenode for motivating me to finally add this
> feature.  I've wanted it for awhile, but not badly enough to actually
> implement it until now.  This is a cool feature because you can do stuff
> like this now:
>
>     guix environment --ad-hoc -e '(@ (gnu) %base-packages)'
>
> Pretty cool!

Yep!

> From c9c282cea04ec5a3ee7bd17e6ad8846600220feb Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> Date: Fri, 30 Oct 2015 21:02:51 -0400
> Subject: [PATCH] scripts: environment: Allow lists of packages in expressions.
>
> * guix/scripts/environment.scm (options/resolve-packages): Match against
>   lists of packages when evaluating expressions.
> * tests/guix-environment.sh: Add test.
> * doc/guix.texi ("invoking guix environment"): Add docs.

OK!

Thanks,
Ludo’.

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

* Re: [PATCH] scripts: environment: Allow lists of packages in expressions.
  2015-10-31 10:25 ` Ludovic Courtès
@ 2015-10-31 11:40   ` Thompson, David
  0 siblings, 0 replies; 3+ messages in thread
From: Thompson, David @ 2015-10-31 11:40 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

On Sat, Oct 31, 2015 at 6:25 AM, Ludovic Courtès <ludo@gnu.org> wrote:
> David Thompson <dthompson2@worcester.edu> skribis:
>
>> From c9c282cea04ec5a3ee7bd17e6ad8846600220feb Mon Sep 17 00:00:00 2001
>> From: David Thompson <dthompson2@worcester.edu>
>> Date: Fri, 30 Oct 2015 21:02:51 -0400
>> Subject: [PATCH] scripts: environment: Allow lists of packages in expressions.
>>
>> * guix/scripts/environment.scm (options/resolve-packages): Match against
>>   lists of packages when evaluating expressions.
>> * tests/guix-environment.sh: Add test.
>> * doc/guix.texi ("invoking guix environment"): Add docs.
>
> OK!

Pushed. Thanks!

- Dave

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

end of thread, other threads:[~2015-10-31 11:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-31  1:09 [PATCH] scripts: environment: Allow lists of packages in expressions David Thompson
2015-10-31 10:25 ` Ludovic Courtès
2015-10-31 11:40   ` Thompson, David

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.