GNU bug report logs - #44694
[PATCH v17 0/8] New take continued: Semantic version aware recursive

Previous Next

Package: guix-patches;

Reported by: Hartmut Goebel <h.goebel <at> crazy-compilers.com>

Date: Mon, 16 Nov 2020 19:08:01 UTC

Severity: normal

Tags: patch

Merged with 38408, 44560

Fixed in version 44560

Done: Hartmut Goebel <h.goebel <at> crazy-compilers.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 44694 in the body.
You can then email your comments to 44694 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#44694; Package guix-patches. (Mon, 16 Nov 2020 19:08:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Hartmut Goebel <h.goebel <at> crazy-compilers.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Mon, 16 Nov 2020 19:08:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
To: guix-patches <at> gnu.org,
	38408 <at> debbugs.gnu.org
Subject: [PATCH v17 0/8] New take continued: Semantic version aware recursive
Date: Mon, 16 Nov 2020 20:07:05 +0100
This is another revision of the patch set. Major changes compared to v16 are:

* When searching dependencies, prefer an existing package satisfying
  semver requirement over importing the highest version create.

  This saves adding a lot of new packages. As an example: When importing
  sequoia-openpgp <at> 0.20.0 this only imports 19 crates now, compared to 96
  using the former method.

* Package names are not trimmed to the first no-zero part.

* Test cases have been improved so packages have different versions. THis
  actually showed some bubs I solved (details see below).


Notable bug-fixes:

* Change selection of package version: use the highest version matching the
  required range instead of first one.
* Sort dependencies by name (was version)

Some details about the improved test cases

* Change crate names to avoid possible confusion
* Use different version (not 1.0.0 for all)
* Add some versions to some of the crates to test selecting the version.
* ids of create version entries are numbers.
* Document crate versions and dependencies used in tests
* Actually define some dependencies using caret semver.


Hartmut Goebel (3):
  import: utils: Trim patch version from names.
  import: crate: Trim version for names after left-most non-zero part.
  import: crate: Use existing package satisfying semver requirement.

Martin Becze (5):
  guix: self: Add guile-semver as a depenedency.
  import: utils: 'recursive-import' accepts an optional version
    parameter.
  import: crate: Use guile-semver to resolve module versions.
  import: crate: Memorize crate->guix-package.
  import: crate: Parameterized importing of dev dependencies.

 guix/import/cran.scm          |   8 +-
 guix/import/crate.scm         | 150 +++++++--
 guix/import/elpa.scm          |   6 +-
 guix/import/gem.scm           |   6 +-
 guix/import/opam.scm          |   8 +-
 guix/import/pypi.scm          |   8 +-
 guix/import/stackage.scm      |   5 +-
 guix/import/utils.scm         |  84 +++--
 guix/scripts/import/cran.scm  |   5 +-
 guix/scripts/import/crate.scm |  13 +-
 guix/scripts/import/elpa.scm  |   4 +-
 guix/self.scm                 |   8 +-
 tests/crate.scm               | 581 +++++++++++++++++++++++-----------
 tests/elpa.scm                |   3 +-
 tests/import-utils.scm        |   8 +-
 15 files changed, 608 insertions(+), 289 deletions(-)

-- 
2.21.3





Information forwarded to guix-patches <at> gnu.org:
bug#44694; Package guix-patches. (Mon, 16 Nov 2020 19:09:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
To: 38408 <at> debbugs.gnu.org,
	guix-patches <at> gnu.org
Subject: [PATCH v17 8/8] import: crate: Use existing package satisfying semver
 requirement.
Date: Mon, 16 Nov 2020 20:07:28 +0100
If a package satisfying the dependency's semver requirement already exists,
use it. Prior to this change the highest version matching the semver
requirement was used (and imported in case it was not defined as package
already).

When resolving a dependency (now done in `sort-map-dependencies`), first
search for a package matching the semver requirement and only if this fails
reach out for a crate.

* guix/import/crate.scm (crate->guix-package)[find-package-version]: New
  function. [dependency-name+version]: New function.
  [sort-map-dependencies]: Use it instead of lambda function.

* tests/crate.scm (test-doctool-crate, test-doctool-dependencies): New
  variables.
  ("self-test …", "cargo-recursive-import-hoors-existing-packages"): New
  tests.
---
 guix/import/crate.scm | 37 ++++++++++++++-----
 tests/crate.scm       | 83 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+), 8 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index b133529ba7..3bc261b04e 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -32,6 +32,7 @@
   #:use-module (guix packages)
   #:use-module (guix upstream)
   #:use-module (guix utils)
+  #:use-module (gnu packages)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:use-module (json)
@@ -92,7 +93,7 @@
   (requirement   crate-dependency-requirement "req")) ;string
 
 (module-autoload! (current-module)
-		  '(semver) '(string->semver semver<?))
+		  '(semver) '(string->semver semver->string semver<?))
 (module-autoload! (current-module)
 		  '(semver ranges) '(string->semver-range semver-range-contains?))
 
@@ -235,6 +236,21 @@ look up the development dependencs for the given crate."
          (or version
              (crate-latest-version crate))))
 
+  ;; find the highest existing package that fulfills the semver <range>
+  (define (find-package-version name range)
+    (let* ((semver-range (string->semver-range range))
+           (versions
+            (sort
+             (filter (lambda (version)
+                       (semver-range-contains? semver-range version))
+                     (map (lambda (pkg)
+                            (string->semver (package-version pkg)))
+                          (find-packages-by-name
+                           (crate-name->package-name name))))
+             semver<?)))
+      (and (not (null-list? versions))
+           (semver->string (last versions)))))
+
   ;; find the highest version of a crate that fulfills the semver <range>
   (define (find-crate-version crate range)
     (let* ((semver-range (string->semver-range range))
@@ -251,6 +267,17 @@ look up the development dependencs for the given crate."
       (and (not (null-list? versions))
            (second (last versions)))))
 
+  (define (dependency-name+version dep)
+    (let* ((name (crate-dependency-id dep))
+           (req (crate-dependency-requirement dep))
+           (existing-version (find-package-version name req)))
+      (if existing-version
+          (list name existing-version)
+          (let* ((crate (lookup-crate* name))
+                 (ver (find-crate-version crate req)))
+            (list name
+                  (crate-version-number ver))))))
+
   (define version*
     (and crate
          (find-crate-version crate version-number)))
@@ -258,13 +285,7 @@ look up the development dependencs for the given crate."
   ;; sort and map the dependencies to a list containing
   ;; pairs of (name version)
   (define (sort-map-dependencies deps)
-    (sort (map (lambda (dep)
-                 (let* ((name (crate-dependency-id dep))
-                        (crate (lookup-crate* name))
-                        (req (crate-dependency-requirement dep))
-                        (ver (find-crate-version crate req)))
-                   (list name
-                         (crate-version-number ver))))
+    (sort (map dependency-name+version
                deps)
           (match-lambda* (((name _) ...)
                           (apply string-ci<? name)))))
diff --git a/tests/crate.scm b/tests/crate.scm
index 1506daeadd..a24f734093 100644
--- a/tests/crate.scm
+++ b/tests/crate.scm
@@ -25,6 +25,7 @@
   #:use-module (guix build-system cargo)
   #:use-module (gcrypt hash)
   #:use-module (guix tests)
+  #:use-module (gnu packages)
   #:use-module (ice-9 iconv)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-64))
@@ -312,6 +313,7 @@
   \"dependencies\": []
 }")
 
+
 (define test-source-hash
   "")
 
@@ -572,4 +574,85 @@
   '(license:expat license:asl2.0)
   (string->license "MIT/Apache-2.0"))
 
+
+
+(define test-doctool-crate
+  "{
+  \"crate\": {
+    \"max_version\": \"2.2.2\",
+    \"name\": \"leaf-bob\",
+    \"description\": \"summary\",
+    \"homepage\": \"http://example.com\",
+    \"repository\": \"http://example.com\",
+    \"keywords\": [\"dummy\", \"test\"],
+    \"categories\": [\"test\"]
+    \"actual_versions\": [
+      { \"id\": 234280,
+        \"num\": \"2.2.2\",
+        \"license\": \"MIT OR Apache-2.0\",
+        \"links\": {
+          \"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\"
+        }
+      }
+    ]
+  }
+}")
+
+;; FIXME: This test depends on some existing packages
+(define test-doctool-dependencies
+  "{
+  \"dependencies\": [
+     {
+       \"crate_id\": \"docopt\",
+       \"kind\": \"normal\",
+       \"req\": \"^0.8.1\"
+     }
+  ]
+}")
+
+
+(test-assert "self-test: rust-docopt 0.8.x is gone, please adjust the test case"
+  (not (null? (find-packages-by-name "rust-docopt" "0.8"))))
+
+(test-assert "cargo-recursive-import-hoors-existing-packages"
+  (mock ((guix http-client) http-fetch
+         (lambda (url . rest)
+           (match url
+             ("https://crates.io/api/v1/crates/doctool"
+              (open-input-string test-doctool-crate))
+             ("https://crates.io/api/v1/crates/doctool/2.2.2/download"
+              (set! test-source-hash
+                    (bytevector->nix-base32-string
+                     (sha256 (string->bytevector "empty file\n" "utf-8"))))
+              (open-input-string "empty file\n"))
+             ("https://crates.io/api/v1/crates/doctool/2.2.2/dependencies"
+              (open-input-string test-doctool-dependencies))
+             (_ (error "Unexpected URL: " url)))))
+        (match (crate-recursive-import "doctool")
+          (((define-public 'rust-doctool-2
+              (package
+                (name "rust-doctool")
+                (version "2.2.2")
+                (source
+                 (origin
+                   (method url-fetch)
+                   (uri (crate-uri "doctool" version))
+                   (file-name
+                    (string-append name "-" version ".tar.gz"))
+                   (sha256
+                    (base32
+                     (?  string? hash)))))
+                (build-system cargo-build-system)
+                (arguments
+                 ('quasiquote (#:cargo-inputs
+                               (("rust-docopt"
+                                 ('unquote 'rust-docopt-0.8))))))
+                (home-page "http://example.com")
+                (synopsis "summary")
+                (description "summary")
+                (license (list license:expat license:asl2.0)))))
+            #t)
+          (x
+           (pk 'fail x #f)))))
+
 (test-end "crate")
-- 
2.21.3





Merged 38408 44694. Request was from Hartmut Goebel <h.goebel <at> crazy-compilers.com> to control <at> debbugs.gnu.org. (Mon, 16 Nov 2020 19:20:01 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#44694; Package guix-patches. (Wed, 02 Dec 2020 21:14:01 GMT) Full text and rfc822 format available.

Message #13 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
To: guix-patches <at> gnu.org, 38408-close <at> debbugs.gnu.org
Cc: Martin Becze <mjbecze <at> riseup.net>
Subject: Re: [PATCH v17 0/8] New take continued: Semantic version aware
 recursive
Date: Wed, 2 Dec 2020 22:13:43 +0100
Finally pished as 054e308f5d85ca96327861a577d69c6e18fdc9dc

Thanks for everybody contributing.

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel <at> crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |





bug marked as fixed in version 44560, send any further explanations to 38408 <at> debbugs.gnu.org and Martin Becze <mjbecze <at> riseup.net> Request was from Hartmut Goebel <h.goebel <at> crazy-compilers.com> to control <at> debbugs.gnu.org. (Sat, 12 Dec 2020 11:03:02 GMT) Full text and rfc822 format available.

Merged 38408 44560 44694. Request was from Hartmut Goebel <h.goebel <at> crazy-compilers.com> to control <at> debbugs.gnu.org. (Sat, 12 Dec 2020 11:09:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 09 Jan 2021 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 179 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.