all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Craven <david@craven.ch>
To: guix-devel@gnu.org
Subject: [PATCH 05/12] import: utils: Refactor license->symbol.
Date: Thu, 22 Sep 2016 15:18:56 +0200	[thread overview]
Message-ID: <20160922131903.1606-5-david@craven.ch> (raw)
In-Reply-To: <20160922131903.1606-1-david@craven.ch>

* guix/import/utils.scm (license->symbol): Work for all licenses.
* tests/import-utils.scm (license->symbol): Add test.
---
 guix/import/utils.scm  | 14 +++++---------
 tests/import-utils.scm |  5 +++++
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index ca00baf..8dab72a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
 ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
 ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
+;;; Copyright © 2016 David Craven <david@craven.ch>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -178,15 +179,10 @@ recursively apply the procedure to the sub-list."
 (define (license->symbol license)
   "Convert license to a symbol representing the variable the object is bound
 to in the (guix licenses) module, or #f if there is no such known license."
-  ;; TODO: Traverse list public variables in (guix licenses) instead so we
-  ;; don't have to maintain a list manualy.
-  (assoc-ref `((,license:lgpl2.0 . license:lgpl2.0)
-               (,license:gpl3 . license:gpl3)
-               (,license:bsd-3 . license:bsd-3)
-               (,license:expat . license:expat)
-               (,license:public-domain . license:public-domain)
-               (,license:asl2.0 . license:asl2.0))
-             license))
+  (define licenses
+    (module-map (lambda (sym var) `(,(variable-ref var) . ,sym))
+                (resolve-interface '(guix licenses) #:prefix 'license:)))
+  (assoc-ref licenses license))
 
 (define (snake-case str)
   "Return a downcased version of the string STR where underscores are replaced
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 3b11875..8d44b9e 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -20,6 +20,7 @@
 (define-module (test-import-utils)
   #:use-module (guix tests)
   #:use-module (guix import utils)
+  #:use-module ((guix licenses) #:prefix license:)
   #:use-module (srfi srfi-64))
 
 (test-begin "import-utils")
@@ -33,4 +34,8 @@
   "This package provides a function to establish world peace"
   (beautify-description "A function to establish world peace"))
 
+(test-equal "license->symbol"
+  'license:lgpl2.0
+  (license->symbol license:lgpl2.0))
+
 (test-end "import-utils")
-- 
2.9.0

  parent reply	other threads:[~2016-09-22 13:20 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-22 13:18 [PATCH 01/12] import: Move json-fetch to (guix import utils) David Craven
2016-09-22 13:18 ` [PATCH 02/12] import: Reorder imports in " David Craven
2016-09-26  9:31   ` Ludovic Courtès
2016-09-22 13:18 ` [PATCH 03/12] import: Move string->license to importers David Craven
2016-09-26  9:32   ` Ludovic Courtès
2016-09-22 13:18 ` [PATCH 04/12] import: utils: Add spdx-string->license David Craven
2016-09-22 14:56   ` Eric Bavier
2016-09-22 15:15     ` David Craven
2016-09-26  9:33   ` Ludovic Courtès
2016-09-22 13:18 ` David Craven [this message]
2016-09-26  9:39   ` [PATCH 05/12] import: utils: Refactor license->symbol Ludovic Courtès
2016-09-22 13:18 ` [PATCH 06/12] import: Add importer for rust crates David Craven
2016-09-26 10:02   ` Ludovic Courtès
2016-09-22 13:18 ` [PATCH 07/12] import: crate: Add crate updater David Craven
2016-09-26 10:09   ` Ludovic Courtès
2016-09-22 13:18 ` [PATCH 08/12] build-system: Add cargo build system David Craven
2016-09-26 10:17   ` Ludovic Courtès
2016-09-26 18:01     ` David Craven
2016-09-30 12:13       ` Ludovic Courtès
2016-09-22 13:19 ` [PATCH 09/12] gnu: Add rust-bootstrap-x86_64-1.12.0 David Craven
2016-09-26 10:18   ` Ludovic Courtès
2016-09-22 13:19 ` [PATCH 10/12] gnu: Add rustc-bootstrap David Craven
2016-09-26 10:24   ` Ludovic Courtès
2016-09-22 13:19 ` [PATCH 11/12] gnu: Add cargo-bootstrap David Craven
2016-09-26 10:28   ` Ludovic Courtès
2016-09-22 13:19 ` [PATCH 12/12] gnu: Add rust helper functions David Craven
2016-09-26 10:29   ` Ludovic Courtès
2016-09-22 14:58 ` [PATCH 01/12] import: Move json-fetch to (guix import utils) Eric Bavier
2016-09-22 15:23   ` David Craven
2016-09-22 16:52     ` Eric Bavier
2016-09-22 16:56       ` David Craven
2016-09-24  5:20         ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160922131903.1606-5-david@craven.ch \
    --to=david@craven.ch \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.