diff mbox series

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

Message ID 444f876473d530a973b2ca2309e593069ceb08c1.1704845053.git.felix.lechner@lease-up.com
State New
Headers show
Series [bug#68356] guix: import(cpan): Complete even when modules do not exist on CPAN. | expand

Commit Message

Felix Lechner Jan. 10, 2024, 12:04 a.m. UTC
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(-)


base-commit: b9fae146d6cc4a6968a8eb18beef29aa1414a31e
diff mbox series

Patch

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