diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm index 17173f121..a05fd5a79 100644 --- a/guix/build-system/python.scm +++ b/guix/build-system/python.scm @@ -153,7 +153,7 @@ pre-defined variants." #:rest arguments) "Return a bag for NAME." (define private-keywords - '(#:source #:target #:python #:inputs #:native-inputs)) + '(#:source #:target #:python #:inputs)) (and (not target) ;XXX: no cross-compilation (bag @@ -174,6 +174,9 @@ pre-defined variants." (define* (python-build store name inputs #:key + (native-inputs '()) + ;; TODO: Something like this: + ;; (disallowed-references native-inputs) (tests? #t) (test-target "test") (use-setuptools? #t) @@ -189,17 +192,24 @@ pre-defined variants." (guix build utils)))) "Build SOURCE using PYTHON, and with INPUTS. This assumes that SOURCE provides a 'setup.py' file as its build system." + (define canonicalize-reference + (match-lambda + (((? derivation? source)) + (derivation->output-path source)) + (((? package? package)) + (derivation->output-path + (package-derivation store package system))) + ((source) + source) + (source + source))) + (define builder `(begin (use-modules ,@modules) (python-build #:name ,name - #:source ,(match (assoc-ref inputs "source") - (((? derivation? source)) - (derivation->output-path source)) - ((source) - source) - (source - source)) + #:source ,(canonicalize-reference + (assoc-ref inputs "source")) #:configure-flags ,configure-flags #:system ,system #:test-target ,test-target @@ -209,7 +219,17 @@ provides a 'setup.py' file as its build system." #:outputs %outputs #:search-paths ',(map search-path-specification->sexp search-paths) - #:inputs %build-inputs))) + #:inputs %build-inputs + + ;; We call them "native inputs" but there's no + ;; cross-compilation here, so that really means + ;; "build-time-only" inputs, things should not be + ;; run-time dependencies. + #:native-inputs ',(map (match-lambda + ((name . rest) + `(,name + . ,(canonicalize-reference rest)))) + native-inputs)))) (define guile-for-build (match guile @@ -222,6 +242,8 @@ provides a 'setup.py' file as its build system." (build-expression->derivation store name builder #:inputs inputs + ;; TODO: + ;; #:disallowed-references disallowed-references #:system system #:modules imported-modules #:outputs outputs diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm index dd07986b9..1ca26104b 100644 --- a/guix/build/python-build-system.scm +++ b/guix/build/python-build-system.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2015, 2016 Ludovic Courtès +;;; Copyright © 2013, 2015, 2016, 2017 Ludovic Courtès ;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2015 Mark H Weaver @@ -184,7 +184,7 @@ when running checks after installing the package." configure-flags))) (call-setuppy "install" params use-setuptools?))) -(define* (wrap #:key inputs outputs #:allow-other-keys) +(define* (wrap #:key native-inputs inputs outputs #:allow-other-keys) (define (list-of-files dir) (map (cut string-append dir "/" <>) (or (scandir dir (lambda (f) @@ -199,14 +199,27 @@ when running checks after installing the package." (string-append dir "/sbin")))) outputs)) + (define build-time-inputs + ;; Built-time-only dependencies. + (match native-inputs + (((names . directories) ...) + directories))) + + (define (build-time-dependency? item) + (any (cut string-prefix? <> item) + build-time-inputs)) + + ;; Wrap binaries such that PYTHONPATH is set appropriately, but remove + ;; build-time-only dependencies (aka. #:native-inputs) from the search path. (let* ((out (assoc-ref outputs "out")) (python (assoc-ref inputs "python")) + (path (search-path-as-string->list + (or (getenv "PYTHONPATH") ""))) (var `("PYTHONPATH" prefix ,(cons (string-append out "/lib/python" (get-python-version python) "/site-packages") - (search-path-as-string->list - (or (getenv "PYTHONPATH") "")))))) + (remove build-time-dependency? path))))) (for-each (lambda (dir) (let ((files (list-of-files dir))) (for-each (cut wrap-program <> var)