diff mbox series

[bug#61420,08/31] import: hackage: Use upstream-name property.

Message ID 20230211100825.47971-7-lars@6xq.net
State New
Headers show
Series Haskell upgrade to Stackage 20.5 | expand

Commit Message

Lars-Dominik Braun Feb. 11, 2023, 10:08 a.m. UTC
* guix/import/hackage.scm (guix-package->hackage-name): Removed.
(latest-release): Use package-upstream-name* instead.
* guix/import/stackage.scm (latest-lts-release): Ditto.
(stackage-lts-package?): Ditto.
---
 guix/import/hackage.scm  | 14 +-------------
 guix/import/stackage.scm |  4 ++--
 2 files changed, 3 insertions(+), 15 deletions(-)

Comments

Simon Tournier Feb. 15, 2023, 10:48 a.m. UTC | #1
Hi,

On Sat, 11 Feb 2023 at 11:08, Lars-Dominik Braun <lars@6xq.net> wrote:
> * guix/import/hackage.scm (guix-package->hackage-name): Removed.
> (latest-release): Use package-upstream-name* instead.
> * guix/import/stackage.scm (latest-lts-release): Ditto.
> (stackage-lts-package?): Ditto.

> -(define guix-package->hackage-name
> -  (let ((uri-rx (make-regexp "(https?://hackage.haskell.org|mirror://hackage)/package/([^/]+)/.*"))
> -        (name-rx (make-regexp "(.*)-[0-9\\.]+")))
> -    (lambda (package)
> -      "Given a Guix package name, return the corresponding Hackage name."
> -      (let* ((source-url (and=> (package-source package) origin-uri))
> -             (name (match:substring (regexp-exec uri-rx source-url) 2)))
> -        (match (regexp-exec name-rx name)
> -          (#f name)
> -          (m (match:substring m 1)))))))

Why not just do a drop-in replacement of the implement of
’guix-package->hackage-name’ by the implementation of
’package-upstream-name*’?

Other said, avoid to introduce a new procedure and remove another; and
instead just replace the implementation of the old by the new.


> -  (let* ((hackage-name (guix-package->hackage-name package))
> +  (let* ((hackage-name (package-upstream-name* package))

It would avoid all these kind of replacement, no?


Cheers,
simon
diff mbox series

Patch

diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm
index 9e305cf080..2f901af47b 100644
--- a/guix/import/hackage.scm
+++ b/guix/import/hackage.scm
@@ -52,7 +52,6 @@  (define-module (guix import hackage)
             hackage-recursive-import
             %hackage-updater
 
-            guix-package->hackage-name
             hackage-name->package-name
             hackage-fetch
             hackage-source-url
@@ -126,17 +125,6 @@  (define (hackage-name->package-name name)
       (string-downcase name)
       (string-append package-name-prefix (string-downcase name))))
 
-(define guix-package->hackage-name
-  (let ((uri-rx (make-regexp "(https?://hackage.haskell.org|mirror://hackage)/package/([^/]+)/.*"))
-        (name-rx (make-regexp "(.*)-[0-9\\.]+")))
-    (lambda (package)
-      "Given a Guix package name, return the corresponding Hackage name."
-      (let* ((source-url (and=> (package-source package) origin-uri))
-             (name (match:substring (regexp-exec uri-rx source-url) 2)))
-        (match (regexp-exec name-rx name)
-          (#f name)
-          (m (match:substring m 1)))))))
-
 (define (read-cabal-and-hash port)
   "Read a Cabal file from PORT and return it and its hash in nix-base32
 format as two values."
@@ -371,7 +359,7 @@  (define* (latest-release package #:key (version #f))
      (formatted-message
       (G_ "~a updater doesn't support updating to a specific version, sorry.")
       "hackage")))
-  (let* ((hackage-name (guix-package->hackage-name package))
+  (let* ((hackage-name (package-upstream-name* package))
          (cabal-meta (hackage-fetch hackage-name)))
     (match cabal-meta
       (#f
diff --git a/guix/import/stackage.scm b/guix/import/stackage.scm
index 9462e70791..735eeb75f7 100644
--- a/guix/import/stackage.scm
+++ b/guix/import/stackage.scm
@@ -149,7 +149,7 @@  (define latest-lts-release
          (formatted-message
           (G_ "~a updater doesn't support updating to a specific version, sorry.")
           "stackage")))
-      (let* ((hackage-name (guix-package->hackage-name pkg))
+      (let* ((hackage-name (package-upstream-name* pkg))
              (version (lts-package-version (packages) hackage-name))
              (name-version (hackage-name-version hackage-name version)))
         (match (and=> name-version hackage-fetch)
@@ -173,7 +173,7 @@  (define (stackage-lts-package? package)
        (false-if-networking-error
         (let ((packages (stackage-lts-packages
                          (stackage-lts-info-fetch %default-lts-version)))
-              (hackage-name (guix-package->hackage-name package)))
+              (hackage-name (package-upstream-name* package)))
           (find (lambda (package)
                   (string=? (stackage-package-name package) hackage-name))
                 packages)))))