diff mbox

[5/7] import cran: Add recursive importer.

Message ID 1464018008-1767-6-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/import/cran.scm (recursive-import): New variable.
---
 guix/import/cran.scm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox

Patch

diff --git a/guix/import/cran.scm b/guix/import/cran.scm
index 522df3e..907441e 100644
--- a/guix/import/cran.scm
+++ b/guix/import/cran.scm
@@ -33,8 +33,10 @@ 
   #:use-module ((guix build-system r) #:select (cran-uri bioconductor-uri))
   #:use-module (guix upstream)
   #:use-module (guix packages)
+  #:use-module (gnu packages)
   #:export (cran->guix-package
             bioconductor->guix-package
+            recursive-import
             %cran-updater
             %bioconductor-updater))
 
@@ -236,6 +238,25 @@  s-expression corresponding to that package, or #f on failure."
 ;; * Then follow
 ;;   https://r-forge.r-project.org/R/?group_id=929 with the given group_id.
 
+(define* (recursive-import package-name #:optional (repo 'cran))
+  (define (iter name imported)
+    ;; FIXME: this might fail, so catch errors
+    (receive (package dependencies)
+        (cran->guix-package name repo)
+      (if package
+          (let* ((new-entry    (cons name (list package)))
+                 (imported     (cons new-entry imported))
+                 (dependencies (filter (lambda (dependency)
+                                         (and (not (assoc dependency imported))
+                                              (null? (find-packages-by-name (guix-name dependency)))))
+                                       dependencies)))
+            (fold iter imported dependencies))
+          (begin
+            (format #t "error: failed to import package ~a from archive ~a.\n" name repo)
+            imported))))
+  (iter package-name '()))
+
+
 
 ;;;
 ;;; Updater.