guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/5] import: pypi: Compute test requirements when using wheels.


From: Cyril Roelandt
Subject: [PATCH 3/5] import: pypi: Compute test requirements when using wheels.
Date: Sat, 16 Jul 2016 17:23:23 +0200

* guix/import/pypi.scm (read-wheel-metadata): Read test requirements from the
metadata included in the wheel.
* guix/import/pypi.scm (guess-requirement-from-source): Return an empty list
for test requirements.
* guix/import/pypi.scm (compute-inputs): Return both the runtime requirements
and the test requirements.
* guix/import.pypi.scm (make-pypi-sexp): Compute native inputs.
* tests/pypi.scm ("pypi->guix-package, wheels"): Update accordingly.
---
 guix/import/pypi.scm | 96 +++++++++++++++++++++++++++++-----------------------
 tests/pypi.scm       | 12 +++++++
 2 files changed, 66 insertions(+), 42 deletions(-)

diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm
index af9b108..f43d7d5 100644
--- a/guix/import/pypi.scm
+++ b/guix/import/pypi.scm
@@ -175,13 +175,21 @@ cannot determine package dependencies"))
                  (lambda (port)
                    (let* ((metadata (json->scm port))
                           (run_requires (hash-ref metadata "run_requires"))
+                          (test_requires (hash-ref metadata "test_requires"))
                           (requirements (if run_requires
                                             (hash-ref (list-ref run_requires 0)
                                                        "requires")
-                                            '())))
-                     (map (lambda (r)
-                            (python->package-name (clean-requirement r)))
-                          requirements)))))
+                                            '()))
+                          (test-requirements (if test_requires
+                                                 (hash-ref (list-ref 
test_requires 0)
+                                                            "requires")
+                                                 '())))
+                     (list (map (lambda (r)
+                                  (python->package-name (clean-requirement r)))
+                                requirements)
+                           (map (lambda (r)
+                                  (python->package-name (clean-requirement r)))
+                                test-requirements))))))
              (lambda ()
                (delete-file json-file)
                (rmdir dirname))))))
@@ -208,15 +216,16 @@ cannot determine package dependencies"))
                 (dynamic-wind
                   (const #t)
                   (lambda ()
-                    (read-requirements req-file))
+                    (list (read-requirements req-file)
+                          '()))
                   (lambda ()
                     (delete-file req-file)
                     (rmdir dirname)))
                 (begin
                   (warning (_ "'tar xf' failed with exit code ~a\n")
                            exit-code)
-                  '())))
-          '())))
+                  (list '() '()))))
+          (list '() '()))))
 
   ;; First, try to compute the requirements using the wheel, since that is the
   ;; most reliable option. If a wheel is not provided for this package, try
@@ -228,17 +237,21 @@ cannot determine package dependencies"))
 
 (define (compute-inputs source-url wheel-url tarball)
   "Given the SOURCE-URL of an already downloaded TARBALL, return a list of
-name/variable pairs describing the required inputs of this package."
-  (sort
-    (map (lambda (input)
-           (list input (list 'unquote (string->symbol input))))
-         ;; Argparse has been part of Python since 2.7.
-         (remove (cut string=? "python-argparse" <>)
-                 (guess-requirements source-url wheel-url tarball)))
-    (lambda args
-      (match args
-        (((a _ ...) (b _ ...))
-         (string-ci<? a b))))))
+two lists: the runtime and test requirements of this package. Each element
+is a list of name/variable pairs describing the required inputs of this
+package."
+  (map (lambda (inputs)
+         (sort
+           (map (lambda (input)
+                  (list input (list 'unquote (string->symbol input))))
+                        ;; Argparse has been part of Python since 2.7.
+                (remove (cut string=? "python-argparse" <>)
+                        inputs))
+           (lambda args
+             (match args
+               (((a _ ...) (b _ ...))
+                (string-ci<? a b))))))
+       (guess-requirements source-url wheel-url tarball)))
 
 (define (make-pypi-sexp name version source-url wheel-url home-page synopsis
                         description license)
@@ -247,30 +260,29 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, 
and LICENSE."
   (call-with-temporary-output-file
    (lambda (temp port)
      (and (url-fetch source-url temp)
-          `(package
-             (name ,(python->package-name name))
-             (version ,version)
-             (source (origin
-                       (method url-fetch)
-
-                       ;; Sometimes 'pypi-uri' doesn't quite work due to mixed
-                       ;; cases in NAME, for instance, as is the case with
-                       ;; "uwsgi".  In that case, fall back to a full URL.
-                       (uri ,(if (equal? (pypi-uri name version) source-url)
-                                 `(pypi-uri ,name version)
-                                 `(string-append
-                                   ,@(factorize-uri source-url version))))
-
-                       (sha256
-                        (base32
-                         ,(guix-hash-url temp)))))
-             (build-system python-build-system)
-             ,@(maybe-inputs 'propagated-inputs
-                             (compute-inputs source-url wheel-url temp))
-             (home-page ,home-page)
-             (synopsis ,synopsis)
-             (description ,description)
-             (license ,(license->symbol license)))))))
+          (let ((inputs (compute-inputs source-url wheel-url temp)))
+            `(package
+               (name ,(python->package-name name))
+               (version ,version)
+               (source (origin
+                         (method url-fetch)
+                         ;; Sometimes 'pypi-uri' doesn't quite work due to 
mixed
+                         ;; cases in NAME, for instance, as is the case with
+                         ;; "uwsgi".  In that case, fall back to a full URL.
+                         (uri ,(if (equal? (pypi-uri name version) source-url)
+                                   `(pypi-uri ,name version)
+                                   `(string-append
+                                     ,@(factorize-uri source-url version))))
+                         (sha256
+                          (base32
+                           ,(guix-hash-url temp)))))
+               (build-system python-build-system)
+               ,@(maybe-inputs 'propagated-inputs (list-ref inputs 0))
+               ,@(maybe-inputs 'native-inputs (list-ref inputs 1))
+               (home-page ,home-page)
+               (synopsis ,synopsis)
+               (description ,description)
+               (license ,(license->symbol license))))))))
 
 (define (pypi->guix-package package-name)
   "Fetch the metadata for PACKAGE-NAME from pypi.python.org, and return the
diff --git a/tests/pypi.scm b/tests/pypi.scm
index 7f0ad23..cbf7066 100644
--- a/tests/pypi.scm
+++ b/tests/pypi.scm
@@ -68,6 +68,14 @@ baz > 13.37")
         \"baz (>13.37)\"
       ]
     }
+  ],
+  \"test_requires\": [
+    {
+      \"requires\": [
+        \"test-bar\",
+        \"test-baz (>42.42)\"
+      ]
+    }
   ]
 }")
 
@@ -169,6 +177,10 @@ baz > 13.37")
           ('quasiquote
            (("python-bar" ('unquote 'python-bar))
             ("python-baz" ('unquote 'python-baz)))))
+         ('native-inputs
+          ('quasiquote
+           (("python-test-bar" ('unquote 'python-test-bar))
+            ("python-test-baz" ('unquote 'python-test-baz)))))
          ('home-page "http://example.com";)
          ('synopsis "summary")
          ('description "summary")
-- 
2.6.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]