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 (guix hash)
24 #:use-module (guix tests)
25 #:use-module ((guix build utils) #:select (delete-file-recursively which))
26 #:use-module (srfi srfi-64)
27 #:use-module (ice-9 match))
32 \"version\": \"1.0.0\",
34 \"license\": \"GNU LGPL\",
35 \"summary\": \"summary\",
36 \"home_page\": \"http://example.com\",
41 \"url\": \"https://example.com/foo-1.0.0.egg\",
42 \"packagetype\": \"bdist_egg\",
44 \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
45 \"packagetype\": \"sdist\",
47 \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\",
48 \"packagetype\": \"bdist_wheel\",
54 (define test-source-hash
57 (define test-requirements
59 # A comment after a space
77 (test-equal "guix-package->pypi-name, old URL style"
79 (guix-package->pypi-name
83 "https://pypi.io/packages/source/p/psutil/psutil-4.3.0.tar.gz"))))))
85 (test-equal "guix-package->pypi-name, new URL style"
87 (guix-package->pypi-name
91 "https://pypi.python.org/packages/a2/3b/4756e6a0ceb14e084042a2a65c615d68d25621c6fd446d0fc10d14c4ce7d/certbot-0.8.1.tar.gz"))))))
93 (test-assert "pypi->guix-package"
94 ;; Replace network resources with sample data.
95 (mock ((guix import utils) url-fetch
96 (lambda (url file-name)
98 ("https://example.com/foo-1.0.0.tar.gz"
101 (with-output-to-file "foo-1.0.0/requirements.txt"
103 (display test-requirements)))
104 (system* "tar" "czvf" file-name "foo-1.0.0/")
105 (delete-file-recursively "foo-1.0.0")
106 (set! test-source-hash
107 (call-with-input-file file-name port-sha256))))
108 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
109 (_ (error "Unexpected URL: " url)))))
110 (mock ((guix http-client) http-fetch
113 ("https://pypi.python.org/pypi/foo/json"
114 (values (open-input-string test-json)
115 (string-length test-json)))
116 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
117 (_ (error "Unexpected URL: " url)))))
118 (match (pypi->guix-package "foo")
124 ('uri (string-append "https://example.com/foo-"
129 ('build-system 'python-build-system)
132 (("python-bar" ('unquote 'python-bar))
133 ("python-baz" ('unquote 'python-baz)))))
134 ('home-page "http://example.com")
135 ('synopsis "summary")
136 ('description "summary")
137 ('license 'license:lgpl2.0))
138 (string=? (bytevector->nix-base32-string
144 (test-skip (if (which "zip") 0 1))
145 (test-assert "pypi->guix-package, wheels"
146 ;; Replace network resources with sample data.
147 (mock ((guix import utils) url-fetch
148 (lambda (url file-name)
150 ("https://example.com/foo-1.0.0.tar.gz"
153 (with-output-to-file "foo-1.0.0/requirements.txt"
155 (display test-requirements)))
156 (system* "tar" "czvf" file-name "foo-1.0.0/")
157 (delete-file-recursively "foo-1.0.0")
158 (set! test-source-hash
159 (call-with-input-file file-name port-sha256))))
160 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl"
162 (mkdir "foo-1.0.0.dist-info")
163 (with-output-to-file "foo-1.0.0.dist-info/metadata.json"
165 (display test-metadata)))
166 (let ((zip-file (string-append file-name ".zip")))
167 ;; zip always adds a "zip" extension to the file it creates,
168 ;; so we need to rename it.
169 (system* "zip" zip-file "foo-1.0.0.dist-info/metadata.json")
170 (rename-file zip-file file-name))
171 (delete-file-recursively "foo-1.0.0.dist-info")))
172 (_ (error "Unexpected URL: " url)))))
173 (mock ((guix http-client) http-fetch
176 ("https://pypi.python.org/pypi/foo/json"
177 (values (open-input-string test-json)
178 (string-length test-json)))
179 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
180 (_ (error "Unexpected URL: " url)))))
181 (match (pypi->guix-package "foo")
187 ('uri (string-append "https://example.com/foo-"
192 ('build-system 'python-build-system)
195 (("python-bar" ('unquote 'python-bar))
196 ("python-baz" ('unquote 'python-baz)))))
197 ('home-page "http://example.com")
198 ('synopsis "summary")
199 ('description "summary")
200 ('license 'license:lgpl2.0))
201 (string=? (bytevector->nix-base32-string