import: stackage: Avoid using (guix ui) in importer code.

* guix/import/stackage.scm (stackage->guix-package, stackage-lts-info-fetch):
  Raise 'message' condition instead of using 'leave' from (guix ui).
* guix/scripts/import/stackage.scm (guix-import-stackage): Handle conditions.
This commit is contained in:
Federico Beffa 2017-02-11 18:18:45 +01:00
parent 4fc282b32a
commit 57075ade97
No known key found for this signature in database
GPG Key ID: 58936E0E2F1B5A4C
2 changed files with 17 additions and 12 deletions

View File

@ -21,12 +21,13 @@
#:use-module (ice-9 regex) #:use-module (ice-9 regex)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
#:use-module (guix import json) #:use-module (guix import json)
#:use-module (guix import hackage) #:use-module (guix import hackage)
#:use-module (guix memoization) #:use-module (guix memoization)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module (guix upstream) #:use-module (guix upstream)
#:use-module (guix ui)
#:export (stackage->guix-package #:export (stackage->guix-package
%stackage-updater)) %stackage-updater))
@ -49,6 +50,9 @@
((_ ("packages" pkg ...)) pkg) ((_ ("packages" pkg ...)) pkg)
(_ '()))) (_ '())))
(define (leave-with-message fmt . args)
(raise (condition (&message (message (apply format #f fmt args))))))
(define stackage-lts-info-fetch (define stackage-lts-info-fetch
;; "Retrieve the information about the LTS Stackage release VERSION." ;; "Retrieve the information about the LTS Stackage release VERSION."
(memoize (memoize
@ -59,7 +63,7 @@
(lts-info (json-fetch url))) (lts-info (json-fetch url)))
(if lts-info (if lts-info
(reverse lts-info) (reverse lts-info)
(leave (_ "LTS release version not found: ~A~%") version)))))) (leave-with-message "LTS release version not found: ~a" version))))))
(define (stackage-package-name pkg-info) (define (stackage-package-name pkg-info)
(assoc-ref pkg-info "name")) (assoc-ref pkg-info "name"))
@ -99,7 +103,7 @@ included in the Stackage LTS release."
(hackage->guix-package name-version (hackage->guix-package name-version
#:include-test-dependencies? #:include-test-dependencies?
include-test-dependencies?) include-test-dependencies?)
(leave (_ "package not found: ~A~%") package-name)))) (leave-with-message "~a: Stackage package not found" package-name))))
;;; ;;;

View File

@ -98,15 +98,16 @@ Import and convert the LTS Stackage package for PACKAGE-NAME.\n"))
(reverse opts)))) (reverse opts))))
(match args (match args
((package-name) ((package-name)
(let ((sexp (stackage->guix-package (with-error-handling
package-name (let ((sexp (stackage->guix-package
#:include-test-dependencies? package-name
(assoc-ref opts 'include-test-dependencies?) #:include-test-dependencies?
#:lts-version (assoc-ref opts 'lts-version)))) (assoc-ref opts 'include-test-dependencies?)
(unless sexp #:lts-version (assoc-ref opts 'lts-version))))
(leave (_ "failed to download cabal file for package '~a'~%") (unless sexp
package-name)) (leave (_ "failed to download cabal file for package '~a'~%")
sexp)) package-name))
sexp)))
(() (()
(leave (_ "too few arguments~%"))) (leave (_ "too few arguments~%")))
((many ...) ((many ...)