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-equal "guix-package->pypi-name, old URL style"
78 (guix-package->pypi-name
82 "https://pypi.io/packages/source/p/psutil/psutil-4.3.0.tar.gz"))))))
84 (test-equal "guix-package->pypi-name, new URL style"
86 (guix-package->pypi-name
90 "https://pypi.python.org/packages/a2/3b/4756e6a0ceb14e084042a2a65c615d68d25621c6fd446d0fc10d14c4ce7d/certbot-0.8.1.tar.gz"))))))
92 (test-assert "pypi->guix-package"
93 ;; Replace network resources with sample data.
94 (mock ((guix import utils) url-fetch
95 (lambda (url file-name)
97 ("https://pypi.python.org/pypi/foo/json"
98 (with-output-to-file file-name
100 (display test-json))))
101 ("https://example.com/foo-1.0.0.tar.gz"
104 (with-output-to-file "foo-1.0.0/requirements.txt"
106 (display test-requirements)))
107 (system* "tar" "czvf" file-name "foo-1.0.0/")
108 (delete-file-recursively "foo-1.0.0")
109 (set! test-source-hash
110 (call-with-input-file file-name port-sha256))))
111 ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
112 (_ (error "Unexpected URL: " url)))))
113 (match (pypi->guix-package "foo")
119 ('uri (string-append "https://example.com/foo-"
124 ('build-system 'python-build-system)
127 (("python-bar" ('unquote 'python-bar))
128 ("python-baz" ('unquote 'python-baz))
129 ("python-setuptools" ('unquote 'python-setuptools)))))
130 ('home-page "http://example.com")
131 ('synopsis "summary")
132 ('description "summary")
134 (string=? (bytevector->nix-base32-string
140 (test-skip (if (which "zip") 0 1))
141 (test-assert "pypi->guix-package, wheels"
142 ;; Replace network resources with sample data.
143 (mock ((guix import utils) url-fetch
144 (lambda (url file-name)
146 ("https://pypi.python.org/pypi/foo/json"
147 (with-output-to-file file-name
149 (display test-json))))
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 (match (pypi->guix-package "foo")
179 ('uri (string-append "https://example.com/foo-"
184 ('build-system 'python-build-system)
187 (("python-bar" ('unquote 'python-bar))
188 ("python-baz" ('unquote 'python-baz))
189 ("python-setuptools" ('unquote 'python-setuptools)))))
190 ('home-page "http://example.com")
191 ('synopsis "summary")
192 ('description "summary")
194 (string=? (bytevector->nix-base32-string