From patchwork Fri Sep 9 13:47:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taiju HIGASHI X-Patchwork-Id: 42358 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 401A027BBEA; Fri, 9 Sep 2022 14:51:38 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED 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 56C2327BBE9 for ; Fri, 9 Sep 2022 14:51:37 +0100 (BST) Received: from localhost ([::1]:46502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oWePw-0001qN-FR for patchwork@mira.cbaines.net; Fri, 09 Sep 2022 09:51:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWeNU-000687-3X for guix-patches@gnu.org; Fri, 09 Sep 2022 09:49:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44217) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oWeNS-0004yY-Eg for guix-patches@gnu.org; Fri, 09 Sep 2022 09:49:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oWeNS-0000Wm-A2 for guix-patches@gnu.org; Fri, 09 Sep 2022 09:49:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57694] [PATCH 1/1] import: gem: Support for importing a specified version of a gem. References: <20220909134434.18497-1-higashi@taiju.info> In-Reply-To: <20220909134434.18497-1-higashi@taiju.info> Resent-From: Taiju HIGASHI Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 09 Sep 2022 13:49:02 +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: 57694@debbugs.gnu.org Cc: Taiju HIGASHI Received: via spool by 57694-submit@debbugs.gnu.org id=B57694.16627312821936 (code B ref 57694); Fri, 09 Sep 2022 13:49:02 +0000 Received: (at 57694) by debbugs.gnu.org; 9 Sep 2022 13:48:02 +0000 Received: from localhost ([127.0.0.1]:32916 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oWeMT-0000Us-AR for submit@debbugs.gnu.org; Fri, 09 Sep 2022 09:48:02 -0400 Received: from mail-pf1-f175.google.com ([209.85.210.175]:37418) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oWeMQ-0000U4-Qv for 57694@debbugs.gnu.org; Fri, 09 Sep 2022 09:48:00 -0400 Received: by mail-pf1-f175.google.com with SMTP id 145so1719438pfw.4 for <57694@debbugs.gnu.org>; Fri, 09 Sep 2022 06:47:58 -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:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=mwWtGSDH+K8Ubu75W/GxodWDNYkwyUlGslPZrHjVyFU=; b=fPlGdbTj9pqLhahkr4kuMOoNKO9TJ6aC+BL3/HMDpIDhu3yWHVI5xjZs3wy+20usMZ M6ONHIyidxATsPKqlcYI55qsrRIk7bJdDj6XcyGT8lk5p/ZQ/WH/SY2ykrPjF/y5AuA5 0HzNgdar3kaiAf6uPkR/bT9cnKZRihmEkkBZl4qxfRJNJDwDFJhY5b9aKtklJZtA9rti kwsJ0C3sK2gAscvNUHl7hW9DjQ3VIcBfvIy3RHnEDe/C3VTgrMPSEuO6rtvUK7fb05zr UD0R8JvizJe0Fbt4uDe5neHhC7YwmbMiEAjwpweOtj03qsO0RS4I4JtOpt9a5YHbiFJO L2gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=mwWtGSDH+K8Ubu75W/GxodWDNYkwyUlGslPZrHjVyFU=; b=gNeOznEy5u9DJ1o2oPxltWI44MZeagjvO596AxwVymeJfCcw1C1AV3bB5Tex4X+siF 38D6H5NxTm7ILojmmwHiX3/KaY1p6do5TcvOsXX+o4FpEVECv7y/S4+XXDZyLlkyKZbq XCa+WA2sRpqR/ydtH+ts/wMcRNvDeipCc0F0HFpLG7hLbTidRfWUU9FFDhwUCLxaee4L AGiWH8Ng2gbr26oyUg6OHJLNGNuynxvziLYols9kqBDETgLZZsFK6qYTETpjSogcybTd NG6F20mDcDYH/1NnMqsEcopVA6yFFZbLTbPOkKZ5/R9XeiLFXUG3SQ9806VxpCRBpAn9 DhZw== X-Gm-Message-State: ACgBeo1rAawnFrPy5zDGCrRT2kVENGGW1phxh62D1UEtW9mOUn0U9gWf fyjY6NI9iomCHu99cUIPVfOnQ+3JddN1mVXS X-Google-Smtp-Source: AA6agR5omOnv7to2D3BmLDg3a9OdNh6V4AM82kgBH1IMM+ksnNZFS7VkckmR5fwPno79vaWanMUTsw== X-Received: by 2002:a63:5a63:0:b0:42f:e143:80d4 with SMTP id k35-20020a635a63000000b0042fe14380d4mr12573987pgm.456.1662731272658; Fri, 09 Sep 2022 06:47:52 -0700 (PDT) Received: from Taix.flets-west.jp ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id q15-20020aa7960f000000b005387bf85ea0sm533978pfg.128.2022.09.09.06.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 06:47:52 -0700 (PDT) From: Taiju HIGASHI Date: Fri, 9 Sep 2022 22:47:36 +0900 Message-Id: <20220909134736.18808-2-higashi@taiju.info> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 © 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Martin Becze ;;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -81,10 +82,12 @@ (define-json-mapping make-gem-dependency 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 failure. If VERSION is #f or missing, return the latest version gem." (and=> (json-fetch - (string-append "https://rubygems.org/api/v1/gems/" name ".json")) + (if version + (string-append "https://rubygems.org/api/v2/rubygems/" name "/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 synopsis 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 #:optional 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 © 2021 Sarah Morgensen ;;; Copyright © 2021 Brice Waegeneire ;;; Copyright © 2021 Simon Tournier +;;; Copyright © 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 #:version 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 © 2016 Ricardo Wurmus ;;; Copyright © 2018 Oleg Pykhalov ;;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 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\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\", + \"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.json" + (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 + "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-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.json" + (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")