From patchwork Mon Mar 24 07:29:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 40770 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 3A1CE27BBE9; Mon, 24 Mar 2025 07:31:01 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 76A6227BBEB for ; Mon, 24 Mar 2025 07:30:58 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1twcGG-0004r2-4Q; Mon, 24 Mar 2025 03:30:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1twcG6-0004eC-RY for guix-patches@gnu.org; Mon, 24 Mar 2025 03:30:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1twcG6-00030G-GE for guix-patches@gnu.org; Mon, 24 Mar 2025 03:30:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=e49lRb8VzZ28MM+vbL4epTAQw9CT5H7gXjiMc/yPkWw=; b=IBCKeThJ63w53BqnyzLD6AaravZOTnHPTtLx1BbHGWaOFivT28qhz2nqwxOjkiW5O0g5OwWsD9xK8dI7ybn/x5SgMrLB8Of2Hat2NI5pAGNCGdxAUezg5MIpBUj1XsbtA6UigwvsYKDTHf1m3RE0qOEAg2eUuNcfEmZ5GdxIoHGxZFiDaG64v3Jcr/9Rp3mX4WqeHyo2H7OjbhvU80tY4HCAnXNwsI6GsP1WoiLxfHcVNNUMFHfFbgqmT1Z145qyQXRgwxeObaAj0ZcwEjs9R9KgG6VUVX84Ql77Kk2Zw58cP9jJsIj2F3n5FYVn4Y/YuJlVfxg4lULbCUw55C3vDw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1twcG6-0005VT-9z for guix-patches@gnu.org; Mon, 24 Mar 2025 03:30:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77231] [PATCH 5/6] import: npm-binary: Handle vector of licenses. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 24 Mar 2025 07:30:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77231 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77231@debbugs.gnu.org Cc: jelle.licht@fsfe.org, Nicolas Graves Received: via spool by 77231-submit@debbugs.gnu.org id=B77231.174280138421060 (code B ref 77231); Mon, 24 Mar 2025 07:30:06 +0000 Received: (at 77231) by debbugs.gnu.org; 24 Mar 2025 07:29:44 +0000 Received: from localhost ([127.0.0.1]:53985 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1twcFi-0005TR-VN for submit@debbugs.gnu.org; Mon, 24 Mar 2025 03:29:43 -0400 Received: from 7.mo563.mail-out.ovh.net ([46.105.59.58]:57971) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twcFa-0005SP-Fs for 77231@debbugs.gnu.org; Mon, 24 Mar 2025 03:29:35 -0400 Received: from director2.derp.mail-out.ovh.net (director2.derp.mail-out.ovh.net [79.137.60.36]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id 4ZLl706s7gz1WFs; Mon, 24 Mar 2025 07:29:32 +0000 (UTC) Received: from director2.derp.mail-out.ovh.net (director2.derp.mail-out.ovh.net. [127.0.0.1]) by director2.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for <77231@debbugs.gnu.org>; Mon, 24 Mar 2025 07:29:32 +0000 (UTC) Received: from mta6.priv.ovhmail-u1.ea.mail.ovh.net (unknown [10.110.96.120]) by director2.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4ZLl706H7Szy6K; Mon, 24 Mar 2025 07:29:32 +0000 (UTC) Received: from ngraves.fr (unknown [10.1.6.7]) by mta6.priv.ovhmail-u1.ea.mail.ovh.net (Postfix) with ESMTPSA id 2D5C7D43CD4; Mon, 24 Mar 2025 07:29:32 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-110S0043dc162e7-0030-47cd-ab3a-efc997541216, AEA14DA1325383AAD40887B56448FDDF9DC3A193) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Mon, 24 Mar 2025 08:29:16 +0100 Message-ID: <20250324072925.19588-5-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250324072925.19588-1-ngraves@ngraves.fr> References: <20250324072925.19588-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 710442844043928290 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduheeludejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeejffeitddtfeevtdeugffhveeuvdegueeftefggfffvdevffeguddvgfefveehgeenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhnphhmjhhsrdhorhhgnecukfhppeduvdejrddtrddtrddupdeltddrledvrdduudejrddugeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehnghhrrghvvghssehnghhrrghvvghsrdhfrhdpnhgspghrtghpthhtohepfedprhgtphhtthhopeejjedvfeduseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepjhgvlhhlvgdrlhhitghhthesfhhsfhgvrdhorhhgpdhrtghpthhtohepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdfovfetjfhoshhtpehmohehieefmgdpmhhouggvpehsmhhtphhouhht DKIM-Signature: a=rsa-sha256; bh=e49lRb8VzZ28MM+vbL4epTAQw9CT5H7gXjiMc/yPkWw=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1742801373; v=1; b=jA3l2ko6P12Ek61zO9m8b8F69qilLrPrti67PoRTSN7YY0quaXHd0DcG4HzeaTBGyKUavBmW hcCaXsJV/5WlURs0dHDgSWLz291fjFPambW578StraHNuP9Wh56iNjwNG7mDvZU0LZRjOKrI+Q4 2SsVgtbnuSpY/3ae+Z7zgDtftEVoVEI406TlwWe1br4bE4lihVT2tg17ub/rMBxTxFJYcxkoGZp kSflWcUtUtmq8i0zOUquVmzdO2gLc7hQVUB1X1iIIM2z1jfbFuKJUSVJy1Kr+DNX0lxe7Vhx268 k/ncANZwW9MiW+Jf11paMjczjEmK79AWtAoIcpUhisYSg== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/import/npm-binary.scm ()[license]: Handle the case where a vector of licenses is used. * tests/npm-binary.scm (foo-json): Redefine as a procedure with license keyword. (test-source-hash): Redefine with direct reference to test-source. (foo-sexp): Redefine as a procedure with license keyword. (npm-binary->guix-package test): Use foo-json and foo-sexp. (npm-binary->guix-package with multiple licenses): Add test. --- guix/import/npm-binary.scm | 16 +++- tests/npm-binary.scm | 158 +++++++++++++++++++++---------------- 2 files changed, 102 insertions(+), 72 deletions(-) diff --git a/guix/import/npm-binary.scm b/guix/import/npm-binary.scm index 60d7c07a8e..01079c2814 100644 --- a/guix/import/npm-binary.scm +++ b/guix/import/npm-binary.scm @@ -105,7 +105,17 @@ (define-json-mapping make-package-revision package-revision? (match (assoc "type" alist) ((_ . (? string? type)) (spdx-string->license type)) - (_ #f))))) + (_ #f))) + ((? vector? vector) + (match (filter-map + (match-lambda + ((? string? str) (spdx-string->license str)) + (_ #f)) + (vector->list vector)) + ((license rest ...) + (cons* license rest)) + ((license) + license))))) (description package-revision-description ;string "description" empty-or-string) (dist package-revision-dist "dist" json->dist)) ;dist @@ -250,7 +260,9 @@ (define resolve-spec (home-page ,home-page) (synopsis ,synopsis) (description ,description) - (license ,license)) + (license ,(if (list? license) + `(list ,@license) + license))) (map (match-lambda (($ name version) (list name (semver->string version)))) resolved-deps)))) diff --git a/tests/npm-binary.scm b/tests/npm-binary.scm index 0cc2864546..b1c6174020 100755 --- a/tests/npm-binary.scm +++ b/tests/npm-binary.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2024 Jelle Licht +;;; Copyright © 2025 Nicolas Graves ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,42 +25,35 @@ (define-module (test-npm-binary) #:use-module (srfi srfi-64) #:use-module (ice-9 iconv) #:use-module (ice-9 match) + #:use-module (json) #:export (run-test)) -(define foo-json - "{ - \"name\": \"foo\", - \"dist-tags\": { - \"latest\": \"1.2.3\", - \"next\": \"2.0.1-beta4\" - }, - \"description\": \"General purpose utilities to foo your bars\", - \"homepage\": \"https://github.com/quartz/foo\", - \"repository\": \"quartz/foo\", - \"versions\": { - \"1.2.3\": { - \"name\": \"foo\", - \"description\": \"General purpose utilities to foo your bars\", - \"version\": \"1.2.3\", - \"author\": \"Jelle Licht \", - \"devDependencies\": { - \"node-megabuilder\": \"^0.0.2\" - }, - \"dependencies\": { - \"bar\": \"^0.1.0\" - }, - \"repository\": { - \"url\": \"quartz/foo\" - }, - \"homepage\": \"https://github.com/quartz/foo\", - \"license\": \"MIT\", - \"dist\": { - \"tarball\": \"https://registry.npmjs.org/foo/-/foo-1.2.3.tgz\" - } - } - } -}") +(define* (foo-json #:key (license "MIT")) + "Create a JSON description of an example foo npm package, optionally using a +different @var{license}." + (scm->json-string + `((name . "foo") + (dist-tags . ((latest . "1.2.3") + (next . "2.0.1-beta4"))) + (description . "General purpose utilities to foo your bars") + (homepage . "https://github.com/quartz/foo") + (repository . "quartz/foo") + (versions + . ((1.2.3 + . ((name . "foo") + (description . "General purpose utilities to foo your bars") + (version . "1.2.3") + (author . "Jelle Licht ") + (devDependencies . ((node-megabuilder . "^0.0.2"))) + (dependencies . ((bar . "^0.1.0"))) + (repository . ((url . "quartz/foo"))) + (homepage . "https://github.com/quartz/foo") + (license . ,license) + (dist + . ((tarball + . "https://registry.npmjs.org/foo/-/foo-1.2.3.tgz")))))))))) +;; Dependency JSON for the bar package (define bar-json "{ \"name\": \"bar\", @@ -87,61 +81,85 @@ (define bar-json } }") -(define test-source-hash - "") - (define test-source "Empty file\n") +(define test-source-hash + (bytevector->nix-base32-string + (gcrypt-sha256 (string->bytevector test-source "utf-8")))) + (define have-guile-semver? (false-if-exception (resolve-interface '(semver)))) +(define* (foo-sexp #:key (license 'license:expat)) + `(package + (name "node-foo") + (version "1.2.3") + (source (origin + (method url-fetch) + (uri "https://registry.npmjs.org/foo/-/foo-1.2.3.tgz") + (sha256 + (base32 "1n0h7zg9zzv4f7yn2gp0mq1v107im7pi6qq4k6q86rixz71ijklh")))) + (build-system node-build-system) + (arguments + (list #:tests? #f + #:phases + (gexp (modify-phases %standard-phases + (delete 'build) + (add-after 'patch-dependencies 'delete-dev-dependencies + (lambda _ + (modify-json + (delete-dependencies '("node-megabuilder"))))))))) + (inputs (list node-bar-0.1.2)) + (home-page "https://github.com/quartz/foo") + (synopsis "General purpose utilities to foo your bars") + (description "General purpose utilities to foo your bars") + (license ,license))) + (test-begin "npm") (unless have-guile-semver? (test-skip 1)) -(test-assert "npm-binary->guix-package" +(test-assert "npm-binary->guix-package base case" (mock ((guix http-client) http-fetch (lambda* (url #:rest _) (match url ("https://registry.npmjs.org/foo" - (values (open-input-string foo-json) - (string-length foo-json))) + (let ((json-foo (foo-json))) + (values (open-input-string json-foo) + (string-length json-foo)))) ("https://registry.npmjs.org/bar" (values (open-input-string bar-json) (string-length bar-json))) ("https://registry.npmjs.org/foo/-/foo-1.2.3.tgz" - (set! test-source-hash - (bytevector->nix-base32-string - (gcrypt-sha256 (string->bytevector test-source "utf-8")))) (values (open-input-string test-source) (string-length test-source)))))) - (match (npm-binary->guix-package "foo") - (`(package - (name "node-foo") - (version "1.2.3") - (source (origin - (method url-fetch) - (uri "https://registry.npmjs.org/foo/-/foo-1.2.3.tgz") - (sha256 - (base32 - ,test-source-hash)))) - (build-system node-build-system) - (arguments - (list #:tests? #f - #:phases - (gexp (modify-phases %standard-phases - (delete 'build) - (add-after 'patch-dependencies 'delete-dev-dependencies - (lambda _ - (modify-json - (delete-dependencies '("node-megabuilder"))))))))) - (inputs (list node-bar-0.1.2)) - (home-page "https://github.com/quartz/foo") - (synopsis "General purpose utilities to foo your bars") - (description "General purpose utilities to foo your bars") - (license license:expat)) - #t) - (x - (pk 'fail x #f))))) + (let ((sexp-foo (foo-sexp))) + (match (npm-binary->guix-package "foo") + (sexp-foo + #t) + (x + (pk 'fail x #f)))))) + +(test-assert "npm-binary->guix-package with multiple licenses" + (mock ((guix http-client) http-fetch + (lambda* (url #:rest _) + (match url + ("https://registry.npmjs.org/foo" + (let ((json-foo (foo-json #:license #("MIT" "Apache2.0")))) + (values (open-input-string json-foo) + (string-length json-foo)))) + ("https://registry.npmjs.org/bar" + (values (open-input-string bar-json) + (string-length bar-json))) + ("https://registry.npmjs.org/foo/-/foo-1.2.3.tgz" + (values (open-input-string test-source) + (string-length test-source)))))) + (let ((sexp-foo (foo-sexp + #:license '(list license:expat license:asl2.0)))) + (match (npm-binary->guix-package "foo") + (sexp-foo + #t) + (x + (pk 'fail x #f)))))) (test-end "npm")