aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Enge <andreas@enge.fr>2013-09-08 16:57:37 +0200
committerAndreas Enge <andreas@enge.fr>2013-09-08 16:57:37 +0200
commit11bb85a10d4a84dab7fdfaaaf7012b743ce7a09f (patch)
tree27f51d1c065139ed94d00b23709205744af82918
parentb191f88ee34576a6908b9b5e94cb7664e88c7e79 (diff)
downloadgnu-guix-11bb85a10d4a84dab7fdfaaaf7012b743ce7a09f.tar
gnu-guix-11bb85a10d4a84dab7fdfaaaf7012b743ce7a09f.tar.gz
guix: python: Add package-with-python2, a procedure rewriting a package
to compile with Python 2 instead of the default Python 3. * guix/build-system/python.scm (default-python2, package-with-explicit-python, package-with-python2): New procedures. * guix/build-system/python.scm (python2-pytz, python2-babel): Use package-with-python2.
-rw-r--r--gnu/packages/python.scm11
-rw-r--r--guix/build-system/python.scm54
2 files changed, 56 insertions, 9 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index ce89281e26..3ff4da2149 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -28,6 +28,7 @@
#:use-module (gnu packages patchelf)
#:use-module (guix packages)
#:use-module (guix download)
+ #:use-module (guix utils)
#:use-module (guix build-system gnu)
#:use-module (guix build-system python)
#:use-module (guix build-system trivial))
@@ -215,9 +216,7 @@ using Python 2.4 or higher and provides access to the Olson timezone database.")
(license x11)))
(define-public python2-pytz
- (package (inherit python-pytz)
- (name "python2-pytz")
- (arguments (append (package-arguments python-pytz) `(#:python ,python-2)))))
+ (package-with-python2 python-pytz))
(define-public python-babel
(package
@@ -247,8 +246,4 @@ etc. ")
(license bsd-3)))
(define-public python2-babel
- (package (inherit python-babel)
- (name "python2-babel")
- (inputs
- `(("python2-pytz" ,python2-pytz)))
- (arguments (append (package-arguments python-babel) `(#:python ,python-2)))))
+ (package-with-python2 python-babel))
diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index 7ac93b296b..d120cc9cc3 100644
--- a/guix/build-system/python.scm
+++ b/guix/build-system/python.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;;
;;; This file is part of GNU Guix.
@@ -25,7 +26,9 @@
#:use-module (guix build-system)
#:use-module (guix build-system gnu)
#:use-module (ice-9 match)
- #:export (python-build
+ #:use-module (srfi srfi-26)
+ #:export (package-with-python2
+ python-build
python-build-system))
;; Commentary:
@@ -41,6 +44,55 @@
(let ((python (resolve-interface '(gnu packages python))))
(module-ref python 'python-wrapper)))
+(define (default-python2)
+ "Return the default Python 2 package."
+ (let ((python (resolve-interface '(gnu packages python))))
+ (module-ref python 'python-2)))
+
+(define (package-with-explicit-python p python old-prefix new-prefix)
+ "Create a package with the same fields as P, which is assumed to use
+PYTHON-BUILD-SYSTEM, such that it is compiled with PYTHON instead. The
+inputs are changed recursively accordingly. If the name of P starts with
+OLD-PREFIX, this is replaced by NEW-PREFIX; otherwise, NEW-PREFIX is
+prepended to the name."
+ (let* ((build-system (package-build-system p))
+ (rewrite-if-package
+ (lambda (content)
+ ;; CONTENT may be a string (e.g., for patches), in which case it
+ ;; is returned, or a package, which is rewritten with the new
+ ;; PYTHON and NEW-PREFIX.
+ (if (package? content)
+ (package-with-explicit-python content python
+ old-prefix new-prefix)
+ content)))
+ (rewrite
+ (match-lambda
+ ((name content . rest)
+ (append (list name (rewrite-if-package content)) rest)))))
+ (package (inherit p)
+ (name
+ (let ((name (package-name p)))
+ (if (eq? build-system python-build-system)
+ (string-append new-prefix
+ (if (string-prefix? old-prefix name)
+ (substring name (string-length old-prefix))
+ name))
+ name)))
+ (arguments
+ (let ((arguments (package-arguments p)))
+ (if (eq? build-system python-build-system)
+ (if (member #:python arguments)
+ (substitute-keyword-arguments arguments ((#:python p) python))
+ (append arguments `(#:python ,python)))
+ arguments)))
+ (inputs
+ (map rewrite (package-inputs p)))
+ (native-inputs
+ (map rewrite (package-native-inputs p))))))
+
+(define package-with-python2
+ (cut package-with-explicit-python <> (default-python2) "python-" "python2-"))
+
(define* (python-build store name source inputs
#:key
(python (default-python))