unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Martin Becze <mjbecze@riseup.net>
To: 38408@debbugs.gnu.org
Cc: efraim@flashner.co.il, Martin Becze <mjbecze@riseup.net>
Subject: [bug#38408] [PATCH 3/3] Rewrote some of guix/import/crate.scm to use recursive-import-semver and updated script and test.
Date: Wed, 27 Nov 2019 19:16:52 -0500	[thread overview]
Message-ID: <052524339786cd4c0db5fda81547239c8bee6003.1574897905.git.mjbecze@riseup.net> (raw)
In-Reply-To: <cover.1574897905.git.mjbecze@riseup.net>

* guix/import/crate.scm (make-crate-sexp): Use <crate> <crate-version> as args
* guix/import/crate.scm (crate->crate-version): New Procedure
* guix/import/crate.scm (crate->versions): New Procedure
* guix/import/crate.scm (crate-recursive-import): Updated to user recursive-import-semver
* guix/scripts/import/crate.scm (guix-import-crate): Remove `define-public` generation from UI
* guix/tests/crate.scm: Updated tests
---
 guix/import/crate.scm         | 165 ++++++++++++++++++----------------
 guix/scripts/import/crate.scm |   9 +-
 tests/crate.scm               |   2 +-
 3 files changed, 91 insertions(+), 85 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 8dc014d232..da92c43b8c 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -38,6 +38,7 @@
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-71)
   #:export (crate->guix-package
             guix-package->crate-name
             crate-recursive-import
@@ -85,7 +86,7 @@
   crate-dependency?
   json->crate-dependency
   (id            crate-dependency-id "crate_id")  ;string
-  (kind          crate-dependency-kind "kind"     ;'normal | 'dev
+  (kind          crate-dependency-kind "kind"     ;'normal | 'dev | 'build
                  string->symbol)
   (requirement   crate-dependency-requirement "req")) ;string
 
@@ -111,7 +112,9 @@ record or #f if it was not found."
          (url  (string-append (%crate-base-url) path)))
     (match (assoc-ref (or (json-fetch url) '()) "dependencies")
       ((? vector? vector)
-       (map json->crate-dependency (vector->list vector)))
+       (filter (lambda (dep)
+                 (not (eq? (crate-dependency-kind dep) 'dev)))
+               (map json->crate-dependency (vector->list vector))))
       (_
        '()))))
 
@@ -141,62 +144,84 @@ record or #f if it was not found."
     ((args ...)
      `((arguments (,'quasiquote ,args))))))
 
-(define* (make-crate-sexp #:key name version cargo-inputs cargo-development-inputs
-                          home-page synopsis description license
-                          #:allow-other-keys)
-  "Return the `package' s-expression for a rust package with the given NAME,
-VERSION, CARGO-INPUTS, CARGO-DEVELOPMENT-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION,
-and LICENSE."
-  (let* ((port (http-fetch (crate-uri name version)))
+(define (make-crate-sexp crate version* dependencies)
+  "Return the `package' s-expression for a rust package given <crate>,
+ <crate-version> and a list of <crate-dependency>"
+  (define normal-dependency?
+    (match-lambda ((_ dep) (not (eq? (crate-dependency-kind dep) 'dev)))))
+
+  (define (string->license string)
+    (match (regexp-exec %dual-license-rx string)
+      (#f (list (spdx-string->license string)))
+      (m  (list (spdx-string->license (match:substring m 1))
+                (spdx-string->license (match:substring m 2))))))
+
+  (let* ((dep-crates dev-dep-crates (partition normal-dependency? dependencies))
+         (cargo-inputs (sort (unzip1 dep-crates)
+                             string-ci<?))
+         (cargo-development-inputs
+          (sort (unzip1 dev-dep-crates)
+                string-ci<?))
+         (name (crate-name crate))
+         (version (crate-version-number version*))
+         (home-page (or (crate-home-page crate)
+                        (crate-repository crate)))
+         (synopsis (crate-description crate))
+         (description (crate-description crate))
+         (license (and=> (crate-version-license version*)
+                         string->license))
+         (port (http-fetch (crate-uri name version)) )
          (guix-name (crate-name->package-name name))
-         (cargo-inputs (map crate-name->package-name cargo-inputs))
-         (cargo-development-inputs (map crate-name->package-name
-                                        cargo-development-inputs))
          (pkg `(package
-                   (name ,guix-name)
-                   (version ,version)
-                   (source (origin
-                             (method url-fetch)
-                             (uri (crate-uri ,name version))
-                             (file-name (string-append name "-" version ".tar.gz"))
-                             (sha256
-                              (base32
-                               ,(bytevector->nix-base32-string (port-sha256 port))))))
-                   (build-system cargo-build-system)
-                   ,@(maybe-arguments (append (maybe-cargo-inputs cargo-inputs)
-                                              (maybe-cargo-development-inputs
-                                                cargo-development-inputs)))
-                   (home-page ,(match home-page
-                                 (() "")
-                                 (_ home-page)))
-                   (synopsis ,synopsis)
-                   (description ,(beautify-description description))
-                   (license ,(match license
-                               (() #f)
-                               ((license) license)
-                               (_ `(list ,@license)))))))
-         (close-port port)
-         pkg))
+                 (name ,guix-name)
+                 (version ,version)
+                 (source (origin
+                           (method url-fetch)
+                           (uri (crate-uri ,name version))
+                           (file-name (string-append name "-" version ".crate"))
+                           (sha256
+                            (base32
+                             ,(bytevector->nix-base32-string (port-sha256 port))))))
+                 (build-system cargo-build-system)
+                 ,@(maybe-arguments (append (maybe-cargo-inputs cargo-inputs)
+                                            (maybe-cargo-development-inputs
+                                             cargo-development-inputs)))
+                 (home-page ,(match home-page
+                               (() "")
+                               (_ home-page)))
+                 (synopsis ,synopsis)
+                 (description ,(beautify-description description))
+                 (license ,(match license
+                             (() #f)
+                             ((license) license)
+                             (_ `(list ,@license)))))))
+
+    (close-port port)
+    pkg))
 
 (define %dual-license-rx
   ;; Dual licensing is represented by a string such as "MIT OR Apache-2.0".
   ;; This regexp matches that.
   (make-regexp "^(.*) OR (.*)$"))
 
+(define (crate->crate-version crate version-number)
+  "returns the <crate-version> for a given CRATE and VERSION-NUMBER"
+  (find (lambda (version)
+            (string=? (crate-version-number version)
+                      version-number))
+          (crate-versions crate)))
+
+(define (crate->versions crate)
+  "Returns a list of versions for a given CRATE"
+  (map (lambda (version)
+         (crate-version-number version))
+       (crate-versions crate)))
+
 (define* (crate->guix-package crate-name #:optional version)
   "Fetch the metadata for CRATE-NAME from crates.io, and return the
 `package' s-expression corresponding to that package, or #f on failure.
 When VERSION is specified, attempt to fetch that version; otherwise fetch the
 latest version of CRATE-NAME."
-  (define (string->license string)
-    (match (regexp-exec %dual-license-rx string)
-      (#f (list (spdx-string->license string)))
-      (m  (list (spdx-string->license (match:substring m 1))
-                (spdx-string->license (match:substring m 2))))))
-
-  (define (normal-dependency? dependency)
-    (eq? (crate-dependency-kind dependency) 'normal))
-
   (define crate
     (lookup-crate crate-name))
 
@@ -205,38 +230,27 @@ latest version of CRATE-NAME."
         (crate-latest-version crate)))
 
   (define version*
-    (find (lambda (version)
-            (string=? (crate-version-number version)
-                      version-number))
-          (crate-versions crate)))
+    (crate->crate-version crate version-number))
 
-  (and crate version*
-       (let* ((dependencies   (crate-version-dependencies version*))
-              (dep-crates     (filter normal-dependency? dependencies))
-              (dev-dep-crates (remove normal-dependency? dependencies))
-              (cargo-inputs   (sort (map crate-dependency-id dep-crates)
-                                    string-ci<?))
-              (cargo-development-inputs
-               (sort (map crate-dependency-id dev-dep-crates)
-                     string-ci<?)))
-         (values
-          (make-crate-sexp #:name crate-name
-                           #:version (crate-version-number version*)
-                           #:cargo-inputs cargo-inputs
-                           #:cargo-development-inputs cargo-development-inputs
-                           #:home-page (or (crate-home-page crate)
-                                           (crate-repository crate))
-                           #:synopsis (crate-description crate)
-                           #:description (crate-description crate)
-                           #:license (and=> (crate-version-license version*)
-                                            string->license))
-          (append cargo-inputs cargo-development-inputs)))))
+  (define dependencies (map
+                        (lambda (dep)
+                          (list (crate-name->package-name
+                           (crate-dependency-id dep)) dep))
+                        (crate-version-dependencies version*)))
+  (make-crate-sexp crate version* dependencies))
 
-(define (crate-recursive-import crate-name)
-  (recursive-import crate-name #f
-                    #:repo->guix-package (lambda (name repo)
-                                           (crate->guix-package name))
-                    #:guix-name crate-name->package-name))
+(define* (crate-recursive-import name #:optional version)
+  (recursive-import-semver
+   #:name name
+   #:version version
+   #:name->metadata lookup-crate
+   #:metadata->package crate->crate-version
+   #:metadata-versions crate->versions
+   #:package-dependencies crate-version-dependencies
+   #:dependency-name crate-dependency-id
+   #:dependency-range crate-dependency-requirement
+   #:guix-name crate-name->package-name
+   #:make-sexp make-crate-sexp))
 
 (define (guix-package->crate-name package)
   "Return the crate name of PACKAGE."
@@ -285,4 +299,3 @@ latest version of CRATE-NAME."
    (description "Updater for crates.io packages")
    (pred crate-package?)
    (latest latest-release)))
-
diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm
index 4690cceb4d..85ae6fbe59 100644
--- a/guix/scripts/import/crate.scm
+++ b/guix/scripts/import/crate.scm
@@ -96,14 +96,7 @@ Import and convert the crate.io package for PACKAGE-NAME.\n"))
          (package-name->name+version spec))
 
        (if (assoc-ref opts 'recursive)
-           (map (match-lambda
-                  ((and ('package ('name name) . rest) pkg)
-                   `(define-public ,(string->symbol name)
-                      ,pkg))
-                  (_ #f))
-                (reverse
-                 (stream->list
-                  (crate-recursive-import name))))
+           (stream->list (crate-recursive-import name version))
            (let ((sexp (crate->guix-package name version)))
              (unless sexp
                (leave (G_ "failed to download meta-data for package '~a'~%")
diff --git a/tests/crate.scm b/tests/crate.scm
index c14862ad9f..b77cbb08c6 100644
--- a/tests/crate.scm
+++ b/tests/crate.scm
@@ -95,7 +95,7 @@
          ('source ('origin
                     ('method 'url-fetch)
                     ('uri ('crate-uri "foo" 'version))
-                    ('file-name ('string-append 'name "-" 'version ".tar.gz"))
+                    ('file-name ('string-append 'name "-" 'version ".crate"))
                     ('sha256
                      ('base32
                       (? string? hash)))))
-- 
2.24.0

  parent reply	other threads:[~2019-11-28  0:18 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 21:39 [bug#44560] [PATCH v16 0/6] New take on: Semantic version aware recursive importer for crates Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 1/6] import: utils: 'recursive-import' accepts an optional version parameter Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 2/6] guix: self: Add guile-semver as a depenedency Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 3/6] import: crate: Use guile-semver to resolve module versions Hartmut Goebel
2020-11-10 22:13   ` Hartmut Goebel
2019-11-28  0:13     ` [bug#38408] [PATCH 0/3] (WIP) Semantic version aware recusive importer for crates Martin Becze
2019-11-28  0:16       ` [bug#38408] [PATCH 1/3] gnu: added new function, find-packages-by-name*/direct Martin Becze
2019-11-28  0:16       ` [bug#38408] [PATCH 2/3] gnu: added new procedure, recusive-import-semver Martin Becze
2019-11-28  0:16       ` Martin Becze [this message]
2019-11-30 16:36         ` [bug#38408] [PATCH 3/3] Rewrote some of guix/import/crate.scm to use recursive-import-semver and updated script and test Martin Becze
2019-12-01  9:00           ` Efraim Flashner
2019-12-05 20:05       ` [bug#38408] [PATCH v2 0/5] Semantic version aware recusive importer for crates Martin Becze
2019-12-05 20:05         ` [bug#38408] [PATCH v2 1/5] gnu: added new function, find-packages-by-name*/direct Martin Becze
2019-12-05 20:05         ` [bug#38408] [PATCH v2 2/5] gnu: added new procedure, recusive-import-semver Martin Becze
2019-12-05 20:05         ` [bug#38408] [PATCH v2 3/5] Rewrote some of guix/import/crate.scm to use recursive-import-semver and updated script and test Martin Becze
2019-12-05 20:05         ` [bug#38408] [PATCH v2 4/5] added "#:skip-build? #t" to the output of (make-crate-sexp). Most the the packages imported will be libaries and won't need to build. The top level package will build them though Martin Becze
2019-12-05 20:05         ` [bug#38408] [PATCH v2 5/5] guix: crate: Depublicated build and normal dependencies Martin Becze
2019-12-06 18:21       ` [bug#38408] [PATCH v3 0/5] Semantic version aware recusive importer for crates Martin Becze
2019-12-06 18:21         ` [bug#38408] [PATCH v3 1/5] gnu: added new function, find-packages-by-name*/direct Martin Becze
2019-12-06 18:21         ` [bug#38408] [PATCH v3 2/5] gnu: added new procedure, recusive-import-semver Martin Becze
2019-12-06 18:21         ` [bug#38408] [PATCH v3 3/5] Rewrote some of guix/import/crate.scm to use recursive-import-semver and updated script and test Martin Becze
2019-12-06 18:21         ` [bug#38408] [PATCH v3 4/5] added "#:skip-build? #t" to the output of (make-crate-sexp). Most the the packages imported will be libaries and won't need to build. The top level package will build them though Martin Becze
2019-12-06 18:21         ` [bug#38408] [PATCH v3 5/5] guix: crate: Depublicated dependencies Martin Becze
2019-12-10 19:23       ` [bug#38408] [PATCH v4 0/6] Semantic version aware recusive importer for crates Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 1/6] gnu: added new function, find-packages-by-name*/direct Martin Becze
2019-12-19 22:00           ` Ludovic Courtès
2019-12-20 18:37             ` Martin Becze
2019-12-27 18:38               ` Ludovic Courtès
2020-01-18 16:40                 ` [bug#38408] [PATCH v6] Semantic version aware recusive importer for crates Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 2/6] gnu: added new procedure, recusive-import-semver Martin Becze
2019-12-19 22:07           ` Ludovic Courtès
2019-12-20 18:46             ` Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 3/6] Rewrote some of guix/import/crate.scm to use recursive-import-semver and updated script and test Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 4/6] added "#:skip-build? #t" to the output of (make-crate-sexp). Most the the packages imported will be libaries and won't need to build. The top level package will build them though Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 5/6] guix: crate: Depublicated dependencies Martin Becze
2019-12-10 19:23         ` [bug#38408] [PATCH v4 6/6] guix: import: recursive-import-semver: allow the range of a package to be specified when begining import Martin Becze
2019-12-16 23:30       ` [bug#38408] Rewrote recursive-import-semver based on topological-sort Martin Becze
2020-02-04 12:18       ` [bug#38408] [PATCH v9 0/8] recursive semver crate importer! Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 1/8] guix: import: (recursive-import) Allow for version numbers Martin Becze
2020-02-17 10:03           ` Efraim Flashner
2020-02-04 12:18         ` [bug#38408] [PATCH v9 2/8] guix: import: crate: Use semver to resovle module versions Martin Becze
2020-02-17 14:35           ` Ludovic Courtès
2020-02-17 14:57             ` Efraim Flashner
2020-02-17 15:37               ` Ludovic Courtès
2020-02-18  8:56                 ` Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 3/8] Added Guile-Semver as a dependency to guix Martin Becze
2020-02-17 10:03           ` Efraim Flashner
2020-02-17 14:36             ` Ludovic Courtès
2020-02-18  9:30               ` Martin Becze
2020-02-20  9:40                 ` Ludovic Courtès
2020-02-20 16:54                   ` Martin Becze
2020-02-21  9:01                     ` Ludovic Courtès
2020-02-21 16:25                       ` Martin Becze
2020-02-21 16:27                         ` Leo Famulari
2020-02-23 20:34                           ` Martin Becze
2020-02-23 21:05                         ` Martin Becze
2020-03-11 20:20                           ` Martin Becze
2020-03-21 18:35                             ` Martin Becze
2020-03-22 19:26                               ` Leo Famulari
2020-03-22 20:10                               ` Leo Famulari
2020-03-23  9:50                                 ` Martin Becze
2020-03-23 16:28                                   ` Martin Becze
2020-03-24 10:18                                     ` Ludovic Courtès
2020-03-24 14:19                                       ` Martin Becze
2020-03-24 19:00                                       ` Martin Becze
2020-04-12 15:07                                         ` Martin Becze
2020-04-12 16:59                                           ` Ludovic Courtès
2020-04-17 14:57                                             ` Martin Becze
2020-04-29 19:50                                               ` Martin Becze
2020-04-29 19:51                                               ` Martin Becze
2020-05-08 19:57                                                 ` Martin Becze
2020-08-18  9:44                                                   ` Martin Becze
2020-07-05  0:23                                                 ` Jakub Kądziołka
2020-02-04 12:18         ` [bug#38408] [PATCH v9 4/8] guix: import: utils: allow generation of inputs to be version aware Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 5/8] guix: import: crate: deduplicate dependencies Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 6/8] guix: import: crate: memorize crate->guix-package Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 7/8] guix: import: utils: trim patch version from names Martin Becze
2020-02-04 12:18         ` [bug#38408] [PATCH v9 8/8] guix: import: parametrized importing of dev dependencies Martin Becze
2020-02-20 18:53         ` [bug#38408] [PATCH v9 0/8] recursive semver crate importer! Leo Famulari
2020-02-21  8:35           ` Martin Becze
2020-02-21 12:15             ` Efraim Flashner
2020-02-21 16:29               ` Martin Becze
2020-11-07 22:19       ` [bug#38408] [PATCH 0/3] (WIP) Semantic version aware recusive importer for crates Hartmut Goebel
2020-11-07 22:35         ` Marius Bakke
2020-11-09 17:15           ` Hartmut Goebel
2020-11-09 17:27             ` Nicolas Goaziou
2020-11-11 15:06       ` [bug#38408] [PATCH v16 3/6] import: crate: Use guile-semver to resolve module versions Timothy Sample
2020-11-16 19:07       ` [bug#44694] [PATCH v17 0/8] New take continued: Semantic version aware recursive Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 1/8] guix: self: Add guile-semver as a depenedency Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 2/8] import: utils: 'recursive-import' accepts an optional version parameter Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 3/8] import: crate: Use guile-semver to resolve module versions Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 4/8] import: crate: Memorize crate->guix-package Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 5/8] import: crate: Parameterized importing of dev dependencies Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 6/8] import: utils: Trim patch version from names Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 7/8] import: crate: Trim version for names after left-most non-zero part Hartmut Goebel
2020-11-16 19:07         ` [bug#38408] [PATCH v17 8/8] import: crate: Use existing package satisfying semver requirement Hartmut Goebel
2020-11-17 21:54         ` [bug#38408] [PATCH v17 0/8] New take continued: Semantic version aware recursive Martin Becze
2020-12-02 21:13         ` bug#38408: " Hartmut Goebel
2020-12-02 21:48           ` [bug#38408] " Leo Famulari
2020-11-17 21:43     ` [bug#38408] [PATCH v16 3/6] import: crate: Use guile-semver to resolve module versions Martin Becze
2020-11-17 21:51       ` Martin Becze
2020-11-18  7:56         ` Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 4/6] import: crate: Memorize crate->guix-package Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 5/6] import: utils: Trim patch version from names Hartmut Goebel
2020-11-10 21:39 ` [bug#38408] [PATCH v16 6/6] import: crate: Parameterized importing of dev dependencies Hartmut Goebel
2020-11-10 22:21   ` Hartmut Goebel
2020-11-10 22:24 ` [bug#38408] [PATCH v16 0/6] New take on: Semantic version aware recursive importer for crates Hartmut Goebel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=052524339786cd4c0db5fda81547239c8bee6003.1574897905.git.mjbecze@riseup.net \
    --to=mjbecze@riseup.net \
    --cc=38408@debbugs.gnu.org \
    --cc=efraim@flashner.co.il \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).