unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob b646f9329562cc0ff9ee76c041bbbc64bf264423 11893 bytes (raw)
name: guix/import/juliahub.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; 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 <http://www.gnu.org/licenses/>.

(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 streams)
  #:use-module (ice-9 string-fun)
  #:use-module (srfi srfi-1)
  #: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)
  #:use-module (guix packages)
  #:use-module (guix upstream)
  #:use-module (json)
  #:use-module ((guix licenses) #:prefix license:)

  #:export (juliahub->guix-package
            %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"
        "ArgTools"
        "Artifacts"
        "Base64"
        "CRC32c"
        "FileWatching"
        "Libdl"
        "Logging"
        "Mmap"
        "NetworkOptions"
        "SHA"
        "Serialization"
        "Sockets"
        "Unicode"
        "DelimitedFiles"
        "LinearAlgebra"
        "Markdown"
        "Printf"
        "Random"
        "Tar"
        "Dates"
        "Distributed"
        "Future"
        "InteractiveUtils"
        "LibGit2"
        "Profile"
        "SparseArrays"
        "UUIDs"
        "REPL"
        "SharedArrays"
        "Statistics"
        "SuiteSparse"
        "TOML"
        "Test"
        "LibCURL"
        "Downloads"
        "Pkg"
        "LazyArtifacts"))

(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-dependencies vector)
  (if (vector? vector)
      (filter-map
       (lambda (el)
         (let ((dep (json->juliahub-dependency el)))
           (if (not (member (juliahub-dependency-name dep)
                            %julia-stdlibs))
               dep
               #f)))
       (vector->list vector))))

(define (ini-list->test-dependencies lst)
  (match lst
    (('test '= ooo ...)
     `(,(caar ooo) ,@(test-list->test-dependencies (cdar ooo))))
    ((value ooo ...)
     (ini-list->test-dependencies ooo))
    ('()
      '())))

(define (test-list->test-dependencies lst)
  (match lst
    ((('unquote value) ooo ...)
     `(,value ,@(test-list->test-dependencies ooo)))
    ('()
      '())))

(define (parse-test-dependencies directory)
  (let* ((port (open-input-file (string-append directory "/Project.toml")))
         (ini-list (stream->list (port->stream port read))))
    (close-port port)
    (ini-list->test-dependencies ini-list)))

;; Julia package.
(define-json-mapping <juliahub-package> make-juliahub-package juliahub-package?
  json->juliahub-package
  (homepage juliahub-package-homepage) ;string
  (readme juliahub-package-readme) ;string
  (version juliahub-package-version) ;string
  (description juliahub-package-description) ;string
  (dependencies
   juliahub-package-dependencies "deps"
   json->juliahub-dependencies) ;list of <juliahub-dependency>
  (url juliahub-package-url) ;string
  (uuid juliahub-package-uuid) ;string
  (license juliahub-package-license)) ;string

(define-json-mapping <juliahub-dependency>
  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

(define (julia-name->guix-name name)
  (string-append "julia-" (snake-case 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))

(define (make-julia-sexp name source home-page synopsis description
                         direct-dependencies test-dependencies-names licenses)
  "Return the `package' s-expression for a Julia package with the given NAME,
VERSION, URI, HASH, HOME-PAGE, DESCRIPTION, DIRECT-DEPENDENCIES,
TEST-DEPENDENCIES-NAMES and LICENSES."
  `(package
     (name ,(julia-name->guix-name name))
     (version ,version)
     (source ,source)
     (build-system julia-build-system)
     ,@(if (null? direct-dependencies)
           '()
           `((propagated-inputs
              (list ,@(map (compose julia-name->guix-name juliahub-dependency-name)
                           direct-dependencies)))))
     ,@(if (null? test-dependencies-names)
           '()
           `((native-inputs
              (list ,@(map julia-name->guix-name test-dependencies-names)))))
     (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-toml (ini-fetch (general-url package-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
                       (juliahub-package-url package)
                       `(tag-or-commit
                         . ,(string-append
                             "v" (juliahub-package-version package))))))
          (let* ((direct-dependencies
                  (filter juliahub-dependency-direct?
                          (juliahub-package-dependencies package)))
                 (dependencies-names
                  (map juliahub-dependency-name
                       direct-dependencies))
                 (licenses
                  (map spdx-string->license
                       (list (juliahub-package-license package))))
                 (test-dependencies-names
                  (if subdir
                      (parse-test-dependencies
                       (string-append subdir "/" directory))
                      (parse-test-dependencies directory))))
            (values (make-julia-sexp
                     package-name
                     source
                     (juliahub-package-homepage package)
                     (juliahub-package-description package)
                     (beautify-description (juliahub-package-readme package))
                     direct-dependencies
                     test-dependencies-names
                     licenses)
                    (append dependencies-names test-dependencies-names))))
        (values #f '()))))

(define (guix-package->juliahub-name package)
  (let* ((url (juliahub-package-url package))
         (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)))
    package-name))

(define* (import-release package #:key (version #f))
  "Return an <upstream-source> for the latest release of PACKAGE."
  (let* ((package-name (guix-package->juliahub-name package))
         (package      (juliahub-fetch package-name))
         (version  (or version (juliahub-package-version package))))
    (upstream-source
     (package (package-name package))
     (version version)
     (urls (list (juliahub-package-url package))))))

(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 julia-name->guix-name
                    #:version version))

debug log:

solving b646f9329562 ...
found b646f9329562 in https://yhetil.org/guix-patches/cfb939c1da2ab7c3997297e91dd69712d715d2af.1695060058.git.zimon.toutoune@gmail.com/
found 2ea461b72aba in https://yhetil.org/guix-patches/f48f3d3027eacc1834b627f2b4e6a5903d53314c.1695060058.git.zimon.toutoune@gmail.com/
found 5327e923251d in https://yhetil.org/guix-patches/e42032f4db1c8b76ff5ba94805deba47992a7c39.1695060058.git.zimon.toutoune@gmail.com/
found fc25ba1d4220 in https://yhetil.org/guix-patches/9c97220836376a2e6de87f52b4a7b842581225ed.1695060058.git.zimon.toutoune@gmail.com/
found b1eeb736a824 in https://yhetil.org/guix-patches/d21d6314221dd876b598a86a655b658821c3334f.1695060058.git.zimon.toutoune@gmail.com/
found af08f3d698d0 in https://yhetil.org/guix-patches/be0f04de20abad380175b8f9509fed461e15690f.1695060058.git.zimon.toutoune@gmail.com/ ||
	https://yhetil.org/guix-patches/20230918180316.cQaFLYyQ65tV_VUL1dkutumkw5Mi7Rof6JjqrCavKVE@z/
found c38c830caaa0 in https://yhetil.org/guix-patches/26c9a5ca41ad1697225de11b5513fcfe04d26f71.1695060058.git.zimon.toutoune@gmail.com/
found fb361a004435 in https://yhetil.org/guix-patches/9582ebba5df585ec5c71e008e71aaefafc036753.1695060058.git.zimon.toutoune@gmail.com/
found 4c3ceed10904 in https://yhetil.org/guix-patches/14e997a8b389bb18d62e00178a68fc5434869da2.1695060058.git.zimon.toutoune@gmail.com/
found 4544dee98016 in https://yhetil.org/guix-patches/57feddb288135a1d5953340fcc5bfe9e3159e372.1695060058.git.zimon.toutoune@gmail.com/
found efe6abbb2481 in https://yhetil.org/guix-patches/cc098ba63817ae293b4c0ba5d72bc61c11057f22.1695060058.git.zimon.toutoune@gmail.com/

applying [1/11] https://yhetil.org/guix-patches/cc098ba63817ae293b4c0ba5d72bc61c11057f22.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
new file mode 100644
index 000000000000..efe6abbb2481


applying [2/11] https://yhetil.org/guix-patches/57feddb288135a1d5953340fcc5bfe9e3159e372.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index efe6abbb2481..4544dee98016 100644


applying [3/11] https://yhetil.org/guix-patches/14e997a8b389bb18d62e00178a68fc5434869da2.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index 4544dee98016..4c3ceed10904 100644


applying [4/11] https://yhetil.org/guix-patches/9582ebba5df585ec5c71e008e71aaefafc036753.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index 4c3ceed10904..fb361a004435 100644


applying [5/11] https://yhetil.org/guix-patches/26c9a5ca41ad1697225de11b5513fcfe04d26f71.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index fb361a004435..c38c830caaa0 100644


applying [6/11] https://yhetil.org/guix-patches/be0f04de20abad380175b8f9509fed461e15690f.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index c38c830caaa0..af08f3d698d0 100644

Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.

skipping https://yhetil.org/guix-patches/20230918180316.cQaFLYyQ65tV_VUL1dkutumkw5Mi7Rof6JjqrCavKVE@z/ for af08f3d698d0
index at:
100644 af08f3d698d0c5cf615aaa9b81bc82165e690052	guix/import/juliahub.scm

applying [7/11] https://yhetil.org/guix-patches/d21d6314221dd876b598a86a655b658821c3334f.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index af08f3d698d0..b1eeb736a824 100644


applying [8/11] https://yhetil.org/guix-patches/9c97220836376a2e6de87f52b4a7b842581225ed.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index b1eeb736a824..fc25ba1d4220 100644


applying [9/11] https://yhetil.org/guix-patches/e42032f4db1c8b76ff5ba94805deba47992a7c39.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index fc25ba1d4220..5327e923251d 100644


applying [10/11] https://yhetil.org/guix-patches/f48f3d3027eacc1834b627f2b4e6a5903d53314c.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index 5327e923251d..2ea461b72aba 100644


applying [11/11] https://yhetil.org/guix-patches/cfb939c1da2ab7c3997297e91dd69712d715d2af.1695060058.git.zimon.toutoune@gmail.com/
diff --git a/guix/import/juliahub.scm b/guix/import/juliahub.scm
index 2ea461b72aba..b646f9329562 100644

Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.
Checking patch guix/import/juliahub.scm...
Applied patch guix/import/juliahub.scm cleanly.

index at:
100644 b646f9329562cc0ff9ee76c041bbbc64bf264423	guix/import/juliahub.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).