From: Andreas Enge <andreas@enge.fr>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: Naming scheme for Python packages
Date: Fri, 6 Sep 2013 23:53:11 +0200 [thread overview]
Message-ID: <20130906215311.GB15258@debian> (raw)
In-Reply-To: <87hadz5spg.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]
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-".
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.
When trying this with python2-babel, the previous code in python.scm
(commented out in the attached patch) and the new one create almost the same
derivations, that differ only in
/nix/store/4rrnwqsj8c086zzviyypr4fikb7pz49v-python2-babel-0.9.6-guile-builder
vs.
/nix/store/5prbhg600qa9k8p0bgjs12p4dm682gn8-python2-babel-0.9.6-guile-builder
so that the final hash is also different.
Comments are welcome.
Andreas
[-- Attachment #2: patch.python --]
[-- Type: text/plain, Size: 4444 bytes --]
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index ce89281..aa2d15c 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -28,6 +28,7 @@
#:use-module (gnu packages patchelf)
#:use-module (guix packages)
#:use-module (guix download)
+ #:use-module (guix utils)
#:use-module (guix build-system gnu)
#:use-module (guix build-system python)
#:use-module (guix build-system trivial))
@@ -215,9 +216,7 @@ using Python 2.4 or higher and provides access to the Olson timezone database.")
(license x11)))
(define-public python2-pytz
- (package (inherit python-pytz)
- (name "python2-pytz")
- (arguments (append (package-arguments python-pytz) `(#:python ,python-2)))))
+ (package-with-python2 python-pytz))
(define-public python-babel
(package
@@ -233,7 +232,8 @@ using Python 2.4 or higher and provides access to the Olson timezone database.")
"03vmr54jq5vf3qw6kpdv7cdk7x7i2jhzyf1mawv2gk8zrxg0hfja"))))
(build-system python-build-system)
(inputs
- `(("python-pytz" ,python-pytz)))
+ `(("python-pytz" ,python-pytz)
+ ("openssl" ,openssl)))
(arguments `(#:tests? #f)) ; no test target
(home-page "http://babel.edgewall.org/")
(synopsis
@@ -246,9 +246,12 @@ access to various locale display names, localized number and date formatting,
etc. ")
(license bsd-3)))
+;; (define-public python2-babel
+;; (package (inherit python-babel)
+;; (name "python2-babel")
+;; (inputs
+;; `(("python2-pytz" ,python2-pytz)))
+;; (arguments (append (package-arguments python-babel) `(#:python ,python-2)))))
+
(define-public python2-babel
- (package (inherit python-babel)
- (name "python2-babel")
- (inputs
- `(("python2-pytz" ,python2-pytz)))
- (arguments (append (package-arguments python-babel) `(#:python ,python-2)))))
+ (package-with-python2 python-babel))
diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index 7ac93b2..a704d35 100644
--- a/guix/build-system/python.scm
+++ b/guix/build-system/python.scm
@@ -41,6 +41,56 @@
(let ((python (resolve-interface '(gnu packages python))))
(module-ref python 'python-wrapper)))
+(define (default-python2)
+ "Return the default Python 2 package."
+ (let ((python (resolve-interface '(gnu packages python))))
+ (module-ref python 'python-2)))
+
+(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)))
+ (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)))
+ (inputs
+ (let ((inputs (package-inputs p)))
+ (if (null? inputs)
+ '()
+ (map rewrite inputs))))
+ (native-inputs
+ (let ((native-inputs (package-native-inputs p)))
+ (if (null? native-inputs)
+ '()
+ (map rewrite native-inputs)))))))
+
+
(define* (python-build store name source inputs
#:key
(python (default-python))
next prev parent reply other threads:[~2013-09-06 21:53 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 [this message]
2013-09-07 12:49 ` Ludovic Courtès
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130906215311.GB15258@debian \
--to=andreas@enge.fr \
--cc=guix-devel@gnu.org \
--cc=ludo@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 external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.