GNU bug report logs - #37928
Better handle license expressions in 'guix import crate'

Previous Next

Package: guix-patches;

Reported by: Brice Waegeneire <brice <at> waegenei.re>

Date: Fri, 25 Oct 2019 20:28:02 UTC

Severity: normal

Tags: patch

Merged with 37927

Done: Ludovic Courtès <ludo <at> gnu.org>

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 37928 in the body.
You can then email your comments to 37928 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#37928; Package guix-patches. (Fri, 25 Oct 2019 20:28:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Brice Waegeneire <brice <at> waegenei.re>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 25 Oct 2019 20:28:02 GMT) Full text and rfc822 format available.

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

From: Brice Waegeneire <brice <at> waegenei.re>
To: guix-patches <at> gnu.org
Subject: [PATCH] import: crate: Fix licenses.
Date: Fri, 25 Oct 2019 22:27:13 +0200
* guix/import/crate.scm (%dual-license-rx): Removed function.
(crate->guix-package): Handle most of the multi-licensing cases.
---
 guix/import/crate.scm | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 8dc014d232..e08028db15 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -178,21 +178,18 @@ and 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->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))))))
+    (filter
+     (lambda (word)
+       (and (not (string-null? word))
+            (not (any (lambda (elem) (string=? elem word))
+                      '("AND" "OR" "WITH"))) ))
+     (string-split string (string->char-set " /"))))
 
   (define (normal-dependency? dependency)
     (eq? (crate-dependency-kind dependency) 'normal))
-- 
2.19.2





Merged 37927 37928. Request was from Mathieu Othacehe <m.othacehe <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 28 Oct 2019 14:41:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#37928; Package guix-patches. (Mon, 04 Nov 2019 22:28:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Brice Waegeneire <brice <at> waegenei.re>
Cc: 37927 <at> debbugs.gnu.org, 37928 <at> debbugs.gnu.org
Subject: Re: [bug#37928] [PATCH] import: crate: Fix licenses.
Date: Mon, 04 Nov 2019 23:27:24 +0100
Hi Brice,

Brice Waegeneire <brice <at> waegenei.re> skribis:

> * guix/import/crate.scm (%dual-license-rx): Removed function.
> (crate->guix-package): Handle most of the multi-licensing cases.

Nice!

>  (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))))))
> +    (filter
> +     (lambda (word)
> +       (and (not (string-null? word))
> +            (not (any (lambda (elem) (string=? elem word))
> +                      '("AND" "OR" "WITH"))) ))
> +     (string-split string (string->char-set " /"))))

It would be great to have tests for that in tests/crate.scm.  To that
end, I think you could lift ‘string->license’ to the top level (that is,
outside ‘crate->guix-package’), and then have a few tests along these
lines:

  (define string->license
    (@@ (guix import crate) string->license))

  (test-equal "GPL OR LGPL"
    (list license:gpl3+ license:lgpl3+)
    (string->license "GPL OR LGPL"))

(See
<https://guix.gnu.org/manual/en/html_node/Running-the-Test-Suite.html>.)

Let me know if anything is unclear.

Could you send an updated patch?

Thanks,
Ludo’.




Changed bug title to 'Better handle license expressions in 'guix import crate'' from '[PATCH] import: crate: Fix licenses.' Request was from Ludovic Courtès <ludo <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 04 Nov 2019 22:29:05 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#37928; Package guix-patches. (Tue, 26 Nov 2019 20:18:01 GMT) Full text and rfc822 format available.

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

From: Brice Waegeneire <brice <at> waegenei.re>
To: 37928 <at> debbugs.gnu.org
Date: Tue, 26 Nov 2019 21:17:20 +0100
I have finally managed to write the requested tests.

string->license has been rewritten to output licenses instead of strings and to avoid swallowing unknown licenses. Now, importing rpigrep recursively give only 3 #f in the licenses fields.





Information forwarded to guix-patches <at> gnu.org:
bug#37928; Package guix-patches. (Tue, 26 Nov 2019 20:18:02 GMT) Full text and rfc822 format available.

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

From: Brice Waegeneire <brice <at> waegenei.re>
To: 37928 <at> debbugs.gnu.org
Subject: [PATCH v2] import: crate: Better handle license expressions.
Date: Tue, 26 Nov 2019 21:17:21 +0100
* guix/import/crate.scm (%dual-license-rx): Removed function.
(crate->guix-package): Handle most of the multi-licensing cases.
* tests/crate.scm (licenses): Add tests for some licenses.
---
 guix/import/crate.scm | 17 ++++++++---------
 tests/crate.scm       | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 8dc014d232..0915d8295a 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -178,21 +178,20 @@ and 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 (string->license string)
+    (map
+     spdx-string->license
+     (filter (lambda (license)
+               (and (not (string-null? license))
+                   (not (any (lambda (elem) (string=? elem license))
+                             '("AND" "OR" "WITH")))))
+            (string-split string (string->char-set " /")))))
 
 (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))
diff --git a/tests/crate.scm b/tests/crate.scm
index c14862ad9f..baad2d0c44 100644
--- a/tests/crate.scm
+++ b/tests/crate.scm
@@ -63,6 +63,9 @@
 (define test-source-hash
   "")
 
+(define string->license
+  (@@ (guix import crate) string->license))
+
 (test-begin "crate")
 
 (test-equal "guix-package->crate-name"
@@ -111,4 +114,24 @@
       (x
        (pk 'fail x #f)))))
 
+(test-equal "licenses: MIT OR Apache-2.0"
+  '(license:expat license:asl2.0)
+  (string->license "MIT OR Apache-2.0"))
+
+(test-equal "licenses: Apache-2.0 / MIT"
+  '(license:asl2.0 license:expat)
+  (string->license "Apache-2.0 / MIT"))
+
+(test-equal "licenses: Apache-2.0 WITH LLVM-exception"
+  '(license:asl2.0 #f)
+  (string->license "Apache-2.0 WITH LLVM-exception"))
+
+(test-equal "licenses: MIT/Apache-2.0 AND BSD-2-Clause"
+  '(license:expat license:asl2.0 #f)
+  (string->license "MIT/Apache-2.0 AND BSD-2-Clause"))
+
+(test-equal "licenses: MIT/Apache-2.0"
+  '(license:expat license:asl2.0)
+  (string->license "MIT/Apache-2.0"))
+
 (test-end "crate")
-- 
2.19.2





Information forwarded to guix-patches <at> gnu.org:
bug#37928; Package guix-patches. (Wed, 11 Dec 2019 13:02:04 GMT) Full text and rfc822 format available.

Message #21 received at 37928-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Brice Waegeneire <brice <at> waegenei.re>
Cc: 37927-done <at> debbugs.gnu.org, 37928-done <at> debbugs.gnu.org
Subject: Re: [bug#37928] [PATCH v2] import: crate: Better handle license
 expressions.
Date: Wed, 11 Dec 2019 12:24:04 +0100
Hi Brice,

Brice Waegeneire <brice <at> waegenei.re> skribis:

> * guix/import/crate.scm (%dual-license-rx): Removed function.
> (crate->guix-package): Handle most of the multi-licensing cases.
> * tests/crate.scm (licenses): Add tests for some licenses.

Thanks for the updated patch!

> +(define (string->license string)
> +    (map
> +     spdx-string->license
> +     (filter (lambda (license)
> +               (and (not (string-null? license))
> +                   (not (any (lambda (elem) (string=? elem license))
> +                             '("AND" "OR" "WITH")))))
> +            (string-split string (string->char-set " /")))))

I changed that to use ‘filter-map’ instead and pushed as
263a267b75e472cb84428571580dabd99d5dff0c.

Thanks!

Ludo’.




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

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

Previous Next


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