1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (test-pypi)
21 #:use-module (guix import pypi)
22 #:use-module (guix base32)
23 #:use-module (gcrypt hash)
24 #:use-module (guix tests)
25 #:use-module (guix build-system python)
26 #:use-module ((guix build utils) #:select (delete-file-recursively which))
27 #:use-module (srfi srfi-64)
28 #:use-module (ice-9 match))
33 \"version\": \"1.0.0\",
35 \"license\": \"GNU LGPL\",
36 \"summary\": \"summary\",
37 \"home_page\": \"http://example.com\",
42 \"url\": \"https://example.com/foo-1.0.0.egg\",
43 \"packagetype\": \"bdist_egg\",
45 \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
46 \"packagetype\": \"sdist\",
48 \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\",
49 \"packagetype\": \"bdist_wheel\",
55 (define test-source-hash
58 (define test-requirements
60 # A comment after a space
78 (test-equal "guix-package->pypi-name, old URL style"
80 (guix-package->pypi-name
84 "https://pypi.org/packages/source/p/psutil/psutil-4.3.0.tar.gz"))))))
86 (test-equal "guix-package->pypi-name, new URL style"
88 (guix-package->pypi-name
92 "https://pypi.org/packages/a2/3b/4756e6a0ceb14e084042a2a65c615d68d25621c6fd446d0fc10d14c4ce7d/certbot-0.8.1.tar.gz"))))))
94 (test-equal "guix-package->pypi-name, several URLs"
96 (guix-package->pypi-name
100 (uri (list "https://bitheap.org/cram/cram-0.7.tar.gz"
101 (pypi-uri "cram" "0.7"))))))))
103 (test-assert "pypi->guix-package"
104 ;; Replace network resources with sample data.
105 (mock ((guix import utils) url-fetch
106 (lambda (url file-name)
108 ("https://example.com/foo-1.0.0.tar.gz"
111 (with-output-to-file "foo-1.0.0/requirements.txt"
113 (display test-requirements)))
114 (system* "tar" "czvf" file-name "foo-1.0.0/")
115 (delete-file-recursively "foo-1.0.0")
116 (set! test-source-hash
117 (call-with-input-file file-name port-sha256))))
118 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
119 (_ (error "Unexpected URL: " url)))))
120 (mock ((guix http-client) http-fetch
123 ("https://pypi.org/pypi/foo/json"
124 (values (open-input-string test-json)
125 (string-length test-json)))
126 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
127 (_ (error "Unexpected URL: " url)))))
128 (match (pypi->guix-package "foo")
134 ('uri ('pypi-uri "foo" 'version))
138 ('build-system 'python-build-system)
141 (("python-bar" ('unquote 'python-bar))
142 ("python-baz" ('unquote 'python-baz)))))
143 ('home-page "http://example.com")
144 ('synopsis "summary")
145 ('description "summary")
146 ('license 'license:lgpl2.0))
147 (string=? (bytevector->nix-base32-string
153 (test-skip (if (which "zip") 0 1))
154 (test-assert "pypi->guix-package, wheels"
155 ;; Replace network resources with sample data.
156 (mock ((guix import utils) url-fetch
157 (lambda (url file-name)
159 ("https://example.com/foo-1.0.0.tar.gz"
162 (with-output-to-file "foo-1.0.0/requirements.txt"
164 (display test-requirements)))
165 (system* "tar" "czvf" file-name "foo-1.0.0/")
166 (delete-file-recursively "foo-1.0.0")
167 (set! test-source-hash
168 (call-with-input-file file-name port-sha256))))
169 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl"
171 (mkdir "foo-1.0.0.dist-info")
172 (with-output-to-file "foo-1.0.0.dist-info/metadata.json"
174 (display test-metadata)))
175 (let ((zip-file (string-append file-name ".zip")))
176 ;; zip always adds a "zip" extension to the file it creates,
177 ;; so we need to rename it.
178 (system* "zip" zip-file "foo-1.0.0.dist-info/metadata.json")
179 (rename-file zip-file file-name))
180 (delete-file-recursively "foo-1.0.0.dist-info")))
181 (_ (error "Unexpected URL: " url)))))
182 (mock ((guix http-client) http-fetch
185 ("https://pypi.org/pypi/foo/json"
186 (values (open-input-string test-json)
187 (string-length test-json)))
188 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
189 (_ (error "Unexpected URL: " url)))))
190 (match (pypi->guix-package "foo")
196 ('uri ('pypi-uri "foo" 'version))
200 ('build-system 'python-build-system)
203 (("python-bar" ('unquote 'python-bar))
204 ("python-baz" ('unquote 'python-baz)))))
205 ('home-page "http://example.com")
206 ('synopsis "summary")
207 ('description "summary")
208 ('license 'license:lgpl2.0))
209 (string=? (bytevector->nix-base32-string