From bac9f8302c65802a576f733cc48829edb33019d8 Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Thu, 20 Jan 2022 20:11:56 +0100 Subject: import: pypi: Convert hyphens to underscores in PyPI URLs if needed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/pypi.scm (find-project-url): New function. (make-pypi-sexp): Use find-project-url. * tests/pypi.scm (foo-json): New procedure. (test-json-1, test-json-2): Define in terms of it. ("find-project-url, with numpy", "find-project-url, uWSGI"): ("find-project-url, flake8-array-spacing") ("find-project-url, foo/goo"): New tests. Co-authored-by: Ludovic Courtès --- tests/pypi.scm | 111 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 53 deletions(-) (limited to 'tests') diff --git a/tests/pypi.scm b/tests/pypi.scm index 1ea5f02643..47a276ae58 100644 --- a/tests/pypi.scm +++ b/tests/pypi.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2016 Ricardo Wurmus ;;; Copyright © 2019 Maxim Cournoyer ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Vivien Kraus ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,68 +24,48 @@ (define-module (test-pypi) #:use-module (guix import pypi) #:use-module (guix base32) #:use-module (guix memoization) + #:use-module (guix utils) #:use-module (gcrypt hash) #:use-module (guix tests) #:use-module (guix build-system python) #:use-module ((guix build utils) #:select (delete-file-recursively which mkdir-p)) + #:use-module ((guix diagnostics) #:select (guix-warning-port)) + #:use-module (json) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-64) - #:use-module (ice-9 match)) + #:use-module (ice-9 match) + #:use-module (ice-9 optargs)) + +(define* (foo-json #:key (name "foo") (name-in-url #f)) + "Create a JSON description of an example pypi package, named @var{name}, +optionally using a different @var{name in its URL}." + (scm->json-string + `((info + . ((version . "1.0.0") + (name . ,name) + (license . "GNU LGPL") + (summary . "summary") + (home_page . "http://example.com") + (classifiers . #()) + (download_url . ""))) + (urls . #()) + (releases + . ((1.0.0 + . #(((url . ,(format #f "https://example.com/~a-1.0.0.egg" + (or name-in-url name))) + (packagetype . "bdist_egg")) + ((url . ,(format #f "https://example.com/~a-1.0.0.tar.gz" + (or name-in-url name))) + (packagetype . "sdist")) + ((url . ,(format #f "https://example.com/~a-1.0.0-py2.py3-none-any.whl" + (or name-in-url name))) + (packagetype . "bdist_wheel"))))))))) (define test-json-1 - "{ - \"info\": { - \"version\": \"1.0.0\", - \"name\": \"foo\", - \"license\": \"GNU LGPL\", - \"summary\": \"summary\", - \"home_page\": \"http://example.com\", - \"classifiers\": [], - \"download_url\": \"\" - }, - \"urls\": [], - \"releases\": { - \"1.0.0\": [ - { - \"url\": \"https://example.com/foo-1.0.0.egg\", - \"packagetype\": \"bdist_egg\" - }, { - \"url\": \"https://example.com/foo-1.0.0.tar.gz\", - \"packagetype\": \"sdist\" - }, { - \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\", - \"packagetype\": \"bdist_wheel\" - } - ] - } -}") + (foo-json)) (define test-json-2 - "{ - \"info\": { - \"version\": \"1.0.0\", - \"name\": \"foo-99\", - \"license\": \"GNU LGPL\", - \"summary\": \"summary\", - \"home_page\": \"http://example.com\", - \"classifiers\": [], - \"download_url\": \"\" - }, - \"urls\": [], - \"releases\": { - \"1.0.0\": [ - { - \"url\": \"https://example.com/foo-99-1.0.0.egg\", - \"packagetype\": \"bdist_egg\" - }, { - \"url\": \"https://example.com/foo-99-1.0.0.tar.gz\", - \"packagetype\": \"sdist\" - }, { - \"url\": \"https://example.com/foo-99-1.0.0-py2.py3-none-any.whl\", - \"packagetype\": \"bdist_wheel\" - } - ] - } -}") + (foo-json #:name "foo-99")) (define test-source-hash "") @@ -211,6 +192,30 @@ (define test-metadata-with-extras-jedi "\ call-with-input-string) (parse-wheel-metadata test-metadata-with-extras-jedi))) +(test-equal "find-project-url, with numpy" + "numpy" + (find-project-url + "numpy" + "https://files.pythonhosted.org/packages/0a/c8/a62767a6b374a0dfb02d2a0456e5f56a372cdd1689dbc6ffb6bf1ddedbc0/numpy-1.22.1.zip")) + +(test-equal "find-project-url, uWSGI" + "uwsgi" + (find-project-url + "uWSGI" + "https://files.pythonhosted.org/packages/24/fd/93851e4a076719199868d4c918cc93a52742e68370188c1c570a6e42a54f/uwsgi-2.0.20.tar.gz")) + +(test-equal "find-project-url, flake8-array-spacing" + "flake8_array_spacing" + (find-project-url + "flake8-array-spacing" + "https://files.pythonhosted.org/packages/a4/21/ff29b901128b681b7de7a2787b3aeb3e1f3cba4a8c0cffa9712cbff016bc/flake8_array_spacing-0.2.0.tar.gz")) + +(test-equal "find-project-url, foo/goo" + "foo" + (find-project-url + "foo" + "https://files.pythonhosted.org/packages/f0/f00/goo-0.0.0.tar.gz")) + (test-assert "pypi->guix-package, no wheel" ;; Replace network resources with sample data. (mock ((guix import utils) url-fetch -- cgit v1.2.3