From patchwork Mon Sep 18 18:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 54040 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 41D5027BBE2; Mon, 18 Sep 2023 19:08:51 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, 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 C804527BBE9 for ; Mon, 18 Sep 2023 19:08:45 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiIcl-0003xS-VR; Mon, 18 Sep 2023 14:05:33 -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 1qiIcD-0003Aq-D9 for guix-patches@gnu.org; Mon, 18 Sep 2023 14:04:58 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiIcD-0003Ye-4q for guix-patches@gnu.org; Mon, 18 Sep 2023 14:04:57 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qiIcL-0002O0-9T for guix-patches@gnu.org; Mon, 18 Sep 2023 14:05:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62202] [PATCH v2 04/23] DRAFT import: Add julia. Resent-From: Simon Tournier Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Sep 2023 18:05:05 +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 moreinfo To: 62202@debbugs.gnu.org Cc: Simon Tournier Received: via spool by 62202-submit@debbugs.gnu.org id=B62202.16950602548844 (code B ref 62202); Mon, 18 Sep 2023 18:05:05 +0000 Received: (at 62202) by debbugs.gnu.org; 18 Sep 2023 18:04:14 +0000 Received: from localhost ([127.0.0.1]:54381 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qiIbV-0002IR-2G for submit@debbugs.gnu.org; Mon, 18 Sep 2023 14:04:14 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:41340) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qiIbD-0002Eb-9C for 62202@debbugs.gnu.org; Mon, 18 Sep 2023 14:04:01 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405101a02bcso2535315e9.1 for <62202@debbugs.gnu.org>; Mon, 18 Sep 2023 11:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695060221; x=1695665021; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OtMvS4o2GJtrUNPCHXTF/xY25oPgYVlB7vGaIpQ+6eY=; b=Ly8lD1fOUE3hVcrCZItwWKBZuELc9P4XmZ2ISUgToDnolnf8NxLWExX2BxtaGAdQoD uEB+6wjSdZpXVixZpXIgvetMtKZFCdi8XuSLpicvstQ9f4RtHcjfMOTyUCl11Kqintaq ADFsRO6QRP8Dl1oAoOkf9hJsC+hjx4xhsAhMEmpjy+R75nx/nlRIbpDfyMnrjXJapaai v3muAv5QF9dmDPyStVzi5MxxD3e8tew+3Kl+oh5mhr/rxtzlJtt9NVsHepvEpeASprS4 KK6W8CSleUgncnX+QDh5h1/lYXgNGZhXdL9vctbnq8P2TN18Z5AfybMH9EsjyzSSR/JB TfeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695060221; x=1695665021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OtMvS4o2GJtrUNPCHXTF/xY25oPgYVlB7vGaIpQ+6eY=; b=X9OI7bboi9dE+vbrmnsfbqT41cOuDrsu6fFvQa7hZJMW3kWEhdOSQmXxFgQXtksFXo /t2UAkV575vUsBJjHSkPrcXNQqHEZJtuhjD145Wwk8ItUnGudfcRxCjMQ1ABK4GmofqB 3nm12gwDxhPmEcUDQqBx4pjBB10zAgCeRyEL5pjqKY8EW0wz7dQR7BjPxzNyxqbudBW+ 5SQzMQd2x9QRUnOsieRiBruARQSx2PZTwl1LOAE00oC+xx7yu7v662RHidPs4eaB164X ImqcKOJA0EIZanVy6vuedju+OK8gJpHIV9mC/x1wlB8jlxOpyeRlD2F7udhNuVT6daMs uw+w== X-Gm-Message-State: AOJu0Yx5AKbcF0oNh1T92d6neQkYZ5Rzjwa1EuE1XzUHohHG96tSjieA OEAJeiltcs67pL3mA52XFMVjlOB093M= X-Google-Smtp-Source: AGHT+IGsyIL6haThWtXtMy3gAFva9TAiiCi/dRlT88aurR35Dx3Gs+6xhguVGr1QoEPApmZrkDYHMg== X-Received: by 2002:adf:ec4f:0:b0:317:5f08:32a3 with SMTP id w15-20020adfec4f000000b003175f0832a3mr7672957wrn.6.1695060221038; Mon, 18 Sep 2023 11:03:41 -0700 (PDT) Received: from localhost.localdomain ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id z2-20020adfd0c2000000b0030ada01ca78sm2210465wrh.10.2023.09.18.11.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:03:40 -0700 (PDT) From: Simon Tournier Date: Mon, 18 Sep 2023 20:03:11 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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: , 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/scripts/import.scm (importers): Add juliahub. * guix/import/juliahub.scm: New file. * guix/scripts/import/juliahub.scm: New file. * Makefile.am: Add them. --- Makefile.am | 2 + guix/import/juliahub.scm | 183 +++++++++++++++++++++++++++++++ guix/scripts/import.scm | 2 +- guix/scripts/import/juliahub.scm | 107 ++++++++++++++++++ 4 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 guix/import/juliahub.scm create mode 100644 guix/scripts/import/juliahub.scm diff --git a/Makefile.am b/Makefile.am index 922913355c45..70b06c1a793f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -289,6 +289,7 @@ MODULES = \ guix/import/hackage.scm \ guix/import/hexpm.scm \ guix/import/json.scm \ + guix/import/juliahub.scm \ guix/import/kde.scm \ guix/import/launchpad.scm \ guix/import/minetest.scm \ @@ -344,6 +345,7 @@ MODULES = \ guix/scripts/import/hackage.scm \ guix/scripts/import/hexpm.scm \ guix/scripts/import/json.scm \ + guix/scripts/import/juliahub.scm \ guix/scripts/import/minetest.scm \ guix/scripts/import/opam.scm \ guix/scripts/import/pypi.scm \ diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm new file mode 100644 index 000000000000..efe6abbb2481 --- /dev/null +++ b/guix/import/juliahub.scm @@ -0,0 +1,183 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Nicolas Graves +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix import juliahub) + #:use-module (ice-9 textual-ports) + #:use-module (ice-9 regex) + #:use-module (ice-9 match) + #:use-module (ice-9 string-fun) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-1) + #:use-module (guix http-client) + #:use-module (guix import utils) + #:use-module (guix import json) + #:use-module (guix base16) + #:use-module (guix base32) + #:use-module (guix packages) + #:use-module (guix upstream) + #:use-module (json) + #:use-module ((guix licenses) #:prefix license:) + + #:export (juliahub->guix-package)) + +(define (juliahub-uri name) + (let* ((url (string-append "https://docs.juliahub.com/" name "/")) + (port (http-fetch url #:text? #t)) + (_ (get-line port)) + (meta (get-line port)) + (regex "url=[a-zA-Z0-9]{5}\\/[0-9\\.]*") + (redirect (match:substring (string-match regex meta)))) + (close-port port) + (string-drop redirect 4))) + +(define (juliahub-url name) + (let* ((url (string-append "https://docs.juliahub.com/" name "/")) + (uri (juliahub-uri name))) + (string-append url uri "/"))) + +(define (juliahub-slug-version name) + (let* ((uri (juliahub-uri name)) + (slug (string-take uri 5)) + (latest-version (string-drop uri 6))) + `(,slug ,latest-version))) + +(define (json->juliahub-direct-dependencies vector) + (if (vector? vector) + (filter-map + (lambda (el) + (let ((dep (json->juliahub-dependency el))) + (if (juliahub-dependency-direct? dep) + dep + #f))) + (vector->list vector)))) + +;; Julia package. +(define-json-mapping make-juliahub-package juliahub-package? + json->juliahub-package + (homepage juliahub-package-homepage) ;string + (readme juliahub-package-readme) ;string + ;; (slug juliahub-package-slug) ;string + (version juliahub-package-version) ;string + (description juliahub-package-description) ;string + (dependencies + juliahub-package-dependencies "deps" + json->juliahub-direct-dependencies) ;list of + ;; (lambda (vector) + ;; (map json->juliahub-dependency (vector->list vector)))) + (url juliahub-package-url) ;string + (uuid juliahub-package-uuid) ;string + (license juliahub-package-license)) ;string + +(define-json-mapping + make-juliahub-dependency juliahub-dependency? + json->juliahub-dependency + (direct? juliahub-dependency-direct? "direct") ;boolean + (name juliahub-dependency-name) ;string + (uuid juliahub-dependency-uuid) ;string + (versions juliahub-dependency-versions "versions" vector->list)) ;list of strings + ;; (slug juliahub-dependency-slug) ;string + +(define (julia-name->guix-name name) + (string-append "julia-" (snake-case name))) + +(define* (juliahub-fetch name #:key (version #f)) + "Return a record for package NAME, or #f on failure." + (and=> (json-fetch (string-append (juliahub-url name) "pkg.json")) + json->juliahub-package)) + +(define (make-julia-sexp name version uri hash home-page synopsis description + dependencies licenses) + "Return the `package' s-expression for a Julia package with the given NAME, +VERSION, URI, HASH, HOME-PAGE, DESCRIPTION, DEPENDENCIES, and LICENSES." + `(package + (name ,(julia-name->guix-name name)) + (version ,version) + (source (origin + (method url-fetch) + (uri ,uri) + (sha256 + (base32 + "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5" + ;; ,(bytevector->nix-base32-string hash) + )))) + (build-system julia-build-system) + ,@(if (null? dependencies) + '() + `((inputs + (list ,@(map (compose julia-name->guix-name juliahub-dependency-name) + dependencies))))) + (synopsis ,synopsis) + (description ,description) + (home-page ,home-page) + (license ,(match licenses + (() #f) + ((license) (license->symbol license)) + (_ `(list ,@(map license->symbol licenses))))))) + +(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)))) + (if package + (let* ((dependencies-names + (map juliahub-dependency-name + (juliahub-package-dependencies package))) + (licenses + (map spdx-string->license + (list (juliahub-package-license package))))) + (values (make-julia-sexp + package-name + (juliahub-package-version package) + (juliahub-package-url package) + "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5" + (juliahub-package-homepage package) + (juliahub-package-description package) + (beautify-description (juliahub-package-readme package)) + (juliahub-package-dependencies package) + licenses) + dependencies-names)) + (values #f '())))) + +(define* (import-release package #:key (version #f)) + "Return an for the latest release of PACKAGE." + (let* ((package-name (guix-package->juliahub-name package)) + (package (juliahub-fetch package-name)) + (version (or version (juliahub-version gem))) + (url (rubyjuliahubs-uri gem-name version))) + (upstream-source + (package (package-name package)) + (version version) + (urls (list url))))) + +(define %juliahub-updater + (upstream-updater + (name 'juliahub) + (description "Updater for Juliahub packages") + (pred juliahub-package?) + (import import-release))) + +(define* (juliahub-recursive-import package-name #:optional version) + (recursive-import package-name + #:repo '() + #:repo->guix-package juliahub->guix-package + #:guix-name ruby-package-name + #:version version)) diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index 4ddd8d46a121..74c26e347335 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -47,7 +47,7 @@ (define %standard-import-options '()) (define importers '("gnu" "pypi" "cpan" "hackage" "stackage" "egg" "elpa" "gem" "go" "cran" "crate" "texlive" "json" "opam" - "minetest" "elm" "hexpm")) + "minetest" "elm" "hexpm" "juliahub")) (define (resolve-importer name) (let ((module (resolve-interface diff --git a/guix/scripts/import/juliahub.scm b/guix/scripts/import/juliahub.scm new file mode 100644 index 000000000000..1317c67aa342 --- /dev/null +++ b/guix/scripts/import/juliahub.scm @@ -0,0 +1,107 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Nicolas Graves +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix scripts import juliahub) + #:use-module (guix ui) + #:use-module (guix utils) + #:use-module (guix scripts) + #:use-module (guix import juliahub) + #:use-module (guix scripts import) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-37) + #:use-module (ice-9 match) + #:use-module (ice-9 format) + #:use-module (ice-9 receive) + #:export (guix-import-juliahub)) + + +;;; +;;; Command-line options. +;;; + +(define %default-options + '()) + +(define (show-help) + (display (G_ "Usage: guix import juliahub PACKAGE-NAME[@VERSION] Import and +convert the Julia package for PACKAGE-NAME. Optionally, a version can be +specified after the at-sign (@) character.\n")) + (display (G_ " + -h, --help display this help and exit")) + (display (G_ " + -V, --version display version information and exit")) + (display (G_ " + -r, --recursive generate package expressions for all Gem packages\ + that are not yet in Guix")) + (newline) + (show-bug-report-information)) + +(define %options + ;; Specification of the command-line options. + (cons* (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix import gem"))) + (option '(#\r "recursive") #f #f + (lambda (opt name arg result) + (alist-cons 'recursive #t result))) + %standard-import-options)) + + +;;; +;;; Entry point. +;;; + +(define (guix-import-juliahub . args) + (define (parse-options) + ;; Return the alist of option values. + (parse-command-line args %options (list %default-options) + #:build-options? #f)) + + (let* ((opts (parse-options)) + (args (filter-map (match-lambda + (('argument . value) + value) + (_ #f)) + (reverse opts)))) + (match args + ((spec) + (receive (package-name package-version) + (package-name->name+version spec) + (let ((code (if (assoc-ref opts 'recursive) + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (juliahub-recursive-import package-name package-version)) + (let ((sexp (juliahub->guix-package package-name #:version package-version))) + (if sexp sexp #f))))) + (match code + ((or #f '(#f)) + (leave (G_ "failed to download meta-data for package '~a'~%") + package-name)) + (_ code))))) + (() + (leave (G_ "too few arguments~%"))) + ((many ...) + (leave (G_ "too many arguments~%"))))))