Subject: [PATCH 03/20] updaters: Issue error-message if version is given:

From: Hartmut Goebel <[email-masked]>
Date: Sun, 28 Aug 2022 15:18:29 +0200

These importer don't support importing a specific version, thus the updater
does neither.  Issue an error message in case version is given.

* guix/import/cpan.scm(latest-release),
  guix/import/elpa.scm(latest-release),
  guix/import/gem.scm(latest-release),
  guix/import/hackage.scm(latest-release),
  guix/import/minetest.scm(latest-minetest-release),
  guix/import/opam.scm(latest-release): Add keyword argument 'version',
  issue error if version is given.
* guix/import/cran.scm(latest-cran-release): Same.
  (latest-bioconductor-release) Same. <version>: rename to <latest-version>.
* guix/import/stackage.scm(latest-lts-release): For each generated updater,
  add keyword argument 'version' and issue error if version is given.
---
 guix/import/cpan.scm     |  9 ++++++++-
 guix/import/cran.scm     | 19 +++++++++++++++----
 guix/import/elpa.scm     |  9 ++++++++-
 guix/import/gem.scm      | 10 +++++++++-
 guix/import/hackage.scm  | 10 +++++++++-
 guix/import/minetest.scm | 10 +++++++++-
 guix/import/opam.scm     |  9 ++++++++-
 guix/import/stackage.scm |  8 +++++++-
 8 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm
index a929dc62e3..8972b87080 100644
--- a/guix/import/cpan.scm
+++ b/guix/import/cpan.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2016 Alex Sassmannshausen <[email-masked]>
 ;;; Copyright © 2017, 2018 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2020, 2021 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -29,6 +30,7 @@
   #:use-module (srfi srfi-26)
   #:use-module (json)
   #:use-module (gcrypt hash)
+  #:use-module (guix diagnostics)
   #:use-module (guix store)
   #:use-module (guix utils)
   #:use-module (guix base32)
@@ -305,8 +307,13 @@ in RELEASE, a <cpan-release> record."
                                              ")"))))
     (url-predicate (cut regexp-exec cpan-rx <>))))
 
-(define (latest-release package)
+(define* (latest-release package #:key (version #f))
   "Return an <upstream-source> for the latest release of PACKAGE."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "cpan")))
   (match (cpan-fetch (package->upstream-name package))
     (#f #f)
     (release
diff --git a/guix/import/cran.scm b/guix/import/cran.scm
index 33305d68eb..eadced512f 100644
--- a/guix/import/cran.scm
+++ b/guix/import/cran.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;; Copyright © 2021 Simon Tournier <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -640,8 +641,13 @@ s-expression corresponding to that package, or #f on failure."
              (_ #f)))
           (_ #f)))))
 
-(define (latest-cran-release pkg)
+(define* (latest-cran-release pkg #:key (version #f))
   "Return an <upstream-source> for the latest release of the package PKG."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a provides only the latest version of each package, sorry.")
+      "CRAN")))
 
   (define upstream-name
     (package->upstream-name pkg))
@@ -660,20 +666,25 @@ s-expression corresponding to that package, or #f on failure."
            (changed-inputs pkg
                            (description->package 'cran meta)))))))
 
-(define (latest-bioconductor-release pkg)
+(define* (latest-bioconductor-release pkg #:key (version #f))
   "Return an <upstream-source> for the latest release of the package PKG."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a provides only the latest version of each package, sorry.")
+      "bioconductor.org")))
 
   (define upstream-name
     (package->upstream-name pkg))
 
-  (define version
+  (define latest-version
     (latest-bioconductor-package-version upstream-name))
 
   (and version
        ;; Bioconductor does not provide signatures.
        (upstream-source
         (package (package-name pkg))
-        (version version)
+        (version latest-version)
         (urls (bioconductor-uri upstream-name version))
         (input-changes
          (changed-inputs
diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm
index 1dbdff9391..f9e9f2de53 100644
--- a/guix/import/elpa.scm
+++ b/guix/import/elpa.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2021 Xinglu Chen <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;; Copyright © 2021 Simon Tournier <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -35,6 +36,7 @@
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
+  #:use-module (guix diagnostics)
   #:use-module ((guix download) #:select (download-to-store))
   #:use-module (guix import utils)
   #:use-module (guix http-client)
@@ -400,11 +402,16 @@ type '<elpa-package>'."
           (string-drop (package-name package) 6)
           (package-name package))))
 
-(define (latest-release package)
+(define* (latest-release package #:key (version #f))
   "Return an <upstream-release> for the latest release of PACKAGE."
   (define name (guix-package->elpa-name package))
   (define repo (elpa-repository package))
 
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "elpa")))
   (match (elpa-package-info name repo)
     (#f
      ;; No info, perhaps because PACKAGE is not truly an ELPA package.
diff --git a/guix/import/gem.scm b/guix/import/gem.scm
index 81ea4e8f9c..590fec3dcd 100644
--- a/guix/import/gem.scm
+++ b/guix/import/gem.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2020, 2021 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -25,10 +26,12 @@
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
   #:use-module (json)
+  #:use-module (guix diagnostics)
   #:use-module ((guix download) #:prefix download:)
   #:use-module (guix import utils)
   #:use-module (guix import json)
   #:use-module (guix packages)
+  #:use-module (guix i18n)
   #:use-module (guix upstream)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix base16)
@@ -167,8 +170,13 @@ package on RubyGems."
 (define gem-package?
   (url-prefix-predicate "https://rubygems.org/downloads/"))
 
-(define (latest-release package)
+(define* (latest-release package #:key (version #f))
   "Return an <upstream-source> for the latest release of PACKAGE."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "gem")))
   (let* ((gem-name (guix-package->gem-name package))
          (gem      (rubygems-fetch gem-name))
          (version  (gem-version gem))
diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm
index d56f52a221..3c2cd75db4 100644
--- a/guix/import/hackage.scm
+++ b/guix/import/hackage.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2021 Xinglu Chen <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;; Copyright © 2019 Simon Tournier <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -30,10 +31,12 @@
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-1)
+  #:use-module (guix diagnostics)
   #:use-module ((guix download) #:select (download-to-store url-fetch))
   #:use-module ((guix utils) #:select (package-name->name+version
                                        canonical-newline-port))
   #:use-module (guix http-client)
+  #:use-module (guix i18n)
   #:use-module (guix import utils)
   #:use-module (guix import cabal)
   #:use-module (guix store)
@@ -359,8 +362,13 @@ respectively."
   (let ((hackage-rx (make-regexp "(https?://hackage.haskell.org|mirror://hackage/)")))
     (url-predicate (cut regexp-exec hackage-rx <>))))
 
-(define (latest-release package)
+(define* (latest-release package #:key (version #f))
   "Return an <upstream-source> for the latest release of PACKAGE."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "hackage")))
   (let* ((hackage-name (guix-package->hackage-name package))
          (cabal-meta (hackage-fetch hackage-name)))
     (match cabal-meta
diff --git a/guix/import/minetest.scm b/guix/import/minetest.scm
index 6581013215..1f1cfc834d 100644
--- a/guix/import/minetest.scm
+++ b/guix/import/minetest.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021, 2022 Maxime Devos <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -25,6 +26,7 @@
   #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
+  #:use-module (guix diagnostics)
   #:use-module ((guix packages) #:prefix package:)
   #:use-module (guix upstream)
   #:use-module (guix utils)
@@ -486,7 +488,7 @@ list of AUTHOR/NAME strings."
   (and (string-prefix? "minetest-" (package:package-name pkg))
        (assq-ref (package:package-properties pkg) 'upstream-name)))
 
-(define (latest-minetest-release pkg)
+(define* (latest-minetest-release pkg #:key (version #f))
   "Return an <upstream-source> for the latest release of the package PKG,
 or #false if the latest release couldn't be determined."
   (define author/name
@@ -494,6 +496,12 @@ or #false if the latest release couldn't be determined."
   (define contentdb-package (contentdb-fetch author/name)) ; TODO warn if #f?
   (define release (latest-release author/name))
   (define source (package:package-source pkg))
+
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "minetest")))
   (and contentdb-package release
        (release-commit release) ; not always set
        ;; Only continue if both the old and new version number are both
diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index 8a5aa4d8c6..59dbb7cb8b 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2021 Xinglu Chen <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;; Copyright © 2021, 2022 Alice Brenon <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -35,6 +36,7 @@
   #:use-module ((guix build utils) #:select (dump-port find-files mkdir-p))
   #:use-module (guix build-system)
   #:use-module (guix build-system ocaml)
+  #:use-module (guix diagnostics)
   #:use-module (guix http-client)
   #:use-module (guix ui)
   #:use-module (guix packages)
@@ -417,8 +419,13 @@ package in OPAM."
     (member (build-system-name (package-build-system package)) '(dune ocaml))
     (not (string-prefix? "ocaml4" (package-name package)))))
 
-(define (latest-release package)
+(define* (latest-release package #:key (version #f))
   "Return an <upstream-source> for the latest release of PACKAGE."
+  (when version
+    (error
+     (formatted-message
+      (G_ "~a updater doesn't support updating to a specific version, sorry.")
+      "opam")))
   (and-let* ((opam-name (guix-package->opam-name package))
              (opam-file (opam-fetch opam-name))
              (version (assoc-ref opam-file "version"))
diff --git a/guix/import/stackage.scm b/guix/import/stackage.scm
index af9809304f..e54df95985 100644
--- a/guix/import/stackage.scm
+++ b/guix/import/stackage.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
 ;;; Copyright © 2021 Xinglu Chem <[email-masked]>
 ;;; Copyright © 2021 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -139,9 +140,14 @@ included in the Stackage LTS release."
          (mlambda ()
            (stackage-lts-packages
             (stackage-lts-info-fetch %default-lts-version)))))
-    (lambda* (pkg)
+    (lambda* (pkg #:key (version #f))
       "Return an <upstream-source> for the latest Stackage LTS release of
 PACKAGE or #f if the package is not included in the Stackage LTS release."
+      (when version
+        (error
+         (formatted-message
+          (G_ "~a updater doesn't support updating to a specific version, sorry.")
+          "stackage")))
       (let* ((hackage-name (guix-package->hackage-name pkg))
              (version (lts-package-version (packages) hackage-name))
              (name-version (hackage-name-version hackage-name version)))
-- 
2.30.4