Patchwork [WIP,5/8] guix: python-build-system: Add helpers for getting and setting PYTHONPATH.

login
register
mail settings
Submitter Hartmut Goebel
Date Oct. 10, 2016, 2:57 p.m.
Message ID <1476111439-20812-6-git-send-email-h.goebel@crazy-compilers.com>
Download mbox | patch
Permalink /patch/16397/
State New
Headers show

Comments

Hartmut Goebel - Oct. 10, 2016, 2:57 p.m.
* guix/build/python-build-system.scm (add-installed-pythonpath,
  site-packages): New exported procedures.
---
 guix/build/python-build-system.scm | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Patch

diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm
index 038fa97..1950b3b 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -28,7 +28,9 @@ 
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:export (%standard-phases
-            python-build))
+            python-build
+            add-installed-pythonpath
+            site-packages))
 
 ;; Commentary:
 ;;
@@ -74,6 +76,24 @@ 
          (major+minor (take components 2)))
     (string-join major+minor ".")))
 
+(define (site-packages outputs inputs)
+  "Return the path of the current output's Python site-package."
+  (let* ((out (assoc-ref outputs "out"))
+         (python (assoc-ref inputs "python")))
+    (string-append out "/lib/python"
+                   (get-python-version python)
+                   "/site-packages/")))
+
+(define (add-installed-pythonpath outputs inputs)
+  "Prepend the Python site-package of OUTPUT to PYTHONPATH.  This is useful
+when running checks after installing the package."
+  (let ((old-path (getenv "PYTHONPATH"))
+        (add-path (site-packages outputs inputs)))
+    (setenv "PYTHONPATH"
+            (string-append add-path
+                           (if old-path (string-append ":" old-path) "")))
+    #t))
+
 (define* (install #:key outputs inputs (configure-flags '()) use-setuptools?
                   #:allow-other-keys)
   "Install a given Python package."