guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Naming scheme for Python packages


From: Ludovic Courtès
Subject: Re: Naming scheme for Python packages
Date: Sat, 07 Sep 2013 14:49:07 +0200
User-agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux)

Andreas Enge <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]