aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-08-16 21:09:19 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-08-27 18:02:35 -0400
commit140b3048155d8fe4b8598786c014139ac5a91706 (patch)
tree9e07f54e4ab718976c1d65602b622accfe5e0a7f
parentf8da3af08655acf2bb016e3a84bcba9b16e667ff (diff)
downloadguix-140b3048155d8fe4b8598786c014139ac5a91706.tar
guix-140b3048155d8fe4b8598786c014139ac5a91706.tar.gz
import: pypi: Move generally useful procedures to utils module.
* guix/import/pypi.scm (make-pypi-sexp): Factorize license to symbol conversion code. (string->license, snake-case, guix-hash-url): Move from here... * guix/import/utils.scm: ... to here. (license->symbol): New procedure.
-rw-r--r--guix/import/pypi.scm29
-rw-r--r--guix/import/utils.scm43
2 files changed, 43 insertions, 29 deletions
diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm
index 10d5bad017..06d21fea45 100644
--- a/guix/import/pypi.scm
+++ b/guix/import/pypi.scm
@@ -31,8 +31,6 @@
#:use-module (guix utils)
#:use-module (guix import utils)
#:use-module (guix import json)
- #:use-module (guix base32)
- #:use-module (guix hash)
#:use-module (guix packages)
#:use-module (guix licenses)
#:use-module (guix build-system python)
@@ -49,16 +47,6 @@ DELIMETER."
((elem . rest)
(cons* elem delimiter (join rest delimiter)))))
-(define string->license
- (match-lambda
- ("GNU LGPL" lgpl2.0)
- ("GPL" gpl3)
- ((or "BSD" "BSD License") bsd-3)
- ((or "MIT" "MIT license" "Expat license") expat)
- ("Public domain" public-domain)
- ("Apache License, Version 2.0" asl2.0)
- (_ #f)))
-
(define (pypi-fetch name)
"Return an alist representation of the PyPI metadata for the package NAME,
or #f on failure."
@@ -75,15 +63,6 @@ or #f on failure."
(assoc-ref* pypi-package "info" "name")
(assoc-ref* pypi-package "info" "version")))))
-(define (snake-case str)
- "Return a downcased version of the string STR where underscores are replaced
-with dashes."
- (string-join (string-split (string-downcase str) #\_) "-"))
-
-(define (guix-hash-url filename)
- "Return the hash of FILENAME in nix-base32 format."
- (bytevector->nix-base32-string (file-sha256 filename)))
-
(define (python->package-name name)
"Given the NAME of a package on PyPI, return a Guix-compliant name for the
package."
@@ -205,13 +184,7 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(home-page ,home-page)
(synopsis ,synopsis)
(description ,description)
- (license ,(assoc-ref `((,lgpl2.0 . lgpl2.0)
- (,gpl3 . gpl3)
- (,bsd-3 . bsd-3)
- (,expat . expat)
- (,public-domain . public-domain)
- (,asl2.0 . asl2.0))
- license)))))))
+ (license ,(license->symbol license)))))))
(define (pypi->guix-package package-name)
"Fetch the metadata for PACKAGE-NAME from pypi.python.org, and return the
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 969491d28d..0734fa1230 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -21,6 +21,8 @@
#:use-module (ice-9 regex)
#:use-module (srfi srfi-1)
#:use-module (guix hash)
+ #:use-module (guix base32)
+ #:use-module (guix licenses)
#:use-module (guix utils)
#:use-module ((guix build download) #:prefix build:)
#:export (factorize-uri
@@ -29,7 +31,13 @@
flatten
assoc-ref*
- url-fetch))
+ url-fetch
+ guix-hash-url
+
+ string->license
+ license->symbol
+
+ snake-case))
(define (factorize-uri uri version)
"Factorize URI, a package tarball URI as a string, such that any occurrences
@@ -95,3 +103,36 @@ recursively apply the procedure to the sub-list."
"Save the contents of URL to FILE-NAME. Return #f on failure."
(parameterize ((current-output-port (current-error-port)))
(build:url-fetch url file-name)))
+
+(define (guix-hash-url filename)
+ "Return the hash of FILENAME in nix-base32 format."
+ (bytevector->nix-base32-string (file-sha256 filename)))
+
+(define (string->license str)
+ "Convert the string STR into a license object."
+ (match str
+ ("GNU LGPL" lgpl2.0)
+ ("GPL" gpl3)
+ ((or "BSD" "BSD License") bsd-3)
+ ((or "MIT" "MIT license" "Expat license") expat)
+ ("Public domain" public-domain)
+ ((or "Apache License, Version 2.0" "Apache 2.0") asl2.0)
+ (_ #f)))
+
+(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 `((,lgpl2.0 . lgpl2.0)
+ (,gpl3 . gpl3)
+ (,bsd-3 . bsd-3)
+ (,expat . expat)
+ (,public-domain . public-domain)
+ (,asl2.0 . asl2.0))
+ license))
+
+(define (snake-case str)
+ "Return a downcased version of the string STR where underscores are replaced
+with dashes."
+ (string-join (string-split (string-downcase str) #\_) "-"))