GNU bug report logs - #68356
[PATCH] guix: import(cpan): Complete even when modules do not exist on CPAN.

Previous Next

Package: guix-patches;

Reported by: Felix Lechner <felix.lechner <at> lease-up.com>

Date: Wed, 10 Jan 2024 00:06:02 UTC

Severity: normal

Tags: patch

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Felix Lechner <felix.lechner <at> lease-up.com>
To: guix-patches <at> gnu.org
Cc: Felix Lechner <felix.lechner <at> lease-up.com>
Subject: [PATCH] guix: import(cpan): Complete even when modules do not exist
 on CPAN.
Date: Tue,  9 Jan 2024 16:04:13 -0800
Allows the following import command to complete:

   guix import cpan SOAP::Lite

As a side note, the Perl module was needed to deploy Debbugs on GNU Guix.

Change-Id: Ic184c3e95e18ec8385b181ab8c34035cbb0aa0f5
---
 guix/import/cpan.scm | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm
index b87736eef6..de557bc024 100644
--- a/guix/import/cpan.scm
+++ b/guix/import/cpan.scm
@@ -138,11 +138,16 @@ (define (module->dist-name module)
   "Return the base distribution module for a given module.  E.g. the 'ok'
 module is distributed with 'Test::Simple', so (module->dist-name \"ok\") would
 return \"Test-Simple\""
-  (assoc-ref (json-fetch (string-append
-                          (%metacpan-base-url) "/module/"
-                          module
-                          "?fields=distribution"))
-             "distribution"))
+  (let* ((url (string-append
+               (%metacpan-base-url) "/module/" module
+               "?fields=distribution"))
+         (json-alist (json-fetch url))
+         (dist-name (assoc-ref json-alist "distribution")))
+    (if (not dist-name)
+        (format (current-error-port)
+                "Cannot determine distribution name for module ~s from ~s~%"
+                module url))
+    dist-name))
 
 (define (package->upstream-name package)
   "Return the CPAN name of PACKAGE."
@@ -249,10 +254,14 @@ (define (cran-dependency->upstream-input dependency)
                     #f))))
        (and type
             (not (core-module? module))           ;expensive call!
-            (upstream-input
-             (name (module->dist-name module))
-             (downstream-name (cpan-name->downstream-name name))
-             (type type)))))))
+            (let* ((cpan-name (module->dist-name module))
+                   (downstream-name (if cpan-name
+                                        (cpan-name->downstream-name cpan-name)
+                                        (format #f "Module ~a not found on CPAN" module))))
+              (upstream-input
+               (name cpan-name)
+               (downstream-name downstream-name)
+               (type type))))))))
 
 (define (cpan-module-inputs release)
   "Return the list of <upstream-input> for dependencies of RELEASE, a

base-commit: b9fae146d6cc4a6968a8eb18beef29aa1414a31e
-- 
2.41.0





This bug report was last modified 1 year and 162 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.