From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id eAngB1qlIWMhgwAAbAwnHQ (envelope-from ) for ; Wed, 14 Sep 2022 11:56:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gAfuB1qlIWMd9gAA9RJhRA (envelope-from ) for ; Wed, 14 Sep 2022 11:56:42 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A2D6938DEE for ; Wed, 14 Sep 2022 11:56:41 +0200 (CEST) Received: from localhost ([::1]:33544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYP8K-00058l-OD for larch@yhetil.org; Wed, 14 Sep 2022 05:56:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYP7j-00057l-EZ for guix-patches@gnu.org; Wed, 14 Sep 2022 05:56:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYP7j-0002dy-5y for guix-patches@gnu.org; Wed, 14 Sep 2022 05:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oYP7j-0001wZ-2d for guix-patches@gnu.org; Wed, 14 Sep 2022 05:56:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57694] [PATCH 1/1] import: gem: Support for importing a specified version of a gem. Resent-From: Taiju HIGASHI Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 14 Sep 2022 09:56:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57694 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: mail@cbaines.net Cc: 57694@debbugs.gnu.org Received: via spool by 57694-submit@debbugs.gnu.org id=B57694.16631493587446 (code B ref 57694); Wed, 14 Sep 2022 09:56:03 +0000 Received: (at 57694) by debbugs.gnu.org; 14 Sep 2022 09:55:58 +0000 Received: from localhost ([127.0.0.1]:53776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYP7d-0001w1-Gu for submit@debbugs.gnu.org; Wed, 14 Sep 2022 05:55:58 -0400 Received: from mail-pj1-f53.google.com ([209.85.216.53]:34735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYP7a-0001vm-7o for 57694@debbugs.gnu.org; Wed, 14 Sep 2022 05:55:56 -0400 Received: by mail-pj1-f53.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso3213721pjq.1 for <57694@debbugs.gnu.org>; Wed, 14 Sep 2022 02:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taiju-info.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:cc:references:subject:to:from:from:to:cc:subject :date; bh=h1plUxcu7XJNzT7VtKLNXuMmjJ3OxV45dcbirHDrZLw=; b=DJSmtFtoLvhbp7RfoqKhBG9AkoTt4kYWdZbWYqiYP3CcdbxNTiEU8EFzMo+pDG0s4q 9ll0Hf0tcq8rrXpSaFWc9iJ1RmqjyXPHVmVWFyaHxREkuDZjd86qjD9/ZbYnKopha4k6 2MAvv2Uhjv34q69ffhLvzbw6WtP59vKe1FHi13PefiruF7dfMoRaH0rb91c2F2DhcLFv 4dSSlcWNKiUApMmpPWNUgjtK3K2YWNiJs0XwY5vgcWsfDLzry4n7wjRzrTHc4A0MASLz 1OSloinXHiT88teJTl5KUkesI+PnCj/CjUggqdfKfhSWhr7YvWIPkQ1n2tLVZ5vP4T5Q 3K1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:cc:references:subject:to:from:x-gm-message-state :from:to:cc:subject:date; bh=h1plUxcu7XJNzT7VtKLNXuMmjJ3OxV45dcbirHDrZLw=; b=N5Llrw9tyX70XyKacUsUSdLXPhHQFz3lpOZLI2XLAfxtYqnqTkVI7owz94lZTgYZi2 85Nnp2VsSMlafEPfSncayIVRTnG1TEyuC3fxitFaFM76IPU5zmr/dXTvPCwkZho/sqYu U3Jqp43wgTi1L+eipkOhRJcARzyxcgeOvvVS+5io1fCiR4N7FJ556aC4APHInIr508Ny Z9KEeZRsaWI6yGbaXvj6ID3BeVCdkk4X3LVbm/kOCsennvaTL1gS25ywOsTz7v5uhj9R 2IhFXxuxpL0JlpawWFYSr3JvRNs/ZijV8uxVqwLTX0kmu6E/ymrvyc7uRWwfJIMxWpWT 5RdQ== X-Gm-Message-State: ACrzQf2U77VDouBCK1X3kIehM1EncudopwtVscFgj2xNm0zeuF00iQDi hO0ZZEJhNfzm886vWxkZyp9+WEFVoGXkwO5a X-Google-Smtp-Source: AMsMyM4oCUHn9jAmm3HMzsceEp3SfaN9ryBjOntqouHNyP2Tn7Al8IVGwqQc83FUds/yBjS3O07gYQ== X-Received: by 2002:a17:90b:4d0d:b0:1fb:a86d:e752 with SMTP id mw13-20020a17090b4d0d00b001fba86de752mr3858247pjb.120.1663149348071; Wed, 14 Sep 2022 02:55:48 -0700 (PDT) Received: from Taix ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id cp19-20020a170902e79300b00176be23bbb3sm10176262plb.172.2022.09.14.02.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 02:55:47 -0700 (PDT) From: Taiju HIGASHI References: <20220909134736.18808-2-higashi@taiju.info> Date: Wed, 14 Sep 2022 18:55:45 +0900 In-Reply-To: <20220909134736.18808-2-higashi@taiju.info> (Taiju HIGASHI's message of "Fri, 9 Sep 2022 22:47:36 +0900") Message-ID: <87o7vie0v2.fsf@taiju.info> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663149401; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=HtyK2rLjbjSnF6LoMQ3nbL36/mkDDHxeGUj3Bqwm6D0=; b=mt9qkAsH1JY9kxPRqw0eEs9p3V4z8sCHeU8XdBarPYjID/l/81XFWDyS5Fz740qXlZaGqF 6Vq8S5KPvTQ8cpcwRv3UPMBxYLbgnZUjZvMtCKQIcpxJrBoZEorGCmuEJ/v/GmJqvFNZ4Z x4hGdej6EbMpjRCX01aTorsOepLGjzlOq4+7EwSdW6VloByajsBBv6tZP3ibO+fiRRrPA8 qW+4YZCu8loYRXeReoCedh7znW2rgQWar3LXU5nw2Uhc7axpMxhXz8zCmIaUntN16nPnBg /hBx81h2s2bkHA2cwbolKKWTRgfxIFcSrukVnWD8jbzphdjmHlG550aNEUNYmA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663149401; a=rsa-sha256; cv=none; b=XeYB/2UrRT6cIF0MtDuncZB0GOBUTvcnjtVGKvU/knFEsjDgA+yOXNndt9TlxKg0qbW8RW USQ94aqk6kk+Kt7qCICv3xoSSphGmcQQdJ5h/NuBYCYfASolbbjo171jqEwOKg9S2MJa/O 9krq2cFW0ny6cPch8OUMHAlqzZDy6Yegkp9gjjpPm5g4dI6KPGD+Oxc7mlvvoVoEeLvgVs LXijzEcxFoLR0ndoNKWOb2mR6a4ldUmXiODs0vuIAQ9o7+888ZldIRE2NPZLx8ntKMSmMs 50kGGpMY8uqa1b7LdDFniI08PX3I16F0/yxZfBp92tUqSMDD28h5u/A1f8O4Ng== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=taiju-info.20210112.gappssmtp.com header.s=20210112 header.b=DJSmtFto; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.68 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=taiju-info.20210112.gappssmtp.com header.s=20210112 header.b=DJSmtFto; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A2D6938DEE X-Spam-Score: 2.68 X-Migadu-Scanner: scn1.migadu.com X-TUID: Lj7vAvejZPLV Hi Chris, Could you give me your opinion on this patch? Is this patch worth it? Taiju HIGASHI writes: > * guix/import/gem.scm: (rubygems-fetch, gem->guix-package) > (gem-recursive-import): Fix to fetch the specified version of the gem. > * guix/scripts/import/gem.scm (show-help): Modify the help message. > (guix-import-gem): Modify the version number to be passed to subsequent > procedures > * tests/gem.scm: Add tests. > --- > guix/import/gem.scm | 19 ++++-- > guix/scripts/import/gem.scm | 39 +++++++------ > tests/gem.scm | 113 ++++++++++++++++++++++++++++++++++++ > 3 files changed, 148 insertions(+), 23 deletions(-) > > diff --git a/guix/import/gem.scm b/guix/import/gem.scm > index 0e5bb7e635..ad1343bff4 100644 > --- a/guix/import/gem.scm > +++ b/guix/import/gem.scm > @@ -5,6 +5,7 @@ > ;;; Copyright =A9 2020, 2021 Ludovic Court=E8s > ;;; Copyright =A9 2020 Martin Becze > ;;; Copyright =A9 2021 Sarah Morgensen > +;;; Copyright =A9 2022 Taiju HIGASHI > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -81,10 +82,12 @@ (define-json-mapping make-gem-depend= ency gem-dependency? > (requirements gem-dependency-requirements)) ;string > > > -(define (rubygems-fetch name) > - "Return a record for the package NAME, or #f on failure." > +(define* (rubygems-fetch name #:optional version) > + "Return a record for the package NAME and VERSION, or #f on fail= ure. If VERSION is #f or missing, return the latest version gem." > (and=3D> (json-fetch > - (string-append "https://rubygems.org/api/v1/gems/" name ".json= ")) > + (if version > + (string-append "https://rubygems.org/api/v2/rubygems/" nam= e "/versions/" version ".json") > + (string-append "https://rubygems.org/api/v1/gems/" name ".= json"))) > json->gem)) > > (define (ruby-package-name name) > @@ -122,8 +125,11 @@ (define (make-gem-sexp name version hash home-page s= ynopsis description > > (define* (gem->guix-package package-name #:key (repo 'rubygems) version) > "Fetch the metadata for PACKAGE-NAME from rubygems.org, and return the > -`package' s-expression corresponding to that package, or #f on failure." > - (let ((gem (rubygems-fetch package-name))) > +`package' s-expression corresponding to that package, or #f on failure. > +Optionally include a VERSION string to fetch a specific version gem." > + (let ((gem (if version > + (rubygems-fetch package-name version) > + (rubygems-fetch package-name)))) > (if gem > (let* ((dependencies-names (map gem-dependency-name > (gem-dependencies-runtime > @@ -189,4 +195,5 @@ (define* (gem-recursive-import package-name #:optiona= l version) > (recursive-import package-name > #:repo '() > #:repo->guix-package gem->guix-package > - #:guix-name ruby-package-name)) > + #:guix-name ruby-package-name > + #:version version)) > diff --git a/guix/scripts/import/gem.scm b/guix/scripts/import/gem.scm > index 82deac16ad..2e646e4475 100644 > --- a/guix/scripts/import/gem.scm > +++ b/guix/scripts/import/gem.scm > @@ -4,6 +4,7 @@ > ;;; Copyright =A9 2021 Sarah Morgensen > ;;; Copyright =A9 2021 Brice Waegeneire > ;;; Copyright =A9 2021 Simon Tournier > +;;; Copyright =A9 2022 Taiju HIGASHI > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -31,6 +32,7 @@ (define-module (guix scripts import gem) > #:use-module (srfi srfi-37) > #:use-module (ice-9 match) > #:use-module (ice-9 format) > + #:use-module (ice-9 receive) > #:export (guix-import-gem)) > > > @@ -42,8 +44,9 @@ (define %default-options > '()) > > (define (show-help) > - (display (G_ "Usage: guix import gem PACKAGE-NAME > -Import and convert the RubyGems package for PACKAGE-NAME.\n")) > + (display (G_ "Usage: guix import gem PACKAGE-NAME[@VERSION] > +Import and convert the RubyGems package for PACKAGE-NAME. Optionally, a > +version can be specified after the arobas (@) character.\n")) > (display (G_ " > -h, --help display this help and exit")) > (display (G_ " > @@ -86,21 +89,23 @@ (define (parse-options) > (_ #f)) > (reverse opts)))) > (match args > - ((package-name) > - (let ((code (if (assoc-ref opts 'recursive) > - (map (match-lambda > - ((and ('package ('name name) . rest) pkg) > - `(define-public ,(string->symbol name) > - ,pkg)) > - (_ #f)) > - (gem-recursive-import package-name 'rubygems= )) > - (let ((sexp (gem->guix-package package-name))) > - (if sexp sexp #f))))) > - (match code > - ((or #f '(#f)) > - (leave (G_ "failed to download meta-data for package '~a'~%") > - package-name)) > - (_ code)))) > + ((spec) > + (receive (package-name package-version) > + (package-name->name+version spec) > + (let ((code (if (assoc-ref opts 'recursive) > + (map (match-lambda > + ((and ('package ('name name) . rest) pkg) > + `(define-public ,(string->symbol name) > + ,pkg)) > + (_ #f)) > + (gem-recursive-import package-name package= -version)) > + (let ((sexp (gem->guix-package package-name #:v= ersion package-version))) > + (if sexp sexp #f))))) > + (match code > + ((or #f '(#f)) > + (leave (G_ "failed to download meta-data for package '~a'~= %") > + package-name)) > + (_ code))))) > (() > (leave (G_ "too few arguments~%"))) > ((many ...) > diff --git a/tests/gem.scm b/tests/gem.scm > index c8fe15398e..6aa0d279dc 100644 > --- a/tests/gem.scm > +++ b/tests/gem.scm > @@ -3,6 +3,7 @@ > ;;; Copyright =A9 2016 Ricardo Wurmus > ;;; Copyright =A9 2018 Oleg Pykhalov > ;;; Copyright =A9 2021 Sarah Morgensen > +;;; Copyright =A9 2022 Taiju HIGASHI > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -44,6 +45,22 @@ (define test-foo-json > \"licenses\": [\"MIT\", \"Apache 2.0\"] > }") > > +(define test-foo-v2-json > + "{ > + \"name\": \"foo\", > + \"version\": \"2.0.0\", > + \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680= 547a8\", > + \"info\": \"A cool gem\", > + \"homepage_uri\": \"https://example.com\", > + \"dependencies\": { > + \"runtime\": [ > + { \"name\": \"bundler\" }, > + { \"name\": \"bar\" } > + ] > + }, > + \"licenses\": [\"MIT\", \"Apache 2.0\"] > +}") > + > (define test-bar-json > "{ > \"name\": \"bar\", > @@ -103,6 +120,35 @@ (define test-bundler-json > (x > (pk 'fail x #f))))) > > +(test-assert "gem->guix-package with a specific version" > + ;; Replace network resources with sample data. > + (mock ((guix http-client) http-fetch > + (lambda (url . rest) > + (match url > + ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.j= son" > + (values (open-input-string test-foo-v2-json) > + (string-length test-foo-v2-json))) > + (_ (error "Unexpected URL: " url))))) > + (match (gem->guix-package "foo" #:version "2.0.0") > + (('package > + ('name "ruby-foo") > + ('version "2.0.0") > + ('source ('origin > + ('method 'url-fetch) > + ('uri ('rubygems-uri "foo" 'version)) > + ('sha256 > + ('base32 > + "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnw= rzk")))) > + ('build-system 'ruby-build-system) > + ('propagated-inputs ('list 'bundler 'ruby-bar)) > + ('synopsis "A cool gem") > + ('description "This package provides a cool gem") > + ('home-page "https://example.com") > + ('license ('list 'license:expat 'license:asl2.0))) > + #t) > + (x > + (pk 'fail x #f))))) > + > (test-assert "gem-recursive-import" > ;; Replace network resources with sample data. > (mock ((guix http-client) http-fetch > @@ -170,4 +216,71 @@ (define test-bundler-json > (x > (pk 'fail x #f))))) > > +(test-assert "gem-recursive-import with a specific version" > + ;; Replace network resources with sample data. > + (mock ((guix http-client) http-fetch > + (lambda (url . rest) > + (match url > + ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.j= son" > + (values (open-input-string test-foo-v2-json) > + (string-length test-foo-v2-json))) > + ("https://rubygems.org/api/v1/gems/bar.json" > + (values (open-input-string test-bar-json) > + (string-length test-bar-json))) > + ("https://rubygems.org/api/v1/gems/bundler.json" > + (values (open-input-string test-bundler-json) > + (string-length test-bundler-json))) > + (_ (error "Unexpected URL: " url))))) > + (match (gem-recursive-import "foo" "2.0.0") > + ((('package > + ('name "ruby-bar") > + ('version "1.0.0") > + ('source > + ('origin > + ('method 'url-fetch) > + ('uri ('rubygems-uri "bar" 'version)) > + ('sha256 > + ('base32 > + "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk= ")))) > + ('build-system 'ruby-build-system) > + ('propagated-inputs ('list 'bundler)) > + ('synopsis "Another cool gem") > + ('description "Another cool gem") > + ('home-page "https://example.com") > + ('license #f)) ;no licensing info > + ('package > + ('name "ruby-bundler") > + ('version "1.14.2") > + ('source > + ('origin > + ('method 'url-fetch) > + ('uri ('rubygems-uri "bundler" 'version)) > + ('sha256 > + ('base32 > + "1446xiz7zg0bz7kgx9jv84y0s4hpsg61dj5l3qb0i00avc1kxd9v= ")))) > + ('build-system 'ruby-build-system) > + ('synopsis "Ruby gem bundler") > + ('description "Ruby gem bundler") > + ('home-page "https://bundler.io/") > + ('license 'license:expat)) > + ('package > + ('name "ruby-foo") > + ('version "2.0.0") > + ('source > + ('origin > + ('method 'url-fetch) > + ('uri ('rubygems-uri "foo" 'version)) > + ('sha256 > + ('base32 > + "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk= ")))) > + ('build-system 'ruby-build-system) > + ('propagated-inputs ('list 'bundler 'ruby-bar)) > + ('synopsis "A cool gem") > + ('description "This package provides a cool gem") > + ('home-page "https://example.com") > + ('license ('list 'license:expat 'license:asl2.0)))) > + #t) > + (x > + (pk 'fail x #f))))) > + > (test-end "gem") Cheers, --=20 Taiju