From 3df47231e6c632aadcd7b103bb5b399a8d29772d Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Wed, 4 Sep 2013 18:04:15 +0200 Subject: guix: python: Switch to python-wrapper as the default version for the python build system (switches to Python 3) and compute python-version instead of passing it as a parameter. * guix/build-system/python.scm (default-python): Switch to python-wrapper. * guix/build-system/python.scm (python-build): Drop parameter #:python-version. * guix/build/python-build-system.scm (wrap): Compute python version from input. --- guix/build-system/python.scm | 6 ++---- guix/build/python-build-system.scm | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'guix') diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm index b60adb182f..7ac93b296b 100644 --- a/guix/build-system/python.scm +++ b/guix/build-system/python.scm @@ -39,13 +39,11 @@ "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* (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) @@ -62,6 +60,7 @@ (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))) @@ -78,7 +77,6 @@ provides a 'setup.py' file as its build system." #:test-target "test" #:tests? ,tests? #: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..04c223bb85 100644 --- a/guix/build/python-build-system.scm +++ b/guix/build/python-build-system.scm @@ -53,7 +53,7 @@ (zero? (apply system* "python" args))) (error "no setup.py found"))) -(define* (wrap #:key outputs python-version #:allow-other-keys) +(define* (wrap #:key inputs outputs #:allow-other-keys) (define (list-of-files dir) (map (cut string-append dir "/" <>) (or (scandir dir (lambda (f) @@ -69,6 +69,8 @@ outputs)) (let* ((out (assoc-ref outputs "out")) + (python (assoc-ref inputs "python")) + (python-version (string-take (string-take-right python 5) 3)) (var `("PYTHONPATH" prefix ,(cons (string-append out "/lib/python" python-version "/site-packages") -- cgit v1.2.3 From 7b96bf82daf25699ce6b4f4cb2ced1e5318b576f Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Thu, 5 Sep 2013 18:43:18 +0200 Subject: gnu: python: Honour #:tests? and #:test-target in build system. * guix/build/python-build-system.scm (check): Use named parameters tests? and test-target (default now: "test" instead of "check"). --- guix/build/python-build-system.scm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'guix') diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm index 04c223bb85..27818526fa 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 +;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2013 Nikita Karetnikov ;;; ;;; This file is part of GNU Guix. @@ -45,13 +46,15 @@ (zero? (apply system* "python" args))) (error "no setup.py found")))) -(define* (check #:key outputs #:allow-other-keys) +(define* (check #:key outputs tests? test-target #:allow-other-keys) "Run the test suite of a given Python package." - (if (file-exists? "setup.py") - (let ((args `("setup.py" "check"))) - (format #t "running 'python' with arguments ~s~%" args) - (zero? (apply system* "python" args))) - (error "no setup.py found"))) + (if tests? + (if (file-exists? "setup.py") + (let ((args `("setup.py" ,test-target))) + (format #t "running 'python' with arguments ~s~%" args) + (zero? (apply system* "python" args))) + (error "no setup.py found")) + #t)) (define* (wrap #:key inputs outputs #:allow-other-keys) (define (list-of-files dir) -- cgit v1.2.3 From b191f88ee34576a6908b9b5e94cb7664e88c7e79 Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Thu, 5 Sep 2013 20:25:08 +0200 Subject: guix: python: Add build phase and factor out calls to setup.py. * guix/build/python-build-system.scm (call-setuppy): New procedure. * guix/build/python-build-system.scm (build): New procedure. * guix/build/python-build-system.scm (check, install): Use call-setuppy. * guix/build/python-build-system.scm (%standard-phases): Add call to build. --- guix/build/python-build-system.scm | 49 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'guix') diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm index 27818526fa..f213a97f01 100644 --- a/guix/build/python-build-system.scm +++ b/guix/build/python-build-system.scm @@ -35,27 +35,33 @@ ;; ;; 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 tests? test-target #:allow-other-keys) +(define (call-setuppy command params) + (if (file-exists? "setup.py") + (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* (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? - (if (file-exists? "setup.py") - (let ((args `("setup.py" ,test-target))) - (format #t "running 'python' with arguments ~s~%" args) - (zero? (apply system* "python" args))) - (error "no setup.py found")) + (call-setuppy test-target '()) #t)) +(define* (install #:key outputs (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))) + (call-setuppy "install" params))) + (define* (wrap #:key inputs outputs #:allow-other-keys) (define (list-of-files dir) (map (cut string-append dir "/" <>) @@ -92,11 +98,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) -- cgit v1.2.3 From 11bb85a10d4a84dab7fdfaaaf7012b743ce7a09f Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Sun, 8 Sep 2013 16:57:37 +0200 Subject: 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. --- gnu/packages/python.scm | 11 +++------ guix/build-system/python.scm | 54 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 9 deletions(-) (limited to 'guix') 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 +;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2013 Nikita Karetnikov ;;; ;;; 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)) -- cgit v1.2.3 From 1d1f939798d2649bbabc962e37f90efe5805e202 Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Tue, 10 Sep 2013 11:42:07 +0200 Subject: guix: python: Add parameter #:phases to build system. * guix/build-system/python.scm (python-build): Use parameter #:phases. --- guix/build-system/python.scm | 1 + 1 file changed, 1 insertion(+) (limited to 'guix') diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm index d120cc9cc3..d018ee70f3 100644 --- a/guix/build-system/python.scm +++ b/guix/build-system/python.scm @@ -128,6 +128,7 @@ provides a 'setup.py' file as its build system." #:system ,system #:test-target "test" #:tests? ,tests? + #:phases ,phases #:outputs %outputs #:search-paths ',(map search-path-specification->sexp (append python-search-paths -- cgit v1.2.3 From e1a264f6fac2f517a2192e07eaae1db600eb8b1d Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Tue, 10 Sep 2013 20:32:50 +0200 Subject: guix: python: Do not import %standard-phases from gnu-build-system. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build-system/python.scm (python-build): Drop module gnu-build-system. Thanks to Ludovic Courtès . --- guix/build-system/python.scm | 1 - 1 file changed, 1 deletion(-) (limited to 'guix') diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm index d018ee70f3..03e587ba01 100644 --- a/guix/build-system/python.scm +++ b/guix/build-system/python.scm @@ -108,7 +108,6 @@ prepended to the name." (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." -- cgit v1.2.3 From 824af8cadc1b4f1ac7a859f3d18cbe69b195a844 Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Wed, 11 Sep 2013 15:47:34 +0200 Subject: guix: python: Create module installation path and add it to PYTHONPATH during the installation phase. * guix/build/python-build-system.scm (get-python-version): New procedure. * guix/build/python-build-system.scm (install): Create and add path. * gnu/packages/python.scm (python-setuptools): Drop path creation code. --- gnu/packages/python.scm | 16 +--------------- guix/build/python-build-system.scm | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'guix') diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 8f65852630..55d23e45e8 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -262,25 +262,11 @@ etc. ") "0hl9sa5xr9bi2ifq51wy1bawsjv5nzvpbac7m9z1ciz778874csf")))) (build-system python-build-system) (arguments - `(#:tests? #f + `(#:tests? #f)) ;;FIXME: test_sdist_with_utf8_encoded_filename fails in ;; /tmp/nix-build-python2-setuptools-1.1.4.drv-0/setuptools-1.1.4/setuptools/tests/test_sdist.py" ;; line 354 ;; The tests pass with Python 2.7.5. - #:phases - (alist-replace - 'install - (lambda* (#:key outputs #:allow-other-keys #:rest args) - (let* ((install (assoc-ref %standard-phases 'install)) - (out (assoc-ref outputs "out")) - (python (assoc-ref %build-inputs "python")) - (python-version (string-take (string-take-right python 5) 3)) - (path (string-append out "/lib/python" python-version - "/site-packages/"))) - (mkdir-p path) - (setenv "PYTHONPATH" path) - (apply install args))) - %standard-phases))) (home-page "https://pypi.python.org/pypi/setuptools") (synopsis "Library designed to facilitate packaging Python projects") diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm index f213a97f01..0bb8c4d49d 100644 --- a/guix/build/python-build-system.scm +++ b/guix/build/python-build-system.scm @@ -54,12 +54,27 @@ (call-setuppy test-target '()) #t)) -(define* (install #:key outputs (configure-flags '()) +(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))) + 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) @@ -79,10 +94,10 @@ (let* ((out (assoc-ref outputs "out")) (python (assoc-ref inputs "python")) - (python-version (string-take (string-take-right python 5) 3)) (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) -- cgit v1.2.3