Message ID | 20191025202713.7739-2-brice@waegenei.re |
---|---|
State | Accepted |
Headers | show |
Series | [bug#37928] import: crate: Fix licenses. | expand |
Hi Brice, Brice Waegeneire <brice@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’.
Hi Brice, Did you have a chance to look into this? (See <https://issues.guix.gnu.org/issue/37927> for context.) Thanks in advance. :-) Ludo’. Ludovic Courtès <ludo@gnu.org> skribis: > Hi Brice, > > Brice Waegeneire <brice@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’.
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.
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))