Subject: [bug#62202] [PATCH v2 15/23] DRAFT import: juliahub: Add support for versions for juliahub-fetch.

From: Simon Tournier <[email-masked]>
Date: Mon, 18 Sep 2023 20:03:22 +0200

From: Nicolas Graves via Guix-patches via <[email-masked]>

Signed-off-by: Simon Tournier <[email-masked]>
---
 guix/import/juliahub.scm | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index b646f9329562..6ce0487dba38 100644
--- a/guix/import/juliahub.scm
+++ b/guix/import/juliahub.scm
@@ -122,7 +122,7 @@ (define %julia-stdlibs
         "Pkg"
         "LazyArtifacts"))
 
-(define (juliahub-uri name)
+(define (juliahub-redirect-uri name)
   (let* ((url (string-append "https://docs.juliahub.com/" name "/"))
          (port (http-fetch url #:text? #t))
          (_ (get-line port))
@@ -134,11 +134,11 @@ (define (juliahub-uri name)
 
 (define (juliahub-url name)
   (let* ((url (string-append "https://docs.juliahub.com/" name "/"))
-         (uri (juliahub-uri name)))
+         (uri (juliahub-redirect-uri name)))
     (string-append url uri "/")))
 
-(define (juliahub-slug-version name)
-  (let* ((uri (juliahub-uri name))
+(define (juliahub-slug+version name)
+  (let* ((uri (juliahub-redirect-uri name))
          (slug (string-take uri 5))
          (latest-version (string-drop uri 6)))
     `(,slug ,latest-version)))
@@ -203,8 +203,12 @@ (define (julia-name->guix-name name)
 
 (define* (juliahub-fetch name #:key (version #f))
   "Return a <juliahub-package> record for package NAME, or #f on failure."
-  (and=> (json-fetch (string-append (juliahub-url name) "pkg.json"))
-         json->juliahub-package))
+  (let ((url (if version
+                 (string-append "https://docs.juliahub.com/" name "/"
+                                (car (juliahub-slug+version name)) "/"
+                                version "/pkg.json")
+                 (string-append (juliahub-url name) "pkg.json"))))
+    (and=> (json-fetch url) json->juliahub-package)))
 
 (define (make-julia-sexp name source home-page synopsis description
                          direct-dependencies test-dependencies-names licenses)
@@ -242,9 +246,9 @@ (define* (juliahub->guix-package package-name
          (subdir (assoc-ref package-toml 'subdir))
          (tag (latest-git-tag (assoc-ref package-toml 'repo)))
          (package (if version
-                      (juliahub-fetch package-name version)
+                      (juliahub-fetch package-name #:version version)
                       (if tag
-                          (juliahub-fetch package-name tag)
+                          (juliahub-fetch package-name #:version tag)
                           (juliahub-fetch package-name)))))
     (if package
         (let-values (((source directory)
-- 
2.38.1