diff mbox

[6/7] import cran: Add "recursive" option.

Message ID 1464018008-1767-7-git-send-email-ricardo.wurmus@mdc-berlin.de
State New
Headers show

Commit Message

Ricardo Wurmus May 23, 2016, 3:40 p.m. UTC
* guix/scripts/import/cran.scm: (%options): Add "recursive" option.
(guix-import-cran): Handle "recursive" option.
---
 guix/scripts/import/cran.scm | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

Comments

Ludovic Courtès May 30, 2016, 8:55 a.m. UTC | #1
Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:

> * guix/scripts/import/cran.scm: (%options): Add "recursive" option.
> (guix-import-cran): Handle "recursive" option.
> ---
>  guix/scripts/import/cran.scm | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/guix/scripts/import/cran.scm b/guix/scripts/import/cran.scm
> index ace1123..4cae9da 100644
> --- a/guix/scripts/import/cran.scm
> +++ b/guix/scripts/import/cran.scm
> @@ -63,6 +63,9 @@ Import and convert the CRAN package for PACKAGE-NAME.\n"))
>                   (lambda (opt name arg result)
>                     (alist-cons 'repo (string->symbol arg)
>                                 (alist-delete 'repo result))))
> +         (option '(#\r "recursive") #f #f
> +                 (lambda (opt name arg result)
> +                   (alist-cons 'recursive #t result)))
>           %standard-import-options))
>  
>  
> @@ -88,12 +91,23 @@ Import and convert the CRAN package for PACKAGE-NAME.\n"))
>                             (reverse opts))))
>      (match args
>        ((package-name)
> -       (let ((sexp (cran->guix-package package-name
> -                                       (or (assoc-ref opts 'repo) 'cran))))
> -         (unless sexp
> -           (leave (_ "failed to download description for package '~a'~%")
> -                  package-name))
> -         sexp))
> +       (if (assoc-ref opts 'recursive)
> +           ;; Recursive import
> +           (map (match-lambda
> +                  ((and (label . (('package ('name name) . rest)))
> +                        (label . (pkg)))
> +                   `(define-public ,(string->symbol name)
> +                      ,pkg))

Perhaps it could check with ‘find-packages-by-name’ whether NAME already
exists?

> +                  (_ #f))
> +                (recursive-import package-name
> +                                  (or (assoc-ref opts 'repo) 'cran)))
> +           ;; Single import
> +           (let ((sexp (cran->guix-package package-name
> +                                           (or (assoc-ref opts 'repo) 'cran))))
> +             (unless sexp
> +               (leave (_ "failed to download description for package '~a'~%")
> +                      package-name))
> +             sexp)))

Do you think this could be moved to (guix scripts import)?  We would
have to change other importers to return an empty list/stream of
dependencies for now.

Thanks,
Ludo’.
Ricardo Wurmus June 14, 2016, 3:30 p.m. UTC | #2
Ludovic Courtès <ludo@gnu.org> writes:

> Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:
>
>> * guix/scripts/import/cran.scm: (%options): Add "recursive" option.
>> (guix-import-cran): Handle "recursive" option.
>> ---
>>  guix/scripts/import/cran.scm | 26 ++++++++++++++++++++------
>>  1 file changed, 20 insertions(+), 6 deletions(-)
>>
>> diff --git a/guix/scripts/import/cran.scm b/guix/scripts/import/cran.scm
>> index ace1123..4cae9da 100644
>> --- a/guix/scripts/import/cran.scm
>> +++ b/guix/scripts/import/cran.scm
>> @@ -63,6 +63,9 @@ Import and convert the CRAN package for PACKAGE-NAME.\n"))
>>                   (lambda (opt name arg result)
>>                     (alist-cons 'repo (string->symbol arg)
>>                                 (alist-delete 'repo result))))
>> +         (option '(#\r "recursive") #f #f
>> +                 (lambda (opt name arg result)
>> +                   (alist-cons 'recursive #t result)))
>>           %standard-import-options))
>>  
>>  
>> @@ -88,12 +91,23 @@ Import and convert the CRAN package for PACKAGE-NAME.\n"))
>>                             (reverse opts))))
>>      (match args
>>        ((package-name)
>> -       (let ((sexp (cran->guix-package package-name
>> -                                       (or (assoc-ref opts 'repo) 'cran))))
>> -         (unless sexp
>> -           (leave (_ "failed to download description for package '~a'~%")
>> -                  package-name))
>> -         sexp))
>> +       (if (assoc-ref opts 'recursive)
>> +           ;; Recursive import
>> +           (map (match-lambda
>> +                  ((and (label . (('package ('name name) . rest)))
>> +                        (label . (pkg)))
>> +                   `(define-public ,(string->symbol name)
>> +                      ,pkg))
>
> Perhaps it could check with ‘find-packages-by-name’ whether NAME already
> exists?

The “recursive-import” method currently only does this for
dependencies.  A check would involve generating “(guix-name
package-name)”, but “guix-name” is defined in “guix/import/cran.scm”.
Should this check happen in the “recursive-import” procedure instead?

>> +                  (_ #f))
>> +                (recursive-import package-name
>> +                                  (or (assoc-ref opts 'repo) 'cran)))
>> +           ;; Single import
>> +           (let ((sexp (cran->guix-package package-name
>> +                                           (or (assoc-ref opts 'repo) 'cran))))
>> +             (unless sexp
>> +               (leave (_ "failed to download description for package '~a'~%")
>> +                      package-name))
>> +             sexp)))
>
> Do you think this could be moved to (guix scripts import)?  We would
> have to change other importers to return an empty list/stream of
> dependencies for now.

Yes, I’ll do that.

~~ Ricardo
diff mbox

Patch

diff --git a/guix/scripts/import/cran.scm b/guix/scripts/import/cran.scm
index ace1123..4cae9da 100644
--- a/guix/scripts/import/cran.scm
+++ b/guix/scripts/import/cran.scm
@@ -63,6 +63,9 @@  Import and convert the CRAN package for PACKAGE-NAME.\n"))
                  (lambda (opt name arg result)
                    (alist-cons 'repo (string->symbol arg)
                                (alist-delete 'repo result))))
+         (option '(#\r "recursive") #f #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'recursive #t result)))
          %standard-import-options))
 
 
@@ -88,12 +91,23 @@  Import and convert the CRAN package for PACKAGE-NAME.\n"))
                            (reverse opts))))
     (match args
       ((package-name)
-       (let ((sexp (cran->guix-package package-name
-                                       (or (assoc-ref opts 'repo) 'cran))))
-         (unless sexp
-           (leave (_ "failed to download description for package '~a'~%")
-                  package-name))
-         sexp))
+       (if (assoc-ref opts 'recursive)
+           ;; Recursive import
+           (map (match-lambda
+                  ((and (label . (('package ('name name) . rest)))
+                        (label . (pkg)))
+                   `(define-public ,(string->symbol name)
+                      ,pkg))
+                  (_ #f))
+                (recursive-import package-name
+                                  (or (assoc-ref opts 'repo) 'cran)))
+           ;; Single import
+           (let ((sexp (cran->guix-package package-name
+                                           (or (assoc-ref opts 'repo) 'cran))))
+             (unless sexp
+               (leave (_ "failed to download description for package '~a'~%")
+                      package-name))
+             sexp)))
       (()
        (leave (_ "too few arguments~%")))
       ((many ...)