summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorAndreas Enge <andreas@enge.fr>2013-09-14 10:45:01 +0200
committerAndreas Enge <andreas@enge.fr>2013-09-14 10:45:01 +0200
commitaae4ead8142d4fd7c674a1e6e302f40469f878c6 (patch)
tree022987d73c705ca882e50c8a63b578c658a72de6 /guix
parent29479de5659ba912b486c74078403bbb9a4df104 (diff)
parent2875caf5b52340ea16965b1d8f76342cc07bf8b5 (diff)
downloadgnu-guix-aae4ead8142d4fd7c674a1e6e302f40469f878c6.tar
gnu-guix-aae4ead8142d4fd7c674a1e6e302f40469f878c6.tar.gz
Merge branch 'python'
Diffstat (limited to 'guix')
-rw-r--r--guix/build-system/python.scm62
-rw-r--r--guix/build/python-build-system.scm71
2 files changed, 105 insertions, 28 deletions
diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index b60adb182f..03e587ba01 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:
@@ -39,13 +42,60 @@
"Return the default Python package."
;; Lazily resolve the binding to avoid a circular dependency.
(let ((python (resolve-interface '(gnu packages python))))
- (module-ref python '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))
- (python-version
- (string-take (package-version (default-python)) 3))
(tests? #t)
(configure-flags ''())
(phases '(@ (guix build python-build-system)
@@ -58,10 +108,10 @@
(guix build gnu-build-system)
(guix build utils)))
(modules '((guix build python-build-system)
- (guix build gnu-build-system)
(guix build utils))))
"Build SOURCE using PYTHON, and with INPUTS. This assumes that SOURCE
provides a 'setup.py' file as its build system."
+
(define python-search-paths
(append (package-native-search-paths python)
(standard-search-paths)))
@@ -77,8 +127,8 @@ provides a 'setup.py' file as its build system."
#:system ,system
#:test-target "test"
#:tests? ,tests?
+ #:phases ,phases
#:outputs %outputs
- #:python-version ,python-version
#:search-paths ',(map search-path-specification->sexp
(append python-search-paths
search-paths))
diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm
index 84299798b0..0bb8c4d49d 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.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.
@@ -34,26 +35,49 @@
;;
;; Code:
-(define* (install #:key outputs (configure-flags '())
- #:allow-other-keys)
- "Install a given Python package."
- (let ((out (assoc-ref outputs "out")))
- (if (file-exists? "setup.py")
- (let ((args `("setup.py" "install" ,(string-append "--prefix=" out)
- ,@configure-flags)))
- (format #t "running 'python' with arguments ~s~%" args)
- (zero? (apply system* "python" args)))
- (error "no setup.py found"))))
-(define* (check #:key outputs #:allow-other-keys)
- "Run the test suite of a given Python package."
+(define (call-setuppy command params)
(if (file-exists? "setup.py")
- (let ((args `("setup.py" "check")))
- (format #t "running 'python' with arguments ~s~%" args)
- (zero? (apply system* "python" args)))
+ (begin
+ (format #t "running \"python setup.py\" with command ~s and parameters ~s~%"
+ command params)
+ (zero? (apply system* "python" "setup.py" command params)))
(error "no setup.py found")))
-(define* (wrap #:key outputs python-version #:allow-other-keys)
+(define* (build #:rest empty)
+ "Build a given Python package."
+ (call-setuppy "build" '()))
+
+(define* (check #:key tests? test-target #:allow-other-keys)
+ "Run the test suite of a given Python package."
+ (if tests?
+ (call-setuppy test-target '())
+ #t))
+
+(define (get-python-version python)
+ (string-take (string-take-right python 5) 3))
+
+(define* (install #:key outputs inputs (configure-flags '())
+ #:allow-other-keys)
+ "Install a given Python package."
+ (let* ((out (assoc-ref outputs "out"))
+ (params (append (list (string-append "--prefix=" out))
+ configure-flags))
+ (python-version (get-python-version (assoc-ref inputs "python")))
+ (old-path (getenv "PYTHONPATH"))
+ (add-path (string-append out "/lib/python" python-version
+ "/site-packages/")))
+ ;; create the module installation directory and add it to PYTHONPATH
+ ;; to make setuptools happy
+ (mkdir-p add-path)
+ (setenv "PYTHONPATH"
+ (string-append (if old-path
+ (string-append old-path ":")
+ "")
+ add-path))
+ (call-setuppy "install" params)))
+
+(define* (wrap #:key inputs outputs #:allow-other-keys)
(define (list-of-files dir)
(map (cut string-append dir "/" <>)
(or (scandir dir (lambda (f)
@@ -69,9 +93,11 @@
outputs))
(let* ((out (assoc-ref outputs "out"))
+ (python (assoc-ref inputs "python"))
(var `("PYTHONPATH" prefix
,(cons (string-append out "/lib/python"
- python-version "/site-packages")
+ (get-python-version python)
+ "/site-packages")
(search-path-as-string->list
(or (getenv "PYTHONPATH") ""))))))
(for-each (lambda (dir)
@@ -87,11 +113,12 @@
'install 'wrap
wrap
(alist-replace
- 'check check
- (alist-replace 'install install
- (alist-delete 'configure
- (alist-delete 'build
- gnu:%standard-phases))))))
+ 'build build
+ (alist-replace
+ 'check check
+ (alist-replace 'install install
+ (alist-delete 'configure
+ gnu:%standard-phases))))))
(define* (python-build #:key inputs (phases %standard-phases)
#:allow-other-keys #:rest args)