diff mbox series

[bug#68935,2/3] guix: import: Wrap package expressions with define-public.

Message ID f51c93b2814ed5f1124d05a0769d81a236cf0883.1707144191.git.herman@rimm.ee
State New
Headers show
Series Add 'put' option to guix import. | expand

Commit Message

Herman Rimm Feb. 5, 2024, 3:07 p.m. UTC
* guix/scripts/import.scm (guix-import): Wrap package expressions.

Change-Id: Ic4d986a4706a692b2fecd6fded8ac72ab6311687
---
 guix/scripts/import.scm | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Ludovic Courtès Feb. 7, 2024, 9:38 p.m. UTC | #1
Herman Rimm <herman@rimm.ee> skribis:

> * guix/scripts/import.scm (guix-import): Wrap package expressions.
>
> Change-Id: Ic4d986a4706a692b2fecd6fded8ac72ab6311687

Probably a good idea!

>             (match (apply (resolve-importer importer) args)
> -             ((and expr (or ('package _ ...)
> -                            ('let _ ...)
> +             ((and expr ('package _ ...))
> +              (print (package->definition expr)))
> +             ((and expr (or ('let _ ...)
>                              ('define-public _ ...)))
>                (print expr))

The (let …) case should be treated like the (package …) case.  It
corresponds to things like:

  (let ((commit "abcde"))
    (package
      …))

> +                  (match expr
> +                         ((and expr ('package _ ...))
> +                          (print (package->definition expr)))
> +                         ((and expr (or ('let _ ...)
> +                                        ('define-public _ ...)))
> +                          (print expr)))

Same here.

Also, please indent ‘match’ the same way as elsewhere in the code:

  (match lst
    ((x y z)
     …))

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index d2a1cee56e..80b1bec7fc 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -6,6 +6,7 @@ 
 ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
+;;; Copyright © 2024 Herman Rimm <herman@rimm.ee>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,6 +24,7 @@ 
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix scripts import)
+  #:use-module (guix import utils)
   #:use-module (guix ui)
   #:use-module (guix scripts)
   #:use-module (guix read-print)
@@ -88,17 +90,23 @@  (define-command (guix-import . args)
                         (leave-on-EPIPE
                          (pretty-print-with-comments (current-output-port) expr)))))
            (match (apply (resolve-importer importer) args)
-             ((and expr (or ('package _ ...)
-                            ('let _ ...)
+             ((and expr ('package _ ...))
+              (print (package->definition expr)))
+             ((and expr (or ('let _ ...)
                             ('define-public _ ...)))
               (print expr))
              ((? list? expressions)
               (for-each (lambda (expr)
-                          (print expr)
-                          ;; Two newlines: one after the closing paren, and
-                          ;; one to leave a blank line.
-                          (newline) (newline))
-                        expressions))
+                  (match expr
+                         ((and expr ('package _ ...))
+                          (print (package->definition expr)))
+                         ((and expr (or ('let _ ...)
+                                        ('define-public _ ...)))
+                          (print expr)))
+                  ;; Two newlines: one after the closing paren, and
+                  ;; one to leave a blank line.
+                  (newline) (newline))
+                expressions))
              (x
               (leave (G_ "'~a' import failed~%") importer))))
          (let ((hint (string-closest importer importers #:threshold 3)))