all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicolas Graves via Guix-patches via <guix-patches@gnu.org>
To: 74086@debbugs.gnu.org
Cc: Nicolas Graves <ngraves@ngraves.fr>
Subject: [bug#74086] [PATCH] guix: import: hackage: Support updating to a specific version.
Date: Tue, 29 Oct 2024 14:53:51 +0100	[thread overview]
Message-ID: <20241029135354.17423-1-ngraves@ngraves.fr> (raw)

* gnu/import/hackage.scm
(hackage-fetch-and-hash, hackage-fetch): Support name and version
argument.
(import-release): New variable, formerly known as latest-release.
Support updating to a specific version.
---
 guix/import/hackage.scm | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm
index 79a51d3300..e3ed98c089 100644
--- a/guix/import/hackage.scm
+++ b/guix/import/hackage.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;; Copyright © 2023-2024 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -136,7 +137,7 @@ (define (read-cabal-and-hash port)
     (values (read-cabal (canonical-newline-port port))
             (bytevector->nix-base32-string (get-hash)))))
 
-(define (hackage-fetch-and-hash name-version)
+(define (hackage-fetch-and-hash name version)
   "Fetch the latest Cabal revision for the package NAME-VERSION, and return
 two values: the parsed Cabal file and its hash in nix-base32 format.  If the
 version part is omitted from the package name, then fetch the latest
@@ -144,18 +145,19 @@ (define (hackage-fetch-and-hash name-version)
   (guard (c ((and (http-get-error? c)
                   (= 404 (http-get-error-code c)))
              (values #f #f)))           ;"expected" if package is unknown
-    (let* ((name version (package-name->name+version name-version))
-           (url          (hackage-cabal-url name version))
-           (port _       (http-fetch url))
-           (cabal hash   (read-cabal-and-hash port)))
+    (let* ((name new-version (package-name->name+version name))
+           (version          (or version new-version))
+           (url              (hackage-cabal-url name version))
+           (port _           (http-fetch url))
+           (cabal hash       (read-cabal-and-hash port)))
       (close-port port)
       (values cabal hash))))
 
-(define (hackage-fetch name-version)
+(define (hackage-fetch name 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."
-  (let ((cabal hash (hackage-fetch-and-hash name-version)))
+  (let ((cabal hash (hackage-fetch-and-hash name version)))
     cabal))
 
 (define string->license
@@ -377,15 +379,10 @@ (define hackage-package?
   (let ((hackage-rx (make-regexp "(https?://hackage.haskell.org|mirror://hackage/)")))
     (url-predicate (cut regexp-exec hackage-rx <>))))
 
-(define* (latest-release package #:key (version #f))
+(define* (import-release package #:key (version #f))
   "Return an <upstream-source> for the latest release of PACKAGE."
-  (when version
-    (raise
-     (formatted-message
-      (G_ "~a updater doesn't support updating to a specific version, sorry.")
-      "hackage")))
   (let* ((hackage-name (package-upstream-name* package))
-         (cabal-meta (hackage-fetch hackage-name)))
+         (cabal-meta (hackage-fetch hackage-name version)))
     (match cabal-meta
       (#f
        (format (current-error-port)
@@ -407,6 +404,6 @@ (define %hackage-updater
    (name 'hackage)
    (description "Updater for Hackage packages")
    (pred hackage-package?)
-   (import latest-release)))
+   (import import-release)))
 
 ;;; cabal.scm ends here
-- 
2.46.0





                 reply	other threads:[~2024-10-29 13:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241029135354.17423-1-ngraves@ngraves.fr \
    --to=guix-patches@gnu.org \
    --cc=74086@debbugs.gnu.org \
    --cc=ngraves@ngraves.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.