unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Andreas Enge <andreas@enge.fr>
Cc: guix-devel@gnu.org
Subject: Re: Naming scheme for Python packages
Date: Sat, 07 Sep 2013 14:49:07 +0200	[thread overview]
Message-ID: <877ges94qk.fsf@gnu.org> (raw)
In-Reply-To: <20130906215311.GB15258@debian> (Andreas Enge's message of "Fri, 6 Sep 2013 23:53:11 +0200")

Andreas Enge <andreas@enge.fr> skribis:

> On Thu, Sep 05, 2013 at 03:00:27PM +0200, Ludovic Courtès wrote:
>> BTW, I haven’t check whether this is the case already, but we need
>> 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’s better to keep it, as a generic version.  Then, we can have:

  (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" package)
> +                   ;; 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 ‘car’, ‘cdr’, and co; use ‘match’ instead: it
leads to code that is both more readable and more robust (info "(guile)
Pattern Matching").  In that case, you can even use ‘match-lambda’,
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 ‘libtool’ (info "(guix)
Packages with Multiple Outputs").

So the ‘rewrite’ 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) python2))
> +                (append arguments `(#:python ,python2)))
> +            arguments)))

Please fix the indentation of the ‘if’ 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’ll 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’.

  reply	other threads:[~2013-09-07 12:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1VHJTB-0006ys-7X@vcs.savannah.gnu.org>
2013-09-04 20:51 ` Naming scheme for Python packages Ludovic Courtès
2013-09-04 20:52   ` Cyril Roelandt
2013-09-04 21:16     ` Andreas Enge
2013-09-04 21:07   ` Cyril Roelandt
2013-09-04 21:36     ` Andreas Enge
2013-09-04 21:08   ` Andreas Enge
2013-09-04 21:32     ` Andreas Enge
2013-09-05 13:00       ` Ludovic Courtès
2013-09-06 21:53         ` Andreas Enge
2013-09-07 12:49           ` Ludovic Courtès [this message]
2013-09-07 21:25             ` Andreas Enge
2013-09-08 14:03               ` Ludovic Courtès
2013-09-08 14:51                 ` Andreas Enge
2013-09-08 20:00                   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877ges94qk.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=andreas@enge.fr \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).