Better handle license expressions in 'guix import crate'

DoneSubmitted by Brice Waegeneire.
Details
3 participants
  • Brice Waegeneire
  • Ludovic Courtès
  • Mathieu Othacehe
Owner
unassigned
Severity
normal
Merged with
B
B
Brice Waegeneire wrote on 25 Oct 2019 22:27
[PATCH] import: crate: Fix licenses.
(address . guix-patches@gnu.org)
20191025202713.7739-2-brice@waegenei.re
* 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(-)
Toggle diff (34 lines)diff --git a/guix/import/crate.scm b/guix/import/crate.scmindex 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
M
M
Mathieu Othacehe wrote on 28 Oct 2019 15:40
control message for bug #37927
(address . control@debbugs.gnu.org)
87sgndj5lr.fsf@gmail.com
merge 37927 37928quit
L
L
Ludovic Courtès wrote on 4 Nov 2019 23:27
Re: [bug#37928] [PATCH] import: crate: Fix licenses.
(name . Brice Waegeneire)(address . brice@waegenei.re)
87mudb46r7.fsf@gnu.org
Hi Brice,
Brice Waegeneire <brice@waegenei.re> skribis:
Toggle quote (3 lines)> * guix/import/crate.scm (%dual-license-rx): Removed function.> (crate->guix-package): Handle most of the multi-licensing cases.
Nice!
Toggle quote (17 lines)> (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 thatend, I think you could lift ‘string->license’ to the top level (that is,outside ‘crate->guix-package’), and then have a few tests along theselines:
(define string->license (@@ (guix import crate) string->license))
(test-equal "GPL OR LGPL" (list license:gpl3+ license:lgpl3+) (string->license "GPL OR LGPL"))
(Seehttps://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’.
L
L
Ludovic Courtès wrote on 4 Nov 2019 23:28
control message for bug #37927
(address . control@debbugs.gnu.org)
87lfsv46q6.fsf@gnu.org
retitle 37927 Better handle license expressions in 'guix import crate'quit
B
B
Brice Waegeneire wrote on 26 Nov 2019 21:17
(address . 37928@debbugs.gnu.org)
20191126201721.7370-1-brice@waegenei.re
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.
B
B
Brice Waegeneire wrote on 26 Nov 2019 21:17
(address . 37928@debbugs.gnu.org)
20191126201721.7370-2-brice@waegenei.re
* 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(-)
Toggle diff (75 lines)diff --git a/guix/import/crate.scm b/guix/import/crate.scmindex 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.scmindex 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
L
L
Ludovic Courtès wrote on 11 Dec 2019 12:24
(name . Brice Waegeneire)(address . brice@waegenei.re)
87tv67jeaz.fsf@gnu.org
Hi Brice,
Brice Waegeneire <brice@waegenei.re> skribis:
Toggle quote (4 lines)> * 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!
Toggle quote (9 lines)> +(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 as263a267b75e472cb84428571580dabd99d5dff0c.
Thanks!
Ludo’.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send email to 37928@debbugs.gnu.org