From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Naming scheme for Python packages Date: Sat, 07 Sep 2013 14:49:07 +0200 Message-ID: <877ges94qk.fsf@gnu.org> References: <87li3c8g56.fsf@gnu.org> <20130904210836.GB8425@debian> <20130904213224.GA8767@debian> <87hadz5spg.fsf@gnu.org> <20130906215311.GB15258@debian> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VII1r-0007wO-0K for guix-devel@gnu.org; Sat, 07 Sep 2013 08:54:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VII1i-0000YT-L2 for guix-devel@gnu.org; Sat, 07 Sep 2013 08:54:18 -0400 Received: from hera.aquilenet.fr ([141.255.128.1]:41734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VII1i-0000YA-BY for guix-devel@gnu.org; Sat, 07 Sep 2013 08:54:10 -0400 In-Reply-To: <20130906215311.GB15258@debian> (Andreas Enge's message of "Fri, 6 Sep 2013 23:53:11 +0200") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Andreas Enge Cc: guix-devel@gnu.org Andreas Enge skribis: > On Thu, Sep 05, 2013 at 03:00:27PM +0200, Ludovic Court=C3=A8s wrote: >> BTW, I haven=E2=80=99t check whether this is the case already, but we ne= ed >> something like >> (define (package-with-explicit-python p python) >> ;; Return a version of P built for PYTHON. >> (package (inherit p) ...)) >> so we can just write: >> (define python2-pytz >> (package-with-explicit-python python-pytz python-2)) > > The attached patch does almost this, following our offline discussion on > how to create packages recursively on the fly: > - It adds an argument pair "#:python ,python-2", or replaces an already > present argument "#:python something-else", and this recursively > for all inputs and native-inputs that use the python build system. > - It rewrites the corresponding names from "python-..." to "python2-...", > or adds a prefix "python2-". Great! > So one can write > (define python2-pytz > (package-with-explicit-python python-pytz)) > As the second argument would always be python-2, I decided to drop it. Still it=E2=80=99s better to keep it, as a generic version. Then, we can h= ave: (define package-with-python-2 (cut package-with-explicit-python <> python-2)) and then use that as needed. > +(define-public (package-with-python2 p) > + "Create a package with the same fields as P, which is assumed to use > +PYTHON-BUILD-SYSTEM and to be compiled with the default python, such that > +it is compiled with python 2 instead. The name of P is prefixed with > +\"python2-\"; a potential existing prefix \"python-\" is dropped." > + (let ((rewrite (lambda (x) > + ;; procedure taking a two-element list ("name" packag= e) > + ;; and returning a two element list > + ;; ("name" (package-with-python2 package)) > + (let ((name (car x)) > + (content (car (cdr x)))) > + (list name > + (if (package? content) > + (package-with-python2 content) > + content))))) > + (build-system (package-build-system p))) Sylistic note: never use =E2=80=98car=E2=80=99, =E2=80=98cdr=E2=80=99, and = co; use =E2=80=98match=E2=80=99 instead: it leads to code that is both more readable and more robust (info "(guile) Pattern Matching"). In that case, you can even use =E2=80=98match-lambda= =E2=80=99, which is equivalent to: (lambda (x) (match x ...)) Second remark: inputs are actually tuples of one of two forms: (name package) (name package output) The first form means that we take the default output of PACKAGE; the second form specifies that we want OUTPUT of PACKAGE. This makes a different for multiple-output packages, such as =E2=80=98libtool=E2=80=99 (= info "(guix) Packages with Multiple Outputs"). So the =E2=80=98rewrite=E2=80=99 procedure must look like this: (define rewrite (match-lambda ((name package) ...) ((name package output) ...))) > + (package (inherit p) > + (name > + (let ((name (package-name p))) > + (if (eq? build-system python-build-system) > + (string-append "python2-" > + (if (string-prefix? "python-" name) > + (substring name 7) > + name)) > + name))) > + (arguments > + (let ((arguments (package-arguments p)) > + (python2 (default-python2))) > + (if (eq? build-system python-build-system) > + (if (member #:python arguments) > + (substitute-keyword-arguments arguments ((#:python p) py= thon2)) > + (append arguments `(#:python ,python2))) > + arguments))) Please fix the indentation of the =E2=80=98if=E2=80=99 arms. > + (inputs > + (let ((inputs (package-inputs p))) > + (if (null? inputs) > + '() > + (map rewrite inputs)))) (map rewrite (package-inputs p)) is enough; if (package-inputs p) is null?, then that=E2=80=99ll return the empty list too. > + (native-inputs > + (let ((native-inputs (package-native-inputs p))) > + (if (null? native-inputs) > + '() > + (map rewrite native-inputs))))))) Ditto. Thanks for working on this! Ludo=E2=80=99.