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 ("python-setuptools" ('unquote 'python-setuptools)))))
135 ('home-page "http://example.com")
136 ('synopsis "summary")
137 ('description "summary")
138 ('license 'license:lgpl2.0))
139 (string=? (bytevector->nix-base32-string
145 (test-skip (if (which "zip") 0 1))
146 (test-assert "pypi->guix-package, wheels"
147 ;; Replace network resources with sample data.
148 (mock ((guix import utils) url-fetch
149 (lambda (url file-name)
151 ("https://pypi.python.org/pypi/foo/json"
152 (with-output-to-file file-name
154 (display test-json))))
155 ("https://example.com/foo-1.0.0.tar.gz"
158 (with-output-to-file "foo-1.0.0/requirements.txt"
160 (display test-requirements)))
161 (system* "tar" "czvf" file-name "foo-1.0.0/")
162 (delete-file-recursively "foo-1.0.0")
163 (set! test-source-hash
164 (call-with-input-file file-name port-sha256))))
165 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl"
167 (mkdir "foo-1.0.0.dist-info")
168 (with-output-to-file "foo-1.0.0.dist-info/metadata.json"
170 (display test-metadata)))
171 (let ((zip-file (string-append file-name ".zip")))
172 ;; zip always adds a "zip" extension to the file it creates,
173 ;; so we need to rename it.
174 (system* "zip" zip-file "foo-1.0.0.dist-info/metadata.json")
175 (rename-file zip-file file-name))
176 (delete-file-recursively "foo-1.0.0.dist-info")))
177 (_ (error "Unexpected URL: " url)))))
178 (match (pypi->guix-package "foo")
184 ('uri (string-append "https://example.com/foo-"
189 ('build-system 'python-build-system)
192 (("python-bar" ('unquote 'python-bar))
193 ("python-baz" ('unquote 'python-baz))
194 ("python-setuptools" ('unquote 'python-setuptools)))))
195 ('home-page "http://example.com")
196 ('synopsis "summary")
197 ('description "summary")
198 ('license 'license:lgpl2.0))
199 (string=? (bytevector->nix-base32-string