From patchwork Wed Mar 15 12:51:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 48033 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C32F316961; Wed, 15 Mar 2023 12:54:00 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 843A816961 for ; Wed, 15 Mar 2023 12:53:58 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcQc0-0003SB-OR; Wed, 15 Mar 2023 08:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcQby-0003RC-I1 for guix-patches@gnu.org; Wed, 15 Mar 2023 08:52:10 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcQbv-00039j-L1 for guix-patches@gnu.org; Wed, 15 Mar 2023 08:52:09 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pcQbv-0001Zp-HP for guix-patches@gnu.org; Wed, 15 Mar 2023 08:52:07 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62202] [PATCH 10/21] import: juliahub: Add functions to parse the git repo for a git tag. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 15 Mar 2023 12:52:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62202 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62202@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 62202-submit@debbugs.gnu.org id=B62202.16788847235982 (code B ref 62202); Wed, 15 Mar 2023 12:52:07 +0000 Received: (at 62202) by debbugs.gnu.org; 15 Mar 2023 12:52:03 +0000 Received: from localhost ([127.0.0.1]:39322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcQbq-0001YB-Rk for submit@debbugs.gnu.org; Wed, 15 Mar 2023 08:52:03 -0400 Received: from 8.mo584.mail-out.ovh.net ([188.165.33.112]:34987) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcQbj-0001X4-OO for 62202@debbugs.gnu.org; Wed, 15 Mar 2023 08:51:57 -0400 Received: from director6.ghost.mail-out.ovh.net (unknown [10.108.20.172]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 0570F22F69 for <62202@debbugs.gnu.org>; Wed, 15 Mar 2023 12:51:53 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-74llp (unknown [10.110.171.145]) by director6.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 44BFA1FE33; Wed, 15 Mar 2023 12:51:52 +0000 (UTC) Received: from ngraves.fr ([37.59.142.96]) by ghost-submission-6684bf9d7b-74llp with ESMTPSA id FMVkFWi/EWQrNhcA/ww3gA (envelope-from ); Wed, 15 Mar 2023 12:51:52 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-96R001b39c5f89-9641-4aa6-8301-a3ef5fa45645, F74D9BBE9ED44B45FF66447495DD0B0753EB5D4A) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 81.67.140.142 Date: Wed, 15 Mar 2023 13:51:19 +0100 Message-Id: <20230315125130.23041-10-ngraves@ngraves.fr> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315125130.23041-1-ngraves@ngraves.fr> References: <20230315125130.23041-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13792555337731597026 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvkedggeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepudfggeejleevtdffjeetheffvedtheekieeuveehgffggfdthedtfeeigeehuedunecuffhomhgrihhnpehgihhthhhusghushgvrhgtohhnthgvnhhtrdgtohhmpdhjuhhlihgrhhhusgdrohhrghenucfkphepuddvjedrtddrtddruddpfeejrdehledrudegvddrleeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeeivddvtddvseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkeegpdhmohguvgepshhmthhpohhuth X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches --- 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 fc25ba1d42..5327e92325 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))