From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Enge Subject: Re: Naming scheme for Python packages Date: Fri, 6 Sep 2013 23:53:11 +0200 Message-ID: <20130906215311.GB15258@debian> References: <87li3c8g56.fsf@gnu.org> <20130904210836.GB8425@debian> <20130904213224.GA8767@debian> <87hadz5spg.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VI3y6-0003sJ-Ai for guix-devel@gnu.org; Fri, 06 Sep 2013 17:53:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VI3y0-0002MO-3d for guix-devel@gnu.org; Fri, 06 Sep 2013 17:53:30 -0400 Content-Disposition: inline In-Reply-To: <87hadz5spg.fsf@gnu.org> 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: Ludovic =?iso-8859-15?Q?Court=E8s?= Cc: guix-devel@gnu.org --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.python" 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)) --nFreZHaLTZJo0R7j--