import: pypi: Do not consider requirements.txt files.

PyPI packages are mandated to have a setup.py file, which contains a listing
of the required dependencies.  The setuptools/distutils machinery embed
metadata in the archives they produce, which contains this information. There
is no need nor gain to collect the requirements from a "requirements.txt"
file, as it is not the true record of dependencies for PyPI packages and may
contain extraneous requirements or not exist at all.

* guix/import/pypi.scm (guess-requirements): Update comment.
[guess-requirements-from-source]: Do not attempt to parse the file
requirements.txt.  Streamline logic.
* tests/pypi.scm (test-requires.txt): Rename from test-requirements, to hint
at the file being tested.
("pypi->guix-package"): Adapt so that the fake package contains a requires.txt
file rather than a requirements.txt file.
("pypi->guix-package, wheels"): Likewise.
This commit is contained in:
Maxim Cournoyer 2019-03-28 00:26:00 -04:00
parent 0f0651295e
commit 01589acc5e
No known key found for this signature in database
GPG key ID: 1260E46482E63562
2 changed files with 25 additions and 33 deletions

View file

@ -206,35 +206,26 @@ (define (guess-requirements-from-source)
(call-with-temporary-directory (call-with-temporary-directory
(lambda (dir) (lambda (dir)
(let* ((pypi-name (string-take dirname (string-rindex dirname #\-))) (let* ((pypi-name (string-take dirname (string-rindex dirname #\-)))
(req-files (list (string-append dirname "/requirements.txt") (requires.txt (string-append dirname "/" pypi-name
(string-append dirname "/" pypi-name ".egg-info" ".egg-info" "/requires.txt"))
"/requires.txt"))) (exit-code (parameterize ((current-error-port (%make-void-port "rw+"))
(exit-codes (map (lambda (file-name) (current-output-port (%make-void-port "rw+")))
(parameterize ((current-error-port (%make-void-port "rw+")) (system* "tar" "xf" tarball "-C" dir requires.txt))))
(current-output-port (%make-void-port "rw+"))) (if (zero? exit-code)
(system* "tar" "xf" tarball "-C" dir file-name))) (read-requirements (string-append dir "/" requires.txt))
req-files)))
;; Only one of these files needs to exist.
(if (any zero? exit-codes)
(match (find-files dir)
((file . _)
(read-requirements file))
(()
(warning (G_ "No requirements file found.\n"))))
(begin (begin
(warning (G_ "Failed to extract requirements files\n")) (warning
(G_ "Failed to extract file: ~a from source.~%")
requires.txt)
'()))))) '())))))
'()))) '())))
;; First, try to compute the requirements using the wheel, since that is the ;; First, try to compute the requirements using the wheel, else, fallback to
;; most reliable option. If a wheel is not provided for this package, try ;; reading the "requires.txt" from the egg-info directory from the source
;; getting them by reading either the "requirements.txt" file or the ;; tarball.
;; "requires.txt" from the egg-info directory from the source tarball. Note
;; that "requirements.txt" is not mandatory, so this is likely to fail.
(or (guess-requirements-from-wheel) (or (guess-requirements-from-wheel)
(guess-requirements-from-source))) (guess-requirements-from-source)))
(define (compute-inputs source-url wheel-url tarball) (define (compute-inputs source-url wheel-url tarball)
"Given the SOURCE-URL of an already downloaded TARBALL, return a list of "Given the SOURCE-URL of an already downloaded TARBALL, return a list of
name/variable pairs describing the required inputs of this package. Also name/variable pairs describing the required inputs of this package. Also

View file

@ -23,7 +23,7 @@ (define-module (test-pypi)
#:use-module (gcrypt hash) #:use-module (gcrypt hash)
#:use-module (guix tests) #:use-module (guix tests)
#:use-module (guix build-system python) #:use-module (guix build-system python)
#:use-module ((guix build utils) #:select (delete-file-recursively which)) #:use-module ((guix build utils) #:select (delete-file-recursively which mkdir-p))
#:use-module (srfi srfi-64) #:use-module (srfi srfi-64)
#:use-module (ice-9 match)) #:use-module (ice-9 match))
@ -55,11 +55,12 @@ (define test-json
(define test-source-hash (define test-source-hash
"") "")
(define test-requirements (define test-requires.txt "\
"# A comment # A comment
# A comment after a space # A comment after a space
bar bar
baz > 13.37") baz > 13.37
")
(define test-metadata (define test-metadata
"{ "{
@ -107,10 +108,10 @@ (define test-metadata
(match url (match url
("https://example.com/foo-1.0.0.tar.gz" ("https://example.com/foo-1.0.0.tar.gz"
(begin (begin
(mkdir "foo-1.0.0") (mkdir-p "foo-1.0.0/foo.egg-info/")
(with-output-to-file "foo-1.0.0/requirements.txt" (with-output-to-file "foo-1.0.0/foo.egg-info/requires.txt"
(lambda () (lambda ()
(display test-requirements))) (display test-requires.txt)))
(system* "tar" "czvf" file-name "foo-1.0.0/") (system* "tar" "czvf" file-name "foo-1.0.0/")
(delete-file-recursively "foo-1.0.0") (delete-file-recursively "foo-1.0.0")
(set! test-source-hash (set! test-source-hash
@ -157,11 +158,11 @@ (define test-metadata
(lambda (url file-name) (lambda (url file-name)
(match url (match url
("https://example.com/foo-1.0.0.tar.gz" ("https://example.com/foo-1.0.0.tar.gz"
(begin (begin
(mkdir "foo-1.0.0") (mkdir-p "foo-1.0.0/foo.egg-info/")
(with-output-to-file "foo-1.0.0/requirements.txt" (with-output-to-file "foo-1.0.0/foo.egg-info/requires.txt"
(lambda () (lambda ()
(display test-requirements))) (display test-requires.txt)))
(system* "tar" "czvf" file-name "foo-1.0.0/") (system* "tar" "czvf" file-name "foo-1.0.0/")
(delete-file-recursively "foo-1.0.0") (delete-file-recursively "foo-1.0.0")
(set! test-source-hash (set! test-source-hash