Patchwork [WIP,3/8] guix: python-build-system: Import setuptools before calling `setup.py'.

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

Comments

Hartmut Goebel - Oct. 10, 2016, 2:57 p.m.
From: Marius Bakke <mbakke@fastmail.com>

This is needed for packages using "distutils" instead of "setuptools" since
the former does not understand the "--single-version-externally-managed"
flag. Also export __file__ since it will be unset when setup.py is called from
python "exec".

* guix/build/python-build-system.scm (call-setuppy): extend "python setup.py"
  call to import setuptools, export __file__, and call setup.py from
  setuptools python environment.

Co-Authored-By: Hartmut Goebel <h.goebel@crazy-compilers.com>
---
 guix/build/python-build-system.scm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Patch

diff --git a/guix/build/python-build-system.scm b/guix/build/python-build-system.scm
index 05a01f3..50a094d 100644
--- a/guix/build/python-build-system.scm
+++ b/guix/build/python-build-system.scm
@@ -36,13 +36,23 @@ 
 ;;
 ;; Code:
 
+(define setuptools-shim
+  ;; Run setup.py with "setuptools" being imported, which will patch
+  ;; "distutils". This is needed for packages using "distutils" instead of
+  ;; "setuptools" since the former does not understand the
+  ;; "--single-version-externally-managed" flag.
+  ;; Python code taken from pip 8.1.2 pip/utils/setuptools_build.py
+  (string-append
+   "import setuptools, tokenize;__file__='setup.py';"
+   "exec(compile(getattr(tokenize, 'open', open)(__file__).read()"
+   ".replace('\\r\\n', '\\n'), __file__, 'exec'))"))
 
 (define (call-setuppy command params)
   (if (file-exists? "setup.py")
       (begin
          (format #t "running \"python setup.py\" with command ~s and parameters ~s~%"
                 command params)
-         (zero? (apply system* "python" "setup.py" command params)))
+         (zero? (apply system* "python" "-c" setuptools-shim command params)))
       (error "no setup.py found")))
 
 (define* (build #:rest empty)