From patchwork Thu Jun 13 18:09:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Timothy Sample X-Patchwork-Id: 14310 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 4261F170CC; Thu, 13 Jun 2019 19:10:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id BE4D3170C9 for ; Thu, 13 Jun 2019 19:10:09 +0100 (BST) Received: from localhost ([::1]:43316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbUAr-000753-6m for patchwork@mira.cbaines.net; Thu, 13 Jun 2019 14:10:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52110) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbUAn-0006xY-E9 for guix-patches@gnu.org; Thu, 13 Jun 2019 14:10:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbUAl-0000JT-Uv for guix-patches@gnu.org; Thu, 13 Jun 2019 14:10:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50763) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbUAl-0000IF-Np for guix-patches@gnu.org; Thu, 13 Jun 2019 14:10:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hbUAk-0003Ai-PK for guix-patches@gnu.org; Thu, 13 Jun 2019 14:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36048] [PATCH] guix: import: hackage: handle hackage revisions Resent-From: Timothy Sample Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 13 Jun 2019 18:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36048 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Robert Vollmert Received: via spool by 36048-submit@debbugs.gnu.org id=B36048.156044936212105 (code B ref 36048); Thu, 13 Jun 2019 18:10:02 +0000 Received: (at 36048) by debbugs.gnu.org; 13 Jun 2019 18:09:22 +0000 Received: from localhost ([127.0.0.1]:36073 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hbUA5-00039A-NN for submit@debbugs.gnu.org; Thu, 13 Jun 2019 14:09:22 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:57397) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hbUA3-00038v-6s for 36048@debbugs.gnu.org; Thu, 13 Jun 2019 14:09:20 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 02568438; Thu, 13 Jun 2019 14:09:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 13 Jun 2019 14:09:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=p28jQ5 3LVruCTCnaGdHGDHkxi7cpgNC50jPE59tZEEU=; b=RaEwpmuQGDHujvu9w86Hkc CUAsBH+6kF3AW7afP6mgcWvrbB5Zi272Uv6qIkp2zCu8KdITOnteLe+NpbAHQUkC 6kG2FYliJo5TTR6d/NLhJAddj6ko/qeRJDTq6N4zLMbaDWUI7I1zEAqbQAPyZmWP VNbIQtkddNVfQlgK/IHV2Rx3jtu1M5DopE/yg80WRQZX+y9eRx+qqx6VirzsA3Lp Z5o1/uIAC0SK4W3JhavVcAKLzBxoXWB/HBET5Vn44RR3Zvh/Bv/Y1PxCTC4/lYfP vfNnoj8cAr25TmGOB+FLcyWJJckpe/d0mhgClabBVjoMy2EgkeWZH8icGUQJT5mQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudehledguddvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufhfffgjkfgfgggtsehmtd erredtreejnecuhfhrohhmpefvihhmohhthhihucfurghmphhlvgcuoehsrghmphhlvght sehnghihrhhordgtohhmqeenucfkphepjeegrdduudeirddukeeirdeggeenucfrrghrrg hmpehmrghilhhfrhhomhepshgrmhhplhgvthesnhhghihrohdrtghomhenucevlhhushht vghrufhiiigvpedt X-ME-Proxy: Received: from mrblack (74-116-186-44.qc.dsl.ebox.net [74.116.186.44]) by mail.messagingengine.com (Postfix) with ESMTPA id A35E6380088; Thu, 13 Jun 2019 14:09:11 -0400 (EDT) From: Timothy Sample References: <20190601223636.74362-1-rob@vllmrt.net> <87sgse43sc.fsf@ngyro.com> Date: Thu, 13 Jun 2019 14:09:10 -0400 In-Reply-To: (Robert Vollmert's message of "Thu, 13 Jun 2019 18:11:00 +0200") Message-ID: <87lfy59x2x.fsf@ngyro.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 36048@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi Robert, Robert Vollmert writes: > Hi Timothy, > > thanks for the detailed feedback, this is very helpful! You’re welcome! > I’ve sent an updated patch addressing some of the concerns, but have > some questions regarding others. (I just realized that the documentation > updates probably anticipate multiple return values.) Yes. >> On 13. Jun 2019, at 04:28, Timothy Sample wrote: >>> + (let-values (((port get-hash) (open-sha256-input-port port))) > >>> + (cons >>> + (read-cabal (canonical-newline-port port)) >>> + (bytevector->nix-base32-string (get-hash))))) > > […] > >> Also, I think returning multiple values would be more natural here >> (i.e., replace “cons” with “values”). > > I tried building it that way to begin with, but I’m having issues > making it work (nicely, or maybe at all). I think it comes down to > later functions optionally failing with a single #f-value. Judging > by the lack of infrastructure, I imagine functions that return different > numbers of values are not idiomatic scheme. Should this be changed to > return two values (#f #f) on failure? Or to raise an exception and > handle it higher up when we want to ignore a failure? > > Currently, implementing this with values/let-values results in me > doing more or less a combination of let-values and match, at which > point it seems that any potential benefits of using multiple values > as opposed to a pair/list are lost. (There’s no match-values form is > there?) I’m not sure I understand the problem. Here’s what I had in mind: As far as I see, this behaves the same as the cons-and-match version. Did I miss something? By the way, you make a good point about “match-values”. That would be handy. In general, we love “match” in Guile and in Guix in particular, but multiple values are part of the Scheme standard – there’s no reason to avoid them. They are perfect for situations like this in place of wrapping the values up into a pair or list and then immediately unwrapping them. -- Tim diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm index 2853037797..9ba3c4b58e 100644 --- a/guix/import/hackage.scm +++ b/guix/import/hackage.scm @@ -120,8 +120,8 @@ version is returned." (define (read-cabal-and-hash port) "Read a cabal file and its base32 hash from a port." (let-values (((port get-hash) (open-sha256-input-port port))) - (cons (read-cabal (canonical-newline-port port)) - (bytevector->nix-base32-string (get-hash))))) + (values (read-cabal (canonical-newline-port port)) + (bytevector->nix-base32-string (get-hash))))) (define (hackage-fetch-and-hash name-version) "Return the Cabal file and hash for the package NAME-VERSION, or #f on @@ -129,7 +129,7 @@ failure. If the version part is omitted from the package name, then return the latest version." (guard (c ((and (http-get-error? c) (= 404 (http-get-error-code c))) - #f)) ;"expected" if package is unknown + (values #f #f))) ;"expected" if package is unknown (let-values (((name version) (package-name->name+version name-version))) (let* ((url (hackage-cabal-url name version)) (port (http-fetch url)) @@ -141,9 +141,8 @@ the latest version." "Return the Cabal file for the package NAME-VERSION, or #f on failure. If the version part is omitted from the package name, then return the latest version." - (match (hackage-fetch-and-hash name-version) - ((cabal . hash) cabal) - (_ #f))) + (let-values (((cabal hash) (hackage-fetch-and-hash name-version))) + cabal)) (define string->license ;; List of valid values from @@ -318,16 +317,14 @@ symbol 'true' or 'false'. The value associated with other keys has to conform to the Cabal file format definition. The default value associated with the keys \"os\", \"arch\" and \"impl\" is \"linux\", \"x86_64\" and \"ghc\" respectively." - (match - (if port (read-cabal-and-hash port) - (hackage-fetch-and-hash package-name)) - ((cabal-meta . cabal-hash) - (and=> cabal-meta (compose (cut hackage-module->sexp <> - cabal-hash - #:include-test-dependencies? - include-test-dependencies?) - (cut eval-cabal <> cabal-environment)))) - (_ #f))) + (let-values (((cabal-meta cabal-hash) + (if port + (read-cabal-and-hash (canonical-newline-port port)) + (hackage-fetch-and-hash package-name)))) + (and=> cabal-meta (compose (cut hackage-module->sexp <> cabal-hash + #:include-test-dependencies? + include-test-dependencies?) + (cut eval-cabal <> cabal-environment))))) (define hackage->guix-package/m ;memoized variant (memoize hackage->guix-package))