From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eToFB-0007tQ-Gg for guix-patches@gnu.org; Tue, 26 Dec 2017 07:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eToF8-0004d2-6P for guix-patches@gnu.org; Tue, 26 Dec 2017 07:22:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:43740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eToF8-0004cu-2K for guix-patches@gnu.org; Tue, 26 Dec 2017 07:22:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eToF7-0001WU-TX for guix-patches@gnu.org; Tue, 26 Dec 2017 07:22:01 -0500 Subject: [bug#29856] [PATCH core-updates] guix: python-build-system: Modify ".py" files in-place. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eToEL-0007gF-Tf for guix-patches@gnu.org; Tue, 26 Dec 2017 07:21:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eToEI-0003ug-MP for guix-patches@gnu.org; Tue, 26 Dec 2017 07:21:13 -0500 Received: from dd26836.kasserver.com ([85.13.145.193]:40074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eToEI-0003tg-GD for guix-patches@gnu.org; Tue, 26 Dec 2017 07:21:10 -0500 From: Danny Milosavljevic Date: Tue, 26 Dec 2017 13:21:05 +0100 Message-Id: <20171226122105.19156-1-dannym@scratchpost.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 29856@debbugs.gnu.org * guix/build/python-build-system.scm (wrap-python-program): New variable. (wrap-program*): New variable. (wrap): Use wrap-program*. --- guix/build/python-build-system.scm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm index dd07986b9..f5f6b07f8 100644 --- a/guix/build/python-build-system.scm +++ b/guix/build/python-build-system.scm @@ -25,6 +25,7 @@ #:use-module (guix build utils) #:use-module (ice-9 match) #:use-module (ice-9 ftw) + #:use-module (ice-9 rdelim) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:export (%standard-phases @@ -184,6 +185,32 @@ when running checks after installing the package." configure-flags))) (call-setuppy "install" params use-setuptools?))) +(define (wrap-python-program file-name vars) + "Wrap the given program as a Python script (in-place)" + (match vars + (("PYTHONPATH" 'prefix python-path) + (let ((pythonish-path (string-join python-path "', '"))) + (with-atomic-file-replacement file-name + (lambda (in out) + (display (format #f "#!~a +import sys +sys.path = ['~a'] + sys.path +" (which "python") pythonish-path) out) + (let loop ((line (read-line in 'concat))) + (if (eof-object? line) + #t + (begin + (display line out) + (loop (read-line in 'concat))))))))))) + +(define (wrap-program* file-name vars) + "Wrap the given program. + If FILE-NAME is ending in '.py', wraps it in a Python way. + Otherwise wraps it in a Bash way." + (if (string-suffix? ".py" file-name) + (wrap-python-program file-name vars) + (wrap-program file-name vars))) + (define* (wrap #:key inputs outputs #:allow-other-keys) (define (list-of-files dir) (map (cut string-append dir "/" <>) @@ -209,7 +236,7 @@ when running checks after installing the package." (or (getenv "PYTHONPATH") "")))))) (for-each (lambda (dir) (let ((files (list-of-files dir))) - (for-each (cut wrap-program <> var) + (for-each (cut wrap-program* <> var) files))) bindirs)))