From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGh5S-0007ad-3o for guix-patches@gnu.org; Thu, 10 May 2018 04:38:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGh5O-0002WB-4N for guix-patches@gnu.org; Thu, 10 May 2018 04:38:06 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:48019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGh5N-0002W0-Ts for guix-patches@gnu.org; Thu, 10 May 2018 04:38:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fGh5N-0002Lh-ND for guix-patches@gnu.org; Thu, 10 May 2018 04:38:01 -0400 Subject: [bug#31399] [PATCH] import: elpa: Implement recursive import. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGh4t-0007aK-SI for guix-patches@gnu.org; Thu, 10 May 2018 04:37:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGh4p-0001c4-Tt for guix-patches@gnu.org; Thu, 10 May 2018 04:37:31 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:34178) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGh4p-0001am-HT for guix-patches@gnu.org; Thu, 10 May 2018 04:37:27 -0400 Received: by mail-wr0-x22b.google.com with SMTP id p18-v6so1141364wrm.1 for ; Thu, 10 May 2018 01:37:27 -0700 (PDT) Received: from magnolia (ppp92-100-98-177.pppoe.avangarddsl.ru. [92.100.98.177]) by smtp.gmail.com with ESMTPSA id b185-v6sm486355wmb.25.2018.05.10.01.37.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 01:37:25 -0700 (PDT) From: Oleg Pykhalov Date: Thu, 10 May 2018 11:37:14 +0300 Message-ID: <87y3grykhx.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 31399@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Guix, I stole recursive importer from =E2=80=98cran=E2=80=99 and made it for =E2= =80=98elpa=E2=80=99, the patch is attached. I don't like it and want to share the code with =E2=80=98cran= =E2=80=99 importer, but I don't know how to do it without increasing complexity. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-import-elpa-Implement-recursive-import.patch Content-Transfer-Encoding: quoted-printable Content-Description: [PATCH] emacs: implement recursive-import. From=205c5023c5f343d673e96517b822b5e884ff20f714 Mon Sep 17 00:00:00 2001 From: Oleg Pykhalov Date: Thu, 10 May 2018 10:07:49 +0300 Subject: [PATCH] import: elpa: Implement recursive import. * guix/import/elpa.scm (guix-name, recursive-import): New procedures. * guix/scripts/import/elpa.scm (%options): Add 'recursive-import'. (guix-import-elpa): Add this. (show-help): Document this. * doc/guix.texi (Invoking guix import): Document this. =2D-- doc/guix.texi | 6 +++ guix/import/elpa.scm | 81 +++++++++++++++++++++++++++++++++++- guix/scripts/import/elpa.scm | 22 ++++++++-- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8b9f8721b..40d3a4c73 100644 =2D-- a/doc/guix.texi +++ b/doc/guix.texi @@ -6481,6 +6481,12 @@ signatures,, emacs, The GNU Emacs Manual}). @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa} identifier. @end itemize + +@item --recursive +@itemx -r +Traverse the dependency graph of the given upstream package recursively +and generate package expressions for all those packages that are not yet +in Guix. @end table =20 @item crate diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index 43e9eb60c..78a69dcc0 100644 =2D-- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -26,6 +26,8 @@ #:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-41) + #:use-module (gnu packages) #:use-module ((guix download) #:select (download-to-store)) #:use-module (guix import utils) #:use-module (guix http-client) @@ -37,7 +39,8 @@ #:use-module (guix packages) #:use-module ((guix utils) #:select (call-with-temporary-output-file)) #:export (elpa->guix-package =2D %elpa-updater)) + %elpa-updater + recursive-import)) =20 (define (elpa-dependencies->names deps) "Convert DEPS, a list of symbol/version pairs =C3=A0 la ELPA, to a list = of @@ -289,4 +292,80 @@ type ''." (pred package-from-gnu.org?) (latest latest-release))) =20 +(define (guix-name name) + "Return a Guix package name for a given Emacs package name." + (string-append "emacs-" (string-map (match-lambda + (#\_ #\-) + (#\. #\-) + (chr (char-downcase chr))) + name))) + +(define* (recursive-import package-name #:optional (repo 'gnu)) + "Generate a stream of package expressions for PACKAGE-NAME and all its +dependencies." + (define (propagated-inputs package) + "Return a list of package names in propagated inputs from PACKAGE." + (and=3D> (match package + ((package fields ...) (assq 'propagated-inputs fields)) + (#f #f)) + (match-lambda + ((propagated-inputs (qp ((package-name package) ...))) + (map (cut string-drop <> (string-length "emacs-")) + package-name)) + (#f #f)))) + (let* ((package (elpa->guix-package package-name repo)) + (dependencies (propagated-inputs package))) + (if (not package) + stream-null + + ;; Generate a lazy stream of package expressions for all unknown + ;; dependencies in the graph. + (let* ((make-state (lambda (queue done) + (cons queue done))) + (next (match-lambda + (((next . rest) . done) next))) + (imported (match-lambda + ((queue . done) done))) + (done? (match-lambda + ((queue . done) + (zero? (length queue))))) + (unknown? (lambda* (dependency #:optional (done '())) + (and (not (member dependency + done)) + (null? (find-packages-by-name + (guix-name dependency)))))) + (update (lambda (state new-queue) + (match state + (((head . tail) . done) + (make-state (lset-difference + equal? + (lset-union equal? new-queue = tail) + done) + (cons head done))))))) + (stream-cons + package + (stream-unfold + ;; map: produce a stream element + (lambda (state) + (elpa->guix-package (next state) repo)) + + ;; predicate + (negate done?) + + ;; generator: update the queue + (lambda (state) + (let* ((package (elpa->guix-package (next state) repo)) + (dependencies (propagated-inputs package))) + (if package + (update state (filter (cut unknown? <> + (cons (next state) + (imported state))) + dependencies)) + ;; TODO: Try the other archives before giving up + (update state (imported state))))) + + ;; initial state + (make-state (filter unknown? dependencies) + (list package-name)))))))) + ;;; elpa.scm ends here diff --git a/guix/scripts/import/elpa.scm b/guix/scripts/import/elpa.scm index 34eb16485..c49c3ac9e 100644 =2D-- a/guix/scripts/import/elpa.scm +++ b/guix/scripts/import/elpa.scm @@ -25,6 +25,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-41) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (guix-import-elpa)) @@ -45,6 +46,8 @@ Import the latest package named PACKAGE-NAME from an ELPA= repository.\n")) (display (G_ " -h, --help display this help and exit")) (display (G_ " + -r, --recursive generate package expressions for all Emac= s packages that are not yet in Guix")) + (display (G_ " -V, --version display version information and exit")) (newline) (show-bug-report-information)) @@ -62,6 +65,9 @@ Import the latest package named PACKAGE-NAME from an ELPA= repository.\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)) =20 @@ -87,10 +93,18 @@ Import the latest package named PACKAGE-NAME from an EL= PA repository.\n")) (reverse opts)))) (match args ((package-name) =2D (let ((sexp (elpa->guix-package package-name (assoc-ref opts 'rep= o)))) =2D (unless sexp =2D (leave (G_ "failed to download package '~a'~%") package-name)) =2D sexp)) + (if (assoc-ref opts 'recursive) + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (reverse (stream->list (recursive-import package-name + (or (assoc-ref op= ts 'repo) 'cran))))) + (let ((sexp (elpa->guix-package package-name (assoc-ref opts 'r= epo)))) + (unless sexp + (leave (G_ "failed to download package '~a'~%") package-nam= e)) + sexp))) (() (leave (G_ "too few arguments~%"))) ((many ...) =2D-=20 2.17.0 --=-=-= Content-Type: text/plain Oleg. --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEc+OyAXw1EaDPCmAPckbhHGm3lWkFAlr0BLoACgkQckbhHGm3 lWmqkxAAob15yHX6Amhh8D0sVOXA/9Q2qqKKBpx/4vKIIkE8cH06hy92gabqkcMw mSRXxxt1iRKiGgV1uWOY9sYpNc3U9Syb4d/qARomZV+RrH2TC+gWnrVUZpdyzsg/ cqQpBu2tknivZBN8yUrHocEDBlkxuRuQqvhBGSNQvfNyaZNoZK0befZkvWAoU+jN tV8XSa/jW2uER+rvzzI1teaniieZ9FbPqu/WyaQ5SLJszhfOH2ajOt1WcowG7pkQ Pq1OHOua+YweUD+5Wu05xSnwuh1dEhEcQuz3aModYCY+RiJ+MJ4bBXg6NTzHdaDu wC/38tkNeeUx79JAfoJVEpOzXrumSwGRpcDyUCOV5c7Jy1Ul/85xFyn4MTt+w30r yNYx6TfvVgRT/s0XytKmLOKHitbKCSB/3hWYkjWQqyA/VutGm8YvXsyLmCUYzIQS yiApV9bhAjc9WH3Tty+XgJnchi7/sUWEv0/oda4mdthNLuPEgVNCW7xWMxKXFJWg hyhCmYz9hzI9U7XiORUMJpFMIz17W07q52xJvmOyEfPoHqIyi8RwokbkSkpYn0+S CV3vZmb/NIumYkT1NoB4yvxeQKBWMw86/MFl8iIFiOaN4Ra/LWaRtA2kgjLqS2px P/gIt1ytdS//fx03PO176bVrCe/8L67MN4vhibVtOJuktFUpKAU= =9Yny -----END PGP SIGNATURE----- --==-=-=--