From: Danny Milosavljevic <dannym@scratchpost.org>
To: 29856@debbugs.gnu.org
Subject: [bug#29856] [PATCH core-updates] guix: python-build-system: Modify ".py" files in-place.
Date: Tue, 26 Dec 2017 13:21:05 +0100 [thread overview]
Message-ID: <20171226122105.19156-1-dannym@scratchpost.org> (raw)
* 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)))
next reply other threads:[~2017-12-26 12:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-26 12:21 Danny Milosavljevic [this message]
2017-12-26 19:10 ` [bug#29856] [PATCH core-updates] guix: python-build-system: Modify ".py" files in-place Leo Famulari
2017-12-27 0:23 ` Danny Milosavljevic
2017-12-31 15:02 ` Marius Bakke
2017-12-31 17:17 ` Danny Milosavljevic
2018-01-02 16:13 ` [bug#29856] [PATCH core-updates] guix: python-build-system:, " Hartmut Goebel
2018-01-02 17:26 ` Danny Milosavljevic
2019-02-04 7:58 ` bug#29856: " Ricardo Wurmus
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=20171226122105.19156-1-dannym@scratchpost.org \
--to=dannym@scratchpost.org \
--cc=29856@debbugs.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).