1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-pypi)
20 #:use-module (guix import pypi)
21 #:use-module (guix base32)
22 #:use-module (guix hash)
23 #:use-module (guix tests)
24 #:use-module ((guix build utils) #:select (delete-file-recursively which))
25 #:use-module (srfi srfi-64)
26 #:use-module (ice-9 match))
31 \"version\": \"1.0.0\",
33 \"license\": \"GNU LGPL\",
34 \"summary\": \"summary\",
35 \"home_page\": \"http://example.com\",
40 \"url\": \"https://example.com/foo-1.0.0.egg\",
41 \"packagetype\": \"bdist_egg\",
43 \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
44 \"packagetype\": \"sdist\",
46 \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\",
47 \"packagetype\": \"bdist_wheel\",
53 (define test-source-hash
56 (define test-requirements
58 # A comment after a space
76 (test-assert "pypi->guix-package"
77 ;; Replace network resources with sample data.
78 (mock ((guix import utils) url-fetch
79 (lambda (url file-name)
81 ("https://pypi.python.org/pypi/foo/json"
82 (with-output-to-file file-name
84 (display test-json))))
85 ("https://example.com/foo-1.0.0.tar.gz"
88 (with-output-to-file "foo-1.0.0/requirements.txt"
90 (display test-requirements)))
91 (system* "tar" "czvf" file-name "foo-1.0.0/")
92 (delete-file-recursively "foo-1.0.0")
93 (set! test-source-hash
94 (call-with-input-file file-name port-sha256))))
95 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
96 (_ (error "Unexpected URL: " url)))))
97 (match (pypi->guix-package "foo")
103 ('uri (string-append "https://example.com/foo-"
108 ('build-system 'python-build-system)
111 (("python-bar" ('unquote 'python-bar))
112 ("python-baz" ('unquote 'python-baz))
113 ("python-setuptools" ('unquote 'python-setuptools)))))
114 ('home-page "http://example.com")
115 ('synopsis "summary")
116 ('description "summary")
118 (string=? (bytevector->nix-base32-string
124 (test-skip (if (which "zip") 0 1))
125 (test-assert "pypi->guix-package, wheels"
126 ;; Replace network resources with sample data.
127 (mock ((guix import utils) url-fetch
128 (lambda (url file-name)
130 ("https://pypi.python.org/pypi/foo/json"
131 (with-output-to-file file-name
133 (display test-json))))
134 ("https://example.com/foo-1.0.0.tar.gz"
137 (with-output-to-file "foo-1.0.0/requirements.txt"
139 (display test-requirements)))
140 (system* "tar" "czvf" file-name "foo-1.0.0/")
141 (delete-file-recursively "foo-1.0.0")
142 (set! test-source-hash
143 (call-with-input-file file-name port-sha256))))
144 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl"
146 (mkdir "foo-1.0.0.dist-info")
147 (with-output-to-file "foo-1.0.0.dist-info/metadata.json"
149 (display test-metadata)))
150 (let ((zip-file (string-append file-name ".zip")))
151 ;; zip always adds a "zip" extension to the file it creates,
152 ;; so we need to rename it.
153 (system* "zip" zip-file "foo-1.0.0.dist-info/metadata.json")
154 (rename-file zip-file file-name))
155 (delete-file-recursively "foo-1.0.0.dist-info")))
156 (_ (error "Unexpected URL: " url)))))
157 (match (pypi->guix-package "foo")
163 ('uri (string-append "https://example.com/foo-"
168 ('build-system 'python-build-system)
171 (("python-bar" ('unquote 'python-bar))
172 ("python-baz" ('unquote 'python-baz))
173 ("python-setuptools" ('unquote 'python-setuptools)))))
174 ('home-page "http://example.com")
175 ('synopsis "summary")
176 ('description "summary")
178 (string=? (bytevector->nix-base32-string