GNU bug report logs - #66083
[PATCH v2 12/23] DRAFT import: juliahub: Add functions to parse the git repo for a git tag.

Previous Next

Package: guix-patches;

Reported by: Simon Tournier <zimon.toutoune <at> gmail.com>

Date: Mon, 18 Sep 2023 18:06:08 UTC

Severity: normal

Tags: patch

Merged with 66075, 66076, 66077, 66078, 66079, 66080, 66081, 66082, 66084, 66085, 66086, 66087, 66088, 66089, 66090, 66091, 66092

Done: Simon Tournier <zimon.toutoune <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66083 in the body.
You can then email your comments to 66083 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#66083; Package guix-patches. (Mon, 18 Sep 2023 18:06:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to Simon Tournier <zimon.toutoune <at> gmail.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Mon, 18 Sep 2023 18:06:08 GMT) Full text and rfc822 format available.

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

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: 62202 <at> debbugs.gnu.org
Cc: Nicolas Graves via Guix-patches via <guix-patches <at> gnu.org>,
 Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: [PATCH v2 12/23] DRAFT import: juliahub: Add functions to parse the
 git repo for a git tag.
Date: Mon, 18 Sep 2023 20:03:19 +0200
From: Nicolas Graves via Guix-patches via <guix-patches <at> gnu.org>

Signed-off-by: Simon Tournier <zimon.toutoune <at> gmail.com>
---
 guix/import/juliahub.scm | 62 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 6 deletions(-)

diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index fc25ba1d4220..5327e923251d 100644
--- a/guix/import/juliahub.scm
+++ b/guix/import/juliahub.scm
@@ -26,6 +26,7 @@ (define-module (guix import juliahub)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-11)
   #:use-module (guix http-client)
+  #:use-module (guix git)
   #:use-module (guix import utils)
   #:use-module (guix import json)
   #:use-module (guix base32)
@@ -38,6 +39,48 @@ (define-module (guix import juliahub)
             %juliahub-updater
             juliahub-recursive-import))
 
+;; Juliahub may be more up-to-date than the General registry or the actual git
+;; tag (it seems around 6 hours pass between the time a commit is supplied to
+;; JuliaRegistrator as a release, and the time Julia TagBot Github Action makes
+;; the git tag). We have no simple way to get the commit of the latest-version.
+;; Thus the best simple thing we can do is get the latest-git-version, and
+;; import this version instead. We do this by parsing Package.toml in the General
+;; registry, and then getting the refs of the git repo supplied by this
+;; file. Parsing this file is also necessary if the package is in a subdir of a
+;; git repository, because the information isn't present in Juliahub.
+;; There's a last case where some Julia packages are not based on a particular
+;; git tag, and where looking for the commit is tedious and artificial. In these
+;; cases, we introduce the tree-commit which is available in the Versions.toml
+;; file in the General repository. This is equivalent to a commit, since we have
+;; a unique hash of the listing of files and directories, thus it can be used to
+;; identify the state of a repository.
+
+(define %general-base-url
+  "https://raw.githubusercontent.com/JuliaRegistries/General/master/")
+
+(define (general-url package-name file)
+  (let ((folder (string-capitalize (string-take package-name 1))))
+    (string-append
+     %general-base-url folder "/" package-name "/" file)))
+
+(define (ini-list->alist lst)
+  (match lst
+    ((attribute '= value ooo ...)
+     `((,attribute . ,value) ,@(ini-list->alist ooo)))
+    ('()
+     '())))
+
+(define (ini-fetch url)
+  (let* ((port (http-fetch url #:text? #t))
+         (ini-list (stream->list (port->stream port read))))
+    (close-port port)
+    (ini-list->alist ini-list)))
+
+(define (latest-git-tag repo)
+  (let* ((last-ref (last (remote-refs repo #:tags? #t)))
+         (last-git-tag (last (string-split last-ref #\/))))
+    (string-drop last-git-tag 1)))
+
 ;; To update, see file sysimg.jl
 (define %julia-stdlibs
   (list "julia"
@@ -194,14 +237,21 @@ (define (make-julia-sexp name source home-page synopsis description
                  ((license) (license->symbol license))
                  (_ `(list ,@(map license->symbol licenses)))))))
 
+;; TODO handle subdir case properly.
+
 (define* (juliahub->guix-package package-name
                                  #:key version #:allow-other-keys)
   "Fetch the metadata for PACKAGE-NAME from juliahub.org, and return the
 `package' s-expression corresponding to that package, or #f on failure.
 Optionally include a VERSION string to fetch a specific version juliahub."
-  (let ((package (if version
-                     (juliahub-fetch package-name version)
-                     (juliahub-fetch package-name))))
+  (let* ((package-toml (ini-fetch (general-url name "Package.toml")))
+         (subdir (assoc-ref package-toml 'subdir))
+         (tag (latest-git-tag (assoc-ref package-toml 'repo)))
+         (package (if version
+                      (juliahub-fetch package-name version)
+                      (if tag
+                          (juliahub-fetch package-name tag)
+                          (juliahub-fetch package-name)))))
     (if package
         (let-values (((source directory)
                       (git->origin+dir
@@ -233,13 +283,13 @@ (define* (juliahub->guix-package package-name
 
 (define (guix-package->juliahub-name package)
   (let* ((url (juliahub-package-url package))
-         (git-name (car (last-pair (string-split url #\/))))
+         (git-name (last (string-split url #\/)))
          (ungitted-name (if (string-suffix? ".git" git-name)
                             (string-drop-right git-name 4)
                             git-name))
          (package-name (if (string-suffix? ".jl" ungitted-name)
-                            (string-drop-right ungitted-name 4)
-                            ungitted-name)))
+                           (string-drop-right ungitted-name 4)
+                           ungitted-name)))
     package-name))
 
 (define* (import-release package #:key (version #f))
-- 
2.38.1





bug closed, send any further explanations to 66083 <at> debbugs.gnu.org and Simon Tournier <zimon.toutoune <at> gmail.com> Request was from Simon Tournier <zimon.toutoune <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 18 Sep 2023 21:01:06 GMT) Full text and rfc822 format available.

Merged 66075 66076 66077 66078 66079 66080 66081 66082 66083 66084 66085 66086 66087 66088 66089. Request was from Simon Tournier <zimon.toutoune <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 18 Sep 2023 21:01:17 GMT) Full text and rfc822 format available.

Merged 66075 66076 66077 66078 66079 66080 66081 66082 66083 66084 66085 66086 66087 66088 66089 66090 66091 66092. Request was from Simon Tournier <zimon.toutoune <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 18 Sep 2023 21:01:19 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 17 Oct 2023 11:24:10 GMT) Full text and rfc822 format available.

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

Previous Next


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