From patchwork Tue Aug 6 19:17:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 14879 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5856717264; Tue, 6 Aug 2019 20:18:11 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 07BBA1725C for ; Tue, 6 Aug 2019 20:18:11 +0100 (BST) Received: from localhost ([::1]:35874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv4yI-0001bH-NS for patchwork@mira.cbaines.net; Tue, 06 Aug 2019 15:18:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49137) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv4yD-0001WV-To for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hv4yC-00044d-89 for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hv4yA-00043W-CG for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hv4yA-0003dp-4Y for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36948] [PATCH 2/2] import: cpan: Adapt for the change to guile-json version 3. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 06 Aug 2019 19:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36948 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36948@debbugs.gnu.org Received: via spool by 36948-submit@debbugs.gnu.org id=B36948.156511905213949 (code B ref 36948); Tue, 06 Aug 2019 19:18:02 +0000 Received: (at 36948) by debbugs.gnu.org; 6 Aug 2019 19:17:32 +0000 Received: from localhost ([127.0.0.1]:37793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hv4xf-0003cq-Qg for submit@debbugs.gnu.org; Tue, 06 Aug 2019 15:17:32 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33936) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hv4xd-0003a5-OE for 36948@debbugs.gnu.org; Tue, 06 Aug 2019 15:17:30 -0400 Received: from localhost (220.185.93.209.dyn.plus.net [209.93.185.220]) by mira.cbaines.net (Postfix) with ESMTPSA id 0109217261 for <36948@debbugs.gnu.org>; Tue, 6 Aug 2019 20:17:28 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id ab168cbf for <36948@debbugs.gnu.org>; Tue, 6 Aug 2019 19:17:28 +0000 (UTC) From: Christopher Baines Date: Tue, 6 Aug 2019 20:17:28 +0100 Message-Id: <20190806191728.22923-2-mail@cbaines.net> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190806191728.22923-1-mail@cbaines.net> References: <20190806191728.22923-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches In guile-json version 3, JSON objects are represented as hash tables, rather than alists. * guix/import/cpan.scm (string->license): Change the match expression to match on lists, rather than vectors. (module->dist-name, cpan-source-url, cpan-version): Change assoc-ref to hash-ref. (cpan-module->sexp): Change assoc-ref to hash-ref, and assoc-ref* to hash-ref*. * tests/cpan.scm ("source-url-http", "source-url-https"): Convert the alist to a hash table. --- guix/import/cpan.scm | 30 ++++++++++++++++-------------- tests/cpan.scm | 13 ++++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm index ec86f11743..0be37e715e 100644 --- a/guix/import/cpan.scm +++ b/guix/import/cpan.scm @@ -34,7 +34,7 @@ #:use-module (guix ui) #:use-module ((guix download) #:select (download-to-store url-fetch)) #:use-module ((guix import utils) #:select (factorize-uri - flatten assoc-ref*)) + flatten hash-ref*)) #:use-module (guix import json) #:use-module (guix packages) #:use-module (guix upstream) @@ -76,8 +76,8 @@ ;; ssleay ;; sun ("zlib" 'zlib) - (#(x) (string->license x)) - (#(lst ...) `(list ,@(map string->license lst))) + ((x) (string->license x)) + ((lst ...) `(list ,@(map string->license lst))) (_ #f))) (define (module->name module) @@ -88,11 +88,11 @@ "Return the base distribution module for a given module. E.g. the 'ok' module is distributed with 'Test::Simple', so (module->dist-name \"ok\") would return \"Test-Simple\"" - (assoc-ref (json-fetch (string-append - "https://fastapi.metacpan.org/v1/module/" - module - "?fields=distribution")) - "distribution")) + (hash-ref (json-fetch (string-append + "https://fastapi.metacpan.org/v1/module/" + module + "?fields=distribution")) + "distribution")) (define (package->upstream-name package) "Return the CPAN name of PACKAGE." @@ -122,12 +122,12 @@ or #f on failure. MODULE should be e.g. \"Test::Script\"" (define (cpan-source-url meta) "Return the download URL for a module's source tarball." (regexp-substitute/global #f "http[s]?://cpan.metacpan.org" - (assoc-ref meta "download_url") + (hash-ref meta "download_url") 'pre "mirror://cpan" 'post)) (define (cpan-version meta) "Return the version number from META." - (match (assoc-ref meta "version") + (match (hash-ref meta "version") ((? number? version) ;; version is sometimes not quoted in the module json, so it gets ;; imported into Guile as a number, so convert it to a string. @@ -183,7 +183,7 @@ depend on (gnu packages perl)." "Return the `package' s-expression for a CPAN module from the metadata in META." (define name - (assoc-ref meta "distribution")) + (hash-ref meta "distribution")) (define (guix-name name) (if (string-prefix? "perl-" name) @@ -198,7 +198,9 @@ META." (match (flatten (map (lambda (ph) (filter-map (lambda (t) - (assoc-ref* meta "metadata" "prereqs" ph t)) + (and=> (hash-ref* meta "metadata" "prereqs" ph t) + (lambda (h) + (hash-map->list cons h)))) '("requires" "recommends" "suggests"))) phases)) (#f @@ -251,9 +253,9 @@ META." ,@(maybe-inputs 'propagated-inputs (convert-inputs '("runtime"))) (home-page ,(cpan-home name)) - (synopsis ,(assoc-ref meta "abstract")) + (synopsis ,(hash-ref meta "abstract")) (description fill-in-yourself!) - (license ,(string->license (assoc-ref meta "license")))))) + (license ,(string->license (hash-ref meta "license")))))) (define (cpan->guix-package module-name) "Fetch the metadata for PACKAGE-NAME from metacpan.org, and return the diff --git a/tests/cpan.scm b/tests/cpan.scm index 189dd027e6..cdd6c0e76a 100644 --- a/tests/cpan.scm +++ b/tests/cpan.scm @@ -24,7 +24,8 @@ #:use-module (guix tests) #:use-module (guix grafts) #:use-module (srfi srfi-64) - #:use-module (ice-9 match)) + #:use-module (ice-9 match) + #:use-module (ice-9 hash-table)) ;; Globally disable grafts because they can trigger early builds. (%graft? #f) @@ -109,14 +110,16 @@ (test-equal "source-url-http" ((@@ (guix import cpan) cpan-source-url) - `(("download_url" . - "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))) + (alist->hash-table + `(("download_url" . + "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))) "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") (test-equal "source-url-https" ((@@ (guix import cpan) cpan-source-url) - `(("download_url" . - "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))) + (alist->hash-table + `(("download_url" . + "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))) "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") (test-end "cpan")