From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EM8TDRttfGEBwgAAgWs5BA (envelope-from ) for ; Fri, 29 Oct 2021 23:52:27 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id qJmXCBttfGEEQAAAbx9fmQ (envelope-from ) for ; Fri, 29 Oct 2021 21:52:27 +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 C4E60D8FE for ; Fri, 29 Oct 2021 23:52:26 +0200 (CEST) Received: from localhost ([::1]:56062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgZnV-0001K0-Us for larch@yhetil.org; Fri, 29 Oct 2021 17:52:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgZXf-0002Pz-7g for guix-patches@gnu.org; Fri, 29 Oct 2021 17:36:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgZXe-0002kp-SJ 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-0006EP-Pu for guix-patches@gnu.org; Fri, 29 Oct 2021 17:36:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51493] [PATCH 1/5] import: pypi: Allow imports of a specific version. References: <20211029212948.30148-1-ludo@gnu.org> In-Reply-To: <20211029212948.30148-1-ludo@gnu.org> 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:02 +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.163554335723925 (code B ref 51493); Fri, 29 Oct 2021 21:36:02 +0000 Received: (at 51493) by debbugs.gnu.org; 29 Oct 2021 21:35:57 +0000 Received: from localhost ([127.0.0.1]:56151 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgZXY-0006Di-OK for submit@debbugs.gnu.org; Fri, 29 Oct 2021 17:35:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgZXV-0006Cv-4Q for 51493@debbugs.gnu.org; Fri, 29 Oct 2021 17:35:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgZXP-0002L9-QD; Fri, 29 Oct 2021 17:35:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=pKGuDFabDBtnXQYf2yviDMuNMQmTqaqIOY4EbLsxxKc=; b=SoGpErlVPww7VM kRhSa6oVODD7uR/eKwFIaATvGUXy99q3p8aKhFGa4SxKp+uLcGBUK0tGMVywKW8tRJ82nxRMxfMLv 7q8JDjoxP4yxxKH5hnx30ijMuk74shg0z0+chum1x/f6w8/Gs1+/gfDT00CbMGrNbhuljPQGbnZ/0 TAWc5zmKt7PwrEXlABWz4ESAZ7Ua/1ZLiW991TbBVYQjmjHYc8KiNN5E6DdA05pLrq8Nx/EP6EX/x K/RWMb6jhmTQx6ALCEZlcLSGZpx1QRmf/s2Fn0m7KlXDjAeONX3gU/XbgAYigSWDfIXBq8vTtLA7J s8ZbkIQ1U/4AJrysMnYg==; 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 1mgZXP-0002gP-DN; Fri, 29 Oct 2021 17:35:47 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 29 Oct 2021 23:35:35 +0200 Message-Id: <20211029213539.30291-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 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=1635544346; 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=pKGuDFabDBtnXQYf2yviDMuNMQmTqaqIOY4EbLsxxKc=; b=svuYSDUQjw5I7OR4Rc/P1er5Y2fKEXJQwwQMcxuIZzG3MVf0d3hReamEEv0xy3O86Kqt3y 3UTIS7O6a5NxF2A+PiaC/5jkvoaj/+BjRakkHodvLcR9BPUa/S+RzRUwPof6qvzgjZYT2o xSCXZt5jy2esgdJKBYumiNzUV/fNpdfACHeRyCGWfbXyN1pk1tjpUgQOBm1eh2Z83ZRWm/ fsbr+w9mtKNjeDreLfqGay5jaxXsevFtmpI4P0HgU61mWH9AM/hVIKhJSL6bGrenSCqRaT +qCxIC2C0pLNOSNmEIWyUjDVH293qRdU7sVry59I0aARaLZJhaVCu7e3WPhCLw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635544346; a=rsa-sha256; cv=none; b=LeHR3mVtysqJbTdedpEl+eFk+J55+EYTEmEN2APlRoq8r/ka4HwCW/M21v/SKFKXN1wyOw NfWqj9/kr7MjLPbg3LvqPpsDzBTQx7Un9KIPcJK9vIwQs4O1kyGSwms5ebxoe1amHqDuvt bPuIWTMJdHSRTKJixWsTf/qJNTyQ/2uBsXGNCL0OfrmSo9Lid/7RzD26zhJR1/NBWJitPH N3MZlik/fAztojcEb21bfUZr1/lqrfhSsVudSnAE3hoAIWEpT0puvvhBuTcHATg9jqvzTL WlLwDdbUHoVsZTCq9WN4I8+pkLb3tGHv9fHr4sxUgX23Y/SRf9rc266qFCr1qw== 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=SoGpErlV; 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=SoGpErlV; 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: C4E60D8FE X-Spam-Score: 2.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: D03VPTUETu7s * guix/import/pypi.scm (latest-version): New procedure. (latest-source-release): Rename to... (source-release): ... this. Add 'version' parameter. (latest-wheel-release): Rename to... (wheel-release): ... this. Add 'version' parameter. (pypi->guix-package): Honor 'version' parameter. (pypi-recursive-import): Add 'version' parameter and honor it. * guix/scripts/import/pypi.scm (guix-import-pypi): Expect a spec. Pass it to 'package-name->name+version'. Pass the 'version' parameter. * tests/pypi.scm ("pypi->guix-package, no wheel"): Exercise the #:version parameter. * doc/guix.texi (Invoking guix import): Document it. --- doc/guix.texi | 10 ++++++-- guix/import/pypi.scm | 47 +++++++++++++++++++----------------- guix/scripts/import/pypi.scm | 32 ++++++++++++------------ tests/pypi.scm | 12 ++++++--- 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 22215214e0..b742a4808a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -11723,13 +11723,19 @@ information, including package dependencies. For maximum efficiency, it is recommended to install the @command{unzip} utility, so that the importer can unzip Python wheels and gather data from them. -The command below imports metadata for the @code{itsdangerous} Python -package: +The command below imports metadata for the latest version of the +@code{itsdangerous} Python package: @example guix import pypi itsdangerous @end example +You can also ask for a specific version: + +@example +guix import pypi itsdangerous@@1.1.0 +@end example + @table @code @item --recursive @itemx -r diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index f908136481..418a3556ec 100644 --- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm @@ -128,27 +128,30 @@ (define-condition-type &missing-source-error &error missing-source-error? (package missing-source-error-package)) -(define (latest-source-release pypi-package) - "Return the latest source release for PYPI-PACKAGE." - (let ((releases (assoc-ref (pypi-project-releases pypi-package) - (project-info-version - (pypi-project-info pypi-package))))) +(define (latest-version project) + "Return the latest version of PROJECT, a record." + (project-info-version (pypi-project-info project))) + +(define* (source-release pypi-package + #:optional (version (latest-version pypi-package))) + "Return the source release of VERSION for PYPI-PACKAGE, a +record, by default the latest version." + (let ((releases (or (assoc-ref (pypi-project-releases pypi-package) version) + '()))) (or (find (lambda (release) (string=? "sdist" (distribution-package-type release))) releases) (raise (condition (&missing-source-error (package pypi-package))))))) -(define (latest-wheel-release pypi-package) +(define* (wheel-release pypi-package + #:optional (version (latest-version pypi-package))) "Return the url of the wheel for the latest release of pypi-package, or #f if there isn't any." - (let ((releases (assoc-ref (pypi-project-releases pypi-package) - (project-info-version - (pypi-project-info pypi-package))))) - (or (find (lambda (release) - (string=? "bdist_wheel" (distribution-package-type release))) - releases) - #f))) + (let ((releases (assoc-ref (pypi-project-releases pypi-package) version))) + (find (lambda (release) + (string=? "bdist_wheel" (distribution-package-type release))) + releases))) (define (python->package-name name) "Given the NAME of a package on PyPI, return a Guix-compliant name for the @@ -484,18 +487,17 @@ (define pypi->guix-package "Fetch the metadata for PACKAGE-NAME from pypi.org, and return the `package' s-expression corresponding to that package, or #f on failure." (let* ((project (pypi-fetch package-name)) - (info (and project (pypi-project-info project)))) + (info (and=> project pypi-project-info)) + (version (or version (and=> project latest-version)))) (and project (guard (c ((missing-source-error? c) (let ((package (missing-source-error-package c))) (leave (G_ "no source release for pypi package ~a ~a~%") - (project-info-name info) - (project-info-version info))))) - (make-pypi-sexp (project-info-name info) - (project-info-version info) - (and=> (latest-source-release project) + (project-info-name info) version)))) + (make-pypi-sexp (project-info-name info) version + (and=> (source-release project version) distribution-url) - (and=> (latest-wheel-release project) + (and=> (wheel-release project version) distribution-url) (project-info-home-page info) (project-info-summary info) @@ -503,8 +505,9 @@ (define pypi->guix-package (string->license (project-info-license info))))))))) -(define (pypi-recursive-import package-name) +(define* (pypi-recursive-import package-name #:optional version) (recursive-import package-name + #:version version #:repo->guix-package pypi->guix-package #:guix-name python->package-name)) @@ -538,7 +541,7 @@ (define (latest-release package) (let* ((info (pypi-project-info pypi-package)) (version (project-info-version info)) (url (distribution-url - (latest-source-release pypi-package)))) + (source-release pypi-package)))) (upstream-source (urls (list url)) (input-changes diff --git a/guix/scripts/import/pypi.scm b/guix/scripts/import/pypi.scm index 9170a0b359..a52cd95c93 100644 --- a/guix/scripts/import/pypi.scm +++ b/guix/scripts/import/pypi.scm @@ -27,6 +27,7 @@ (define-module (guix scripts import pypi) #: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-pypi)) @@ -83,21 +84,22 @@ (define (parse-options) (_ #f)) (reverse opts)))) (match args - ((package-name) - (if (assoc-ref opts 'recursive) - ;; Recursive import - (map (match-lambda - ((and ('package ('name name) . rest) pkg) - `(define-public ,(string->symbol name) - ,pkg)) - (_ #f)) - (pypi-recursive-import package-name)) - ;; Single import - (let ((sexp (pypi->guix-package package-name))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - package-name)) - sexp))) + ((spec) + (let ((name version (package-name->name+version spec))) + (if (assoc-ref opts 'recursive) + ;; Recursive import + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (pypi-recursive-import name version)) + ;; Single import + (let ((sexp (pypi->guix-package name #:version version))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + name)) + sexp)))) (() (leave (G_ "too few arguments~%"))) ((many ...) diff --git a/tests/pypi.scm b/tests/pypi.scm index 70f4298a90..ad869ac31f 100644 --- a/tests/pypi.scm +++ b/tests/pypi.scm @@ -260,9 +260,15 @@ (define test-metadata-with-extras-jedi "\ ('synopsis "summary") ('description "summary") ('license 'license:lgpl2.0)) - (string=? (bytevector->nix-base32-string - test-source-hash) - hash)) + (and (string=? (bytevector->nix-base32-string + test-source-hash) + hash) + (equal? (pypi->guix-package "foo" #:version "1.0.0") + (pypi->guix-package "foo")) + (catch 'quit + (lambda () + (pypi->guix-package "foo" #:version "42")) + (const #t)))) (x (pk 'fail x #f)))))) -- 2.33.0