all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Cyril Roelandt <tipecaml@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 3/5] import: pypi: Compute test requirements when using wheels.
Date: Sat, 16 Jul 2016 17:23:23 +0200	[thread overview]
Message-ID: <1468682605-12622-4-git-send-email-tipecaml@gmail.com> (raw)
In-Reply-To: <1468682605-12622-1-git-send-email-tipecaml@gmail.com>

* 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

  parent reply	other threads:[~2016-07-16 15:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-16 15:23 [PATCH 0/5] Improve the pypi updater Cyril Roelandt
2016-07-16 15:23 ` [PATCH 1/5] import: pypi: Move runtime dependencies to the propagated-inputs Cyril Roelandt
2016-07-16 15:23 ` [PATCH 2/5] import: pypi: Remove setuptools from the inputs Cyril Roelandt
2016-07-22 21:24   ` Ludovic Courtès
2016-07-22 21:43     ` Leo Famulari
2016-07-23 14:46       ` Cyril Roelandt
2016-07-25 21:07         ` Ludovic Courtès
2016-07-16 15:23 ` Cyril Roelandt [this message]
2016-07-22 21:28   ` [PATCH 3/5] import: pypi: Compute test requirements when using wheels Ludovic Courtès
2016-07-16 15:23 ` [PATCH 4/5] import: pypi: Compute test requirements when reading requirements files Cyril Roelandt
2016-07-22 21:30   ` Ludovic Courtès
2016-07-23 14:48     ` Cyril Roelandt
2016-07-25 21:12       ` Ludovic Courtès
2016-07-16 15:23 ` [PATCH 5/5] import: pypi: Add more tests Cyril Roelandt
2016-07-22 21:31   ` Ludovic Courtès
2016-07-17 16:30 ` [PATCH 0/5] Improve the pypi updater Hartmut Goebel
2016-07-22 21:22 ` Ludovic Courtès
2016-07-23 14:53   ` Cyril Roelandt
2016-07-25 21:14     ` Ludovic Courtès

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468682605-12622-4-git-send-email-tipecaml@gmail.com \
    --to=tipecaml@gmail.com \
    --cc=guix-devel@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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.