unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob a0115f5e3643672fe4d113d30f24949a66fa4232 4266 bytes (raw)
name: guix/import/gem.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
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;;
;;; 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 gem)
  #:use-module (ice-9 match)
  #:use-module (ice-9 pretty-print)
  #:use-module (json)
  #:use-module (web uri)
  #:use-module (guix utils)
  #:use-module (guix import utils)
  #:use-module (guix import json)
  #:use-module (guix packages)
  #:use-module (guix licenses)
  #:export (gem->guix-package))

(define (rubygems-fetch name)
  "Return an alist representation of the RubyGems metadata for the package NAME,
or #f on failure."
  (json-fetch
   (string-append "https://rubygems.org/api/v1/gems/" name ".json")))

(define (ruby-package-name name)
  "Given the NAME of a package on RubyGems, return a Guix-compliant name for
the package."
  (if (string-prefix? "ruby-" name)
      (snake-case name)
      (string-append "ruby-" (snake-case name))))

(define (make-gem-sexp name version source-url home-page description
                       dependencies licenses)
  "Return the `package' s-expression for a Ruby package with the given NAME,
VERSION, SOURCE-URL, HOME-PAGE, DESCRIPTION, DEPENDENCIES, and LICENSES."
  (call-with-temporary-output-file
   (lambda (temp port)
     (and (url-fetch source-url temp)
          `(package
             (name ,(ruby-package-name name))
             (version ,version)
             (source (origin
                       (method url-fetch)
                       (uri (rubygems-uri ,name version))
                       (sha256
                        (base32
                         ,(guix-hash-url temp)))))
             (build-system ruby-build-system)
             ,@(if (null? dependencies)
                   '()
                   `(propagated-inputs
                     (,'quasiquote
                      ,(map (lambda (name)
                              `(,name
                                (,'unquote
                                 ,(string->symbol name))))
                            dependencies))))
             (synopsis ,description) ; nothing better to use
             (description ,description)
             (home-page ,home-page)
             (license ,(match licenses
                         ((license) (license->symbol license))
                         (_ (map license->symbol licenses)))))))))

(define (gem->guix-package package-name)
  "Fetch the metadata for PACKAGE-NAME from rubygems.org, and return the
`package' s-expression corresponding to that package, or #f on failure."
  (let ((package (rubygems-fetch package-name)))
    (and package
         (let ((name         (assoc-ref package "name"))
               (version      (assoc-ref package "version"))
               (source-url   (assoc-ref package "gem_uri"))
               (description  (assoc-ref package "info"))
               (home-page    (assoc-ref package "homepage_uri"))
               (dependencies (map (lambda (dep)
                                    (let ((name (assoc-ref dep "name")))
                                      (if (string=? name "bundler")
                                          "bundler" ; special case, no prefix
                                          (ruby-package-name name))))
                                  (assoc-ref* package "dependencies"
                                              "runtime")))
               (licenses     (map string->license
                                  (assoc-ref package "licenses"))))
           (make-gem-sexp name version source-url home-page
                          description dependencies licenses)))))

debug log:

solving a0115f5 ...
found a0115f5 in https://yhetil.org/guix-devel/878u9allll.fsf@gnu.org/

applying [1/1] https://yhetil.org/guix-devel/878u9allll.fsf@gnu.org/
diff --git a/guix/import/gem.scm b/guix/import/gem.scm
new file mode 100644
index 0000000..a0115f5

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

index at:
100644 a0115f5e3643672fe4d113d30f24949a66fa4232	guix/import/gem.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).