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: Sat, 7 Sep 2013 23:25:13 +0200 [thread overview]
Message-ID: <20130907212513.GA27881@debian> (raw)
In-Reply-To: <877ges94qk.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]
Hello,
and thanks for your comments! I am attaching a new patch.
On Sat, Sep 07, 2013 at 02:49:07PM +0200, Ludovic Courtès wrote:
> 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.
I modified with two additional parameters, OLD-PREFIX and NEW-PREFIX:
When going to python-2, one rewrites the prefix "python-" to "python2-".
The current patch would allow to go back to Python 3 by calling
(package-with-explicit-python p python "python2-" "python-").
> 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
> ...))
This is rather surprising for a language based on lists...
But admittedly, the code becomes more readable.
> Second remark: inputs are actually tuples of one of two forms:
> (name package)
> (name package output)
Or a third one, (name-of-patch store-path-of-patch), which was already
handled. The current patch should handle all cases.
> (map rewrite (package-inputs p)) is enough; if (package-inputs p) is
> null?, then that’ll return the empty list too.
This is something that I had tested, and strangely, it did not work at the
time I made the test. But the error must have lain somewhere else then.
Andreas
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 3964 bytes --]
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index ce89281..3ff4da2 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
@@ -247,8 +246,4 @@ 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)))))
+ (package-with-python2 python-babel))
diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index 7ac93b2..30cf6ec 100644
--- a/guix/build-system/python.scm
+++ b/guix/build-system/python.scm
@@ -25,6 +25,7 @@
#:use-module (guix build-system)
#:use-module (guix build-system gnu)
#:use-module (ice-9 match)
+ #:use-module (srfi srfi-26)
#:export (python-build
python-build-system))
@@ -41,6 +42,55 @@
(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 (package-with-explicit-python p python old-prefix new-prefix)
+ "Create a package with the same fields as P, which is assumed to use
+PYTHON-BUILD-SYSTEM, such that it is compiled with PYTHON instead. The
+inputs are changed recursively accordingly. If the name of P starts with
+OLD-PREFIX, this is replaced by NEW-PREFIX; otherwise, NEW-PREFIX is
+prepended to the name."
+ (let* ((build-system (package-build-system p))
+ (rewrite-if-package
+ (lambda (content)
+ ;; CONTENT may be a string (e.g., for patches), in which case it
+ ;; is returned, or a package, which is rewritten with the new
+ ;; PYTHON and NEW-PREFIX.
+ (if (package? content)
+ (package-with-explicit-python content python
+ old-prefix new-prefix)
+ content)))
+ (rewrite
+ (match-lambda
+ ((name content . rest)
+ (append (list name (rewrite-if-package content)) rest)))))
+ (package (inherit p)
+ (name
+ (let ((name (package-name p)))
+ (if (eq? build-system python-build-system)
+ (string-append new-prefix
+ (if (string-prefix? old-prefix name)
+ (substring name (string-length old-prefix))
+ name))
+ name)))
+ (arguments
+ (let ((arguments (package-arguments p)))
+ (if (eq? build-system python-build-system)
+ (if (member #:python arguments)
+ (substitute-keyword-arguments arguments ((#:python p) python))
+ (append arguments `(#:python ,python)))
+ arguments)))
+ (inputs
+ (map rewrite (package-inputs p)))
+ (native-inputs
+ (map rewrite (package-native-inputs p))))))
+
+(define-public package-with-python2
+ (cut package-with-explicit-python <> (default-python2) "python-" "python2-"))
+
(define* (python-build store name source inputs
#:key
(python (default-python))
next prev parent reply other threads:[~2013-09-07 21:25 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
2013-09-07 21:25 ` Andreas Enge [this message]
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=20130907212513.GA27881@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 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).