From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2JovGhdtfGFBwgAAgWs5BA (envelope-from ) for ; Fri, 29 Oct 2021 23:52:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id MCs1FRdtfGFLHQAAbx9fmQ (envelope-from ) for ; Fri, 29 Oct 2021 21:52:23 +0000 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 1E6A22D69B for ; Fri, 29 Oct 2021 23:52:22 +0200 (CEST) Received: from localhost ([::1]:55414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgZnR-0000se-9M for larch@yhetil.org; Fri, 29 Oct 2021 17:52:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgZXe-0002OZ-P7 for guix-patches@gnu.org; Fri, 29 Oct 2021 17:36:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgZXe-0002kc-Af for guix-patches@gnu.org; Fri, 29 Oct 2021 17:36:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mgZXe-0006E9-0e for guix-patches@gnu.org; Fri, 29 Oct 2021 17:36:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51493] [PATCH 2/5] import: cran: Allow imports of a specific version. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 29 Oct 2021 21:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51493 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51493@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 51493-submit@debbugs.gnu.org id=B51493.163554335623910 (code B ref 51493); Fri, 29 Oct 2021 21:36:01 +0000 Received: (at 51493) by debbugs.gnu.org; 29 Oct 2021 21:35:56 +0000 Received: from localhost ([127.0.0.1]:56145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgZXX-0006DT-Mk for submit@debbugs.gnu.org; Fri, 29 Oct 2021 17:35:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33006) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgZXV-0006Cw-Nv for 51493@debbugs.gnu.org; Fri, 29 Oct 2021 17:35:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgZXQ-0002LI-Fg; Fri, 29 Oct 2021 17:35:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=g5oP/WKVa2AYyiThuh/XN36U+/IDk/o2TGL0xURENy8=; b=q9mezrU1jXUmdJUYQmLK vV/etAv//+u1uly1YsvGh23Fhte5LOjRhXN4I/6fUeHkp0lHo91NCHmiLytfC4hUfY/yY8N12tKQ+ glKTJ8dUNlLKvdSTLnVR/RoMdIfQnJRkq1w9xfYsp94tPg11jvksnX7cq+JRdJuXC9ERhoeypxbrA tucwznZXdU37qCx/2QEXO2aNrKT04r1xrHq9A9zVjkZxAi96qdup2iPRhcIBInoXjLnLRrL6GLXSL PAroEqwbelHqcFwqgT33kfslvAi3ZtJa6QYZtsXzr9pTXlKNdj2JWk5cCO8qZ1V8tpIFo/pYb6Tn3 2OuwfVL6FWldjA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:55462 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgZXQ-0002gP-2O; Fri, 29 Oct 2021 17:35:48 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 29 Oct 2021 23:35:36 +0200 Message-Id: <20211029213539.30291-2-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211029213539.30291-1-ludo@gnu.org> References: <20211029213539.30291-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635544342; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=g5oP/WKVa2AYyiThuh/XN36U+/IDk/o2TGL0xURENy8=; b=FT5u8QIQbbyDAJkf++JT1EZmiF+Vhwj+B8DXsElg/NHj7+uKozRpbU4wASStAe5PjeQVYn IIZuFaY1hZO5YSFFahhAzTGz/TD/L34YS/yD3Td3pf50dIrJjnugr/sVwO0ceXeC5KpzIl EEmQntxtR5JksuepezadFwZWffhFesLsqzDdP2nC6WUUUwawm9fKDxqRVDxanuFGOXC2OL OgLz2b9ig0As0TqqK/9fhCLbjOmTLt0FWBDcrHJcs38up6TX3hPUVjA4p+taNm2XK6TW+p iq3esZmlYbuwzKnvp6Q3yZJBML7Cf7aSn6glBQAxkNQNE9WpswO0r1CKJ7J5UQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635544342; a=rsa-sha256; cv=none; b=POKT2LYYTGs8HZnEXEW04MWn2KRAQh91D9oxsZ6rVuemSTKtw3he73R+lK/QjJny0Ep97m B8iX6AAHVIz/S2A2IDXZXRwj25LDwgwiGnRNGCtzQSnERmjHlRkB+n5geBI1J3UnQP2RmM vAxnGSSLQnRI36TuRTFweCXmpC9YFSc2qEzWQiIVRh9EWdk12n8UGQnNa4p370aNJ+fwcf EUZptsnyxqhisnWuSmfQjs90qgFl8MlLt7gru7xdDkcVbgDMdoD9s/qDgTBTVhoFxWoWtd BBuHx/8ZSrrfLcWM8oznIUJUzApqtobHAeE3on5ECixhMBemzqe52NzJu5GFpQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=q9mezrU1; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.08 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=q9mezrU1; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 1E6A22D69B X-Spam-Score: 2.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: iFgsWkVrRnrr * guix/import/cran.scm (download): Handle the case where URL is a list. (fetch-description-from-tarball): New procedure. (fetch-description): Add #:version parameter. Honor it when REPOSITORY is 'cran. Use 'fetch-description-from-tarball' when REPOSITORY is 'bioconductor. (description->package): SOURCE-URL may now be a list. (cran->guix-package): Pass VERSION to 'fetch-description'. (cran-recursive-import): Add #:version parameter. * guix/scripts/import/cran.scm (guix-import-cran): Expect a spec rather than a mere package name. * doc/guix.texi (Invoking guix import): Document it. --- doc/guix.texi | 6 +++ guix/import/cran.scm | 89 +++++++++++++++++++++++------------- guix/scripts/import/cran.scm | 35 +++++++------- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index b742a4808a..7645f6f01a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -11833,6 +11833,12 @@ The command command below imports metadata for the Cairo R package: guix import cran Cairo @end example +You can also ask for a specific version: + +@example +guix import cran rasterVis@@0.50.3 +@end example + When @option{--recursive} is added, the importer will traverse the dependency graph of the given upstream package recursively and generate package expressions for all those packages that are not yet in Guix. diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 5f5f73cbf4..22fae5d7cb 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -229,26 +229,61 @@ (define download (let ((store-directory (add-to-store store (basename url) #t "sha256" dir))) (values store-directory changeset))))))) - (else (download-to-store store url))))))) + (else + (match url + ((? string?) + (download-to-store store url)) + ((urls ...) + ;; Try all the URLs. A use case where this is useful is when one + ;; of the URLs is the /Archive CRAN URL. + (any (cut download-to-store store <>) urls))))))))) -(define (fetch-description repository name) +(define (fetch-description-from-tarball url) + "Fetch the tarball at URL, extra its 'DESCRIPTION' file, parse it, and +return the resulting alist." + (match (download url) + (#f #f) + (tarball + (call-with-temporary-directory + (lambda (dir) + (parameterize ((current-error-port (%make-void-port "rw+")) + (current-output-port (%make-void-port "rw+"))) + (and (zero? (system* "tar" "--wildcards" "-x" + "--strip-components=1" + "-C" dir + "-f" tarball "*/DESCRIPTION")) + (description->alist + (call-with-input-file (string-append dir "/DESCRIPTION") + read-string))))))))) + +(define* (fetch-description repository name #:optional version) "Return an alist of the contents of the DESCRIPTION file for the R package -NAME in the given REPOSITORY, or #f in case of failure. NAME is +NAME at VERSION in the given REPOSITORY, or #f in case of failure. NAME is case-sensitive." (case repository ((cran) - (let ((url (string-append %cran-url name "/DESCRIPTION"))) - (guard (c ((http-get-error? c) - (warning (G_ "failed to retrieve package information \ + (guard (c ((http-get-error? c) + (warning (G_ "failed to retrieve package information \ from ~a: ~a (~a)~%") - (uri->string (http-get-error-uri c)) - (http-get-error-code c) - (http-get-error-reason c)) - #f)) - (let* ((port (http-fetch url)) - (result (description->alist (read-string port)))) - (close-port port) - result)))) + (uri->string (http-get-error-uri c)) + (http-get-error-code c) + (http-get-error-reason c)) + #f)) + ;; When VERSION is true, we have to download the tarball to get at its + ;; 'DESCRIPTION' file; only the latest one is directly accessible over + ;; HTTP. + (if version + (let ((urls (list (string-append "mirror://cran/src/contrib/" + name "_" version ".tar.gz") + (string-append "mirror://cran/src/contrib/Archive/" + name "/" + name "_" version ".tar.gz")))) + (fetch-description-from-tarball urls)) + (let* ((url (string-append %cran-url name "/DESCRIPTION")) + (port (http-fetch url)) + (result (description->alist (read-string port)))) + (close-port port) + result)))) ((bioconductor) ;; Currently, the bioconductor project does not offer a way to access a ;; package's DESCRIPTION file over HTTP, so we determine the version, @@ -257,22 +292,13 @@ (define (fetch-description repository name) (and (latest-bioconductor-package-version name) #t) (and (latest-bioconductor-package-version name 'annotation) 'annotation) (and (latest-bioconductor-package-version name 'experiment) 'experiment))) + ;; TODO: Honor VERSION. (version (latest-bioconductor-package-version name type)) (url (car (bioconductor-uri name version type))) - (tarball (download url))) - (call-with-temporary-directory - (lambda (dir) - (parameterize ((current-error-port (%make-void-port "rw+")) - (current-output-port (%make-void-port "rw+"))) - (and (zero? (system* "tar" "--wildcards" "-x" - "--strip-components=1" - "-C" dir - "-f" tarball "*/DESCRIPTION")) - (and=> (description->alist (with-input-from-file - (string-append dir "/DESCRIPTION") read-string)) - (lambda (meta) - (if (boolean? type) meta - (cons `(bioconductor-type . ,type) meta)))))))))) + (meta (fetch-description-from-tarball url))) + (if (boolean? type) + meta + (cons `(bioconductor-type . ,type) meta)))) ((git) (and (string-prefix? "http" name) ;; Download the git repository at "NAME" @@ -485,7 +511,7 @@ (define (description->package repository meta) ((bioconductor) (list (assoc-ref meta 'bioconductor-type))) (else '()))) - ((url rest ...) url) + ((urls ...) urls) ((? string? url) url) (_ #f))))) (git? (assoc-ref meta 'git)) @@ -592,7 +618,7 @@ (define cran->guix-package (lambda* (package-name #:key (repo 'cran) version) "Fetch the metadata for PACKAGE-NAME from REPO and return the `package' s-expression corresponding to that package, or #f on failure." - (let ((description (fetch-description repo package-name))) + (let ((description (fetch-description repo package-name version))) (if description (description->package repo description) (case repo @@ -610,8 +636,9 @@ (define cran->guix-package (&message (message "couldn't find meta-data for R package"))))))))))) -(define* (cran-recursive-import package-name #:key (repo 'cran)) +(define* (cran-recursive-import package-name #:key (repo 'cran) version) (recursive-import package-name + #:version version #:repo repo #:repo->guix-package cran->guix-package #:guix-name cran-guix-name)) diff --git a/guix/scripts/import/cran.scm b/guix/scripts/import/cran.scm index 3e4b038cc4..2934d4300a 100644 --- a/guix/scripts/import/cran.scm +++ b/guix/scripts/import/cran.scm @@ -27,8 +27,8 @@ (define-module (guix scripts import cran) #:use-module (guix import utils) #:use-module (guix scripts import) #:use-module (srfi srfi-1) - #:use-module (srfi srfi-11) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-71) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (guix-import-cran)) @@ -98,21 +98,24 @@ (define (parse-options) (reverse opts)))) (parameterize ((%input-style (assoc-ref opts 'style))) (match args - ((package-name) - (if (assoc-ref opts 'recursive) - ;; Recursive import - (with-error-handling - (map package->definition - (filter identity - (cran-recursive-import package-name - #:repo (or (assoc-ref opts 'repo) 'cran))))) - ;; Single import - (let ((sexp (cran->guix-package package-name - #:repo (or (assoc-ref opts 'repo) 'cran)))) - (unless sexp - (leave (G_ "failed to download description for package '~a'~%") - package-name)) - sexp))) + ((spec) + (let ((name version (package-name->name+version spec))) + (if (assoc-ref opts 'recursive) + ;; Recursive import + (with-error-handling + (map package->definition + (filter identity + (cran-recursive-import name + #:version version + #:repo (or (assoc-ref opts 'repo) 'cran))))) + ;; Single import + (let ((sexp (cran->guix-package name + #:version version + #:repo (or (assoc-ref opts 'repo) 'cran)))) + (unless sexp + (leave (G_ "failed to download description for package '~a'~%") + name)) + sexp)))) (() (leave (G_ "too few arguments~%"))) ((many ...) -- 2.33.0