From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Subject: bug#25235: Wrapped python programs get native-inputs in PYTHONPATH Date: Thu, 30 Mar 2017 17:30:25 +0200 Message-ID: <87o9wiwzn2.fsf@gnu.org> References: <87eg13birp.fsf@kirby.i-did-not-set--mail-host-address--so-tickle-me> <87y3zahf8t.fsf@gnu.org> <20161226182608.GA20609@jasmine> <716a63e7.AEQAIoR8aXkAAAAAAAAAAAOwyEEAAAACwQwAAAAAAAW9WABY25oY@mailjet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctc2U-0007pR-Bx for bug-guix@gnu.org; Thu, 30 Mar 2017 11:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctc2Q-0003ym-E9 for bug-guix@gnu.org; Thu, 30 Mar 2017 11:31:06 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:54886) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctc2Q-0003yM-Av for bug-guix@gnu.org; Thu, 30 Mar 2017 11:31:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ctc2Q-0005nw-1z for bug-guix@gnu.org; Thu, 30 Mar 2017 11:31:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <716a63e7.AEQAIoR8aXkAAAAAAAAAAAOwyEEAAAACwQwAAAAAAAW9WABY25oY@mailjet.com> (Arun Isaac's message of "Wed, 29 Mar 2017 16:57:12 +0530") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Arun Isaac Cc: 25235@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Arun Isaac skribis: > I'm working on fixing this bug. I have modified > guix/build/python-build-system.scm for the same. In particular, I have > added #:use-module (guix packages) because I need the functions > `package-name' and `package-transitive-target-inputs'. But, when I try > building any python-build-system package with something like > "./pre-inst-env guix build scons", I get a ("no code for module" (guix > packages)) error. What am I missing? > > Full backtrace follows: [...] > 2954: 4 [define-module* (guix build python-build-system) #:filename ...] > 2929: 3 [resolve-imports ((# # gnu:) (#) (#) (#) ...)] > 2870: 2 [resolve-interface (guix packages) #:select ...] > In unknown file: > ?: 1 [scm-error misc-error #f "~A ~S" ("no code for module" (guix pack= ages)) #f] =E2=80=9CBuild-side=E2=80=9D modules, which typically live in (guix build = =E2=80=A6), should not depend on =E2=80=9Chost-side=E2=80=9D modules such as (guix packages). Tha= t=E2=80=99s because if we did that, we=E2=80=99d effectively end up importing all of Guix on the build side, but then we=E2=80=99d also have to serialize data structures su= ch as packages to pass them from one side to the other. (I hope this makes sense to you, but if it doesn=E2=80=99t maybe the intro of can shed some light.) So in short, we cannot use =E2=80=98package-name=E2=80=99 and =E2=80=98package-transitive-target-inputs=E2=80=99 in this module. (Time passes=E2=80=A6) I wasn=E2=80=99t sure how to fix this bug myself so I gave it a try and end= ed up with the patch below, but I haven=E2=80=99t tested in detail. (You=E2=80= =99ll notice (guix build-system python) is hard to work with because it doesn=E2=80=99t = use gexps yet.) How does it look? Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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)) =20 (and (not target) ;XXX: no cross-compilati= on (bag @@ -174,6 +174,9 @@ pre-defined variants." =20 (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-referenc= e rest)))) + native-inputs)))) =20 (define guile-for-build (match guile @@ -222,6 +242,8 @@ provides a 'setup.py' file as its build system." =20 (build-expression->derivation store name builder #:inputs inputs + ;; TODO: + ;; #:disallowed-references disallowed-refe= rences #:system system #:modules imported-modules #:outputs outputs diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-s= ystem.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 =C2=A9 2013, 2015, 2016 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2013, 2015, 2016, 2017 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2013 Andreas Enge ;;; Copyright =C2=A9 2013 Nikita Karetnikov ;;; Copyright =C2=A9 2015 Mark H Weaver @@ -184,7 +184,7 @@ when running checks after installing the package." configure-flags))) (call-setuppy "install" params use-setuptools?))) =20 -(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)) =20 + (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 p= ath. (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) --=-=-=--