From 758a4f70fda5758449747e14db1991f6243174b1 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 18 Oct 2022 12:45:15 +0200 Subject: [PATCH 1/3] import/cran: Allow custom license prefix. X-Debbugs-Cc: zimon.toutoune@gmail.com X-Debbugs-Cc: dev@jpoiret.xyz X-Debbugs-Cc: mail@cbaines.net X-Debbugs-Cc: rekado@elephly.net X-Debbugs-Cc: othacehe@gnu.org X-Debbugs-Cc: ludo@gnu.org * guix/import/cran.scm (%license-prefix): New parameter. (string->license): Use it. * guix/scripts/import/cran.scm (%options): Add new parameter -p/--license-prefix. (show-help): Document it. (parse-options): Pass it as a parameter to importer. --- guix/import/cran.scm | 10 +++++++--- guix/scripts/import/cran.scm | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 17e33d5f52..d13231f633 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -55,6 +55,7 @@ (define-module (guix import cran) #:use-module (guix packages) #:use-module (gnu packages) #:export (%input-style + %license-prefix cran->guix-package bioconductor->guix-package @@ -82,6 +83,9 @@ (define-module (guix import cran) (define %input-style (make-parameter 'variable)) ; or 'specification +(define %license-prefix + (make-parameter identity)) + (define (string->licenses license-string) (let ((licenses (map string-trim-both @@ -89,9 +93,9 @@ (define (string->licenses license-string) (char-set-complement (char-set #\|)))))) (string->license licenses))) -(define string->license - (let ((prefix identity)) - (match-lambda +(define (string->license license-string) + (let ((prefix (%license-prefix))) + (match license-string ("AGPL-3" (prefix 'agpl3)) ("AGPL (>= 3)" (prefix 'agpl3+)) ("Artistic-2.0" (prefix 'artistic2.0)) diff --git a/guix/scripts/import/cran.scm b/guix/scripts/import/cran.scm index 2934d4300a..3186bf9248 100644 --- a/guix/scripts/import/cran.scm +++ b/guix/scripts/import/cran.scm @@ -53,6 +53,9 @@ (define (show-help) (display (G_ " -s, --style=STYLE choose output style, either specification or variable")) (display (G_ " + -p, --license-prefix=PREFIX + add custom prefix to licenses, useful for prefixed import of (guix licenses)")) + (display (G_ " -V, --version display version information and exit")) (newline) (show-bug-report-information)) @@ -74,6 +77,10 @@ (define %options (lambda (opt name arg result) (alist-cons 'style (string->symbol arg) (alist-delete 'style result)))) + (option '(#\p "license-prefix") #t #f + (lambda (opt name arg result) + (alist-cons 'license-prefix arg + (alist-delete 'license-prefix result)))) (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'recursive #t result))) @@ -95,8 +102,15 @@ (define (parse-options) (('argument . value) value) (_ #f)) - (reverse opts)))) - (parameterize ((%input-style (assoc-ref opts 'style))) + (reverse opts))) + (prefix (assoc-ref opts 'license-prefix)) + (prefix-proc (if (string? prefix) + (lambda (symbol) + (string->symbol + (string-append prefix (symbol->string symbol)))) + identity))) + (parameterize ((%input-style (assoc-ref opts 'style)) + (%license-prefix prefix-proc)) (match args ((spec) (let ((name version (package-name->name+version spec))) -- 2.37.3