From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kFfGEKUv8GEFNwAAgWs5BA (envelope-from ) for ; Tue, 25 Jan 2022 18:13:09 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id GKt6DaUv8GFFYwEAauVa8A (envelope-from ) for ; Tue, 25 Jan 2022 18:13:09 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7709C3FC4A for ; Tue, 25 Jan 2022 18:13:07 +0100 (CET) Received: from localhost ([::1]:52944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCPNS-0001Si-M6 for larch@yhetil.org; Tue, 25 Jan 2022 12:13:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCP60-00022f-1e for guix-patches@gnu.org; Tue, 25 Jan 2022 11:55:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:57012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nCP5y-00023l-CH for guix-patches@gnu.org; Tue, 25 Jan 2022 11:55:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nCP5y-0001CR-7W for guix-patches@gnu.org; Tue, 25 Jan 2022 11:55:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53395] Fix pypi import for flake8-array-spacing Resent-From: Vivien Kraus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 25 Jan 2022 16:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53395 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 53395@debbugs.gnu.org Received: via spool by 53395-submit@debbugs.gnu.org id=B53395.16431296864585 (code B ref 53395); Tue, 25 Jan 2022 16:55:02 +0000 Received: (at 53395) by debbugs.gnu.org; 25 Jan 2022 16:54:46 +0000 Received: from localhost ([127.0.0.1]:49915 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCP5h-0001Bs-Dv for submit@debbugs.gnu.org; Tue, 25 Jan 2022 11:54:46 -0500 Received: from planete-kraus.eu ([89.234.140.182]:39034) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCP5b-0001Bd-VZ for 53395@debbugs.gnu.org; Tue, 25 Jan 2022 11:54:44 -0500 Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id 6f6fd4c5; Tue, 25 Jan 2022 16:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=dkim; bh=xgEEppXEfvv1XHWCxJg/fmXGg 4k=; b=ZcR305VmoT4BAn1krWLKKWKKBgpFhbSXvrVOL8tkgW+YyPkBWdB65eGt2 KGNd1n+jeRnOviZfymNB+eNncFPGYKxL22q5w6Zns6UbiPx8SZyxpn+qMyI8K/a9 bU0dsiiq9PHE7l58G0cgRmWy5kXOSW6Pj0S7DLWbV2xOy/Iog0= Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id 8505303b (TLSv1.3:AEAD-CHACHA20-POLY1305-SHA256:256:NO); Tue, 25 Jan 2022 16:54:12 +0000 (UTC) References: <87czkmi434.fsf@planete-kraus.eu> <87ee4xut38.fsf@gnu.org> <87mtjk22rn.fsf@planete-kraus.eu> <87y234lzqu.fsf@gnu.org> User-agent: mu4e 1.6.10; emacs 27.2 Date: Tue, 25 Jan 2022 17:39:54 +0100 In-reply-to: <87y234lzqu.fsf@gnu.org> Message-ID: <87ee4v21u6.fsf@planete-kraus.eu> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Vivien Kraus X-ACL-Warn: , Vivien Kraus via Guix-patches From: Vivien Kraus via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643130788; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=z/flP7dGtFh/7/3ijl49SU/KK2CRlgHI3FofwkzG4iM=; b=McXLBW0g08x/iSJXXIKNVpKV5a9mGzrOmZA667dAfk62WezhOm4fROhm2ePbsAO1O9vT8M lMZOqs0A2HQTQ5mJElcD8bT3zw6R8AgNN0gQNt/qLToTY8Q81v19zWVpTeN8sJaHl1nNnr UxAYbZaAsyWY81dCB2Qrc5WCah9BBM4zIEC7iGovVUfSetuBRgNYBTfaeEiewiD69DuRF7 whdIPXNsaVSXZyMpoZxA1KI9gRLrr5ep0n70hM7OXT7I7iylNJp87TvcY0hLmRWTDJoZ26 tcEkADPwAtwJhX9/j3qjH3R5GZ2jBm3S6rPez92mUsdWv3iVzQFXItmjFu75SA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643130788; a=rsa-sha256; cv=none; b=XniwxsTlvlRg7FLi4MIQbJ1TB2MLtbqMHf49c2LKq2yFX8gSoKKuFrZSmHPFMmRDB33cCn 8VnmFV203ykiTarH21Zb51hSPC44Pb21o0RaIkMMEQBGxUgckNzeYU7HCm89+l2ofMrFOq JzIrFIfIlcgGRkOU7adqs8Jb7towYs8DTer4MFRJSzv4BHKZ4VTpl/isQhU7UUbHPts7ki MrC4zMk+pzLhl+3zQT2nSH7uIckBplsjPNUH0DLus4FfjvYuaTg/BGlr19lyVov2VzWlpy eBri6u+OYMVZPLWffIm8JHINHwAzDEDfnRRPaPg8kMZGks6W7L15ACpByiTjHQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=dkim header.b=ZcR305Vm; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -6.23 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=dkim header.b=ZcR305Vm; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 7709C3FC4A X-Spam-Score: -6.23 X-Migadu-Scanner: scn0.migadu.com X-TUID: vVgZHk8UplQg --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Here we go! Ludovic Court=C3=A8s writes: > Yes, just one =E2=80=98display-hint=E2=80=99 call, using complete sentenc= es and > paragraphs. The text should provide an explanation and more importantly > a hint as to what can done, like =E2=80=9CThe generated package definitio= n might > be wrong; please double-check =E2=80=A6=E2=80=9D. I made a new version for that. > > You can avoid @strong though, because it doesn=E2=80=99t do > anything useful. Okay. > >> + (warning >> + (G_ "The project name does not appear verbatim in the pypi URI= ~%")) > > I=E2=80=99d make it: > > "project name ~a does not appear verbatim in the PyPI URI~%" Changed. > >>> Also, what about adding a unit test? > > [...] > >> +(test-equal "If the package goo is released as foo, the importer warns" >> + "warning: The project name does not appear verbatim in the pypi URI >> +hint: The project name is: *goo* >> + >> +hint: The pypi URI is: *`https://example.com/foo-1.0.0.tar.gz'* >> + >> +hint: The pypi-uri declaration in the generated package might need to b= e changed. >> + >> +" >> + (call-with-output-string >> + (lambda (port) >> + (parameterize ((guix-warning-port port) >> + (current-error-port port)) >> + ;; Replace network resources with sample data. >> + (mock ((guix import utils) url-fetch >> + (lambda (url file-name) >> + (match url > > These two tests are really integration tests: they exercise the whole > shebang. I was thinking about having a unit test of just > =E2=80=98find-project-url=E2=80=99, which is less work (and maintenance := -)) and may be > good enough. Let=E2=80=99s do both! If you don=E2=80=99t want the integration tests, jus= t delete them (now or when maintenance becomes too demanding). > > Perhaps you can also change one of the existing python-foo tests to > exercise this bit, for instance by making it =E2=80=9CFoo=E2=80=9D. I added a test function that can be used by all integration tests. It=E2=80= =99s not perfect (there=E2=80=99s still a lot of code copied from test to test, = and I=E2=80=99m not innocent there too) but I don=E2=80=99t want to change the = other tests beyond trivial things. Vivien --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-pypi-importer-Convert-to-_-in-pypi-urls-if-needed.patch Content-Transfer-Encoding: quoted-printable Content-Description: Fix an edge case in the pypi importer, and push more tests From=208792367617d288e584a703db38c82c749a067c26 Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Thu, 20 Jan 2022 20:11:56 +0100 Subject: [PATCH] pypi importer: Convert - to _ in pypi urls if needed. * guix/import/pypi.scm (find-project-url): New function. (make-pypi-sexp): Use find-project-url. * tests/pypi.scm ("Package Foo has a correct pypi-uri of foo"): New test. ("If the package goo is released as foo, the importer warns"): New test. =2D-- guix/import/pypi.scm | 30 ++-- tests/pypi.scm | 337 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 305 insertions(+), 62 deletions(-) diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index b4284f5c33..8245ed6348 100644 =2D-- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm @@ -41,6 +41,7 @@ (define-module (guix import pypi) #:use-module (guix memoization) #:use-module (guix diagnostics) #:use-module (guix i18n) + #:use-module ((guix ui) #:select (display-hint)) #:use-module ((guix build utils) #:select ((package-name->name+version . hyphen-package-name->name+version) @@ -59,6 +60,7 @@ (define-module (guix import pypi) specification->requirement-name guix-package->pypi-name pypi-recursive-import + find-project-url pypi->guix-package %pypi-updater)) =20 @@ -418,6 +420,24 @@ (define process-requirements (values (map process-requirements dependencies) (concatenate dependencies)))) =20 +(define (find-project-url name pypi-url) + "Try different project name substitution until the result is found in +pypi-uri. Downcase is required for \"uWSGI\", and +underscores are required for flake8-array-spacing." + (or (find (cut string-contains pypi-url <>) + (list name + (string-downcase name) + (string-replace-substring name "-" "_"))) + (begin + (warning + (G_ "project name ~a does not appear verbatim in the PyPI URI~%") + name) + (display-hint + (format #f (G_ "The PyPI URI is: @url{~a}. You should review the +pypi-uri declaration in the generated package. You may need to replace ~s = with +a substring of the PyPI URI that identifies the package.") pypi-url name)) +name))) + (define (make-pypi-sexp name version source-url wheel-url home-page synops= is description license) "Return the `package' s-expression for a python package with the given N= AME, @@ -446,15 +466,7 @@ (define (maybe-upstream-name name) (origin (method url-fetch) (uri (pypi-uri =2D ;; PyPI URL are case sensitive, but sometim= es =2D ;; a project named using mixed case has a U= RL =2D ;; using lower case, so we must work around= this =2D ;; inconsistency. For actual examples, com= pare =2D ;; the URLs of the "Deprecated" and "uWSGI"= PyPI =2D ;; packages. =2D ,(if (string-contains source-url name) =2D name =2D (string-downcase name)) + ,(find-project-url name source-url) version ;; Some packages have been released as `.zip` ;; instead of the more common `.tar.gz`. For diff --git a/tests/pypi.scm b/tests/pypi.scm index 1ea5f02643..b1647ac0a7 100644 =2D-- a/tests/pypi.scm +++ b/tests/pypi.scm @@ -23,68 +23,57 @@ (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) =2D #: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-no= ne-any.whl" + (or name-in-url name))) + (packagetype . "bdist_wheel"))))))))) =20 (define test-json-1 =2D "{ =2D \"info\": { =2D \"version\": \"1.0.0\", =2D \"name\": \"foo\", =2D \"license\": \"GNU LGPL\", =2D \"summary\": \"summary\", =2D \"home_page\": \"http://example.com\", =2D \"classifiers\": [], =2D \"download_url\": \"\" =2D }, =2D \"urls\": [], =2D \"releases\": { =2D \"1.0.0\": [ =2D { =2D \"url\": \"https://example.com/foo-1.0.0.egg\", =2D \"packagetype\": \"bdist_egg\" =2D }, { =2D \"url\": \"https://example.com/foo-1.0.0.tar.gz\", =2D \"packagetype\": \"sdist\" =2D }, { =2D \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\", =2D \"packagetype\": \"bdist_wheel\" =2D } =2D ] =2D } =2D}") + (foo-json)) =20 (define test-json-2 =2D "{ =2D \"info\": { =2D \"version\": \"1.0.0\", =2D \"name\": \"foo-99\", =2D \"license\": \"GNU LGPL\", =2D \"summary\": \"summary\", =2D \"home_page\": \"http://example.com\", =2D \"classifiers\": [], =2D \"download_url\": \"\" =2D }, =2D \"urls\": [], =2D \"releases\": { =2D \"1.0.0\": [ =2D { =2D \"url\": \"https://example.com/foo-99-1.0.0.egg\", =2D \"packagetype\": \"bdist_egg\" =2D }, { =2D \"url\": \"https://example.com/foo-99-1.0.0.tar.gz\", =2D \"packagetype\": \"sdist\" =2D }, { =2D \"url\": \"https://example.com/foo-99-1.0.0-py2.py3-none-any.whl= \", =2D \"packagetype\": \"bdist_wheel\" =2D } =2D ] =2D } =2D}") + (foo-json #:name "foo-99")) + +(define test-json-3 + (foo-json #:name "Foo" #:name-in-url "foo")) + +(define test-json-4 + (foo-json #:name "foo-bar" #:name-in-url "foo_bar")) + +(define test-json-5 + (foo-json #:name "foo" #:name-in-url "goo")) =20 (define test-source-hash "") @@ -211,6 +200,30 @@ (define test-metadata-with-extras-jedi "\ call-with-input-string) (parse-wheel-metadata test-metadata-with-extras-jedi))) =20 +(test-equal "find-project-url, with numpy" + "numpy" + (find-project-url + "numpy" + "https://files.pythonhosted.org/packages/0a/c8/a62767a6b374a0dfb02d2a04= 56e5f56a372cdd1689dbc6ffb6bf1ddedbc0/numpy-1.22.1.zip")) + +(test-equal "find-project-url, uWSGI" + "uwsgi" + (find-project-url + "uWSGI" + "https://files.pythonhosted.org/packages/24/fd/93851e4a076719199868d4c9= 18cc93a52742e68370188c1c570a6e42a54f/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/ff29b901128b681b7de7a278= 7b3aeb3e1f3cba4a8c0cffa9712cbff016bc/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 @@ -428,4 +441,222 @@ (define test-metadata-with-extras-jedi "\ (x (pk 'fail x #f)))))) =20 +(test-equal "pypi->guix-package, package name is capitalized but not in do= wnload URI (like uWSGI)" + ;; Checking that the importer doesn=E2=80=99t emit a warning + "" + (call-with-output-string + (lambda (port) + (parameterize ((guix-warning-port port)) + ;; Replace network resources with sample data. + (mock ((guix import utils) url-fetch + (lambda (url file-name) + (match url + ;; Package Foo has /foo- download URLs + ("https://example.com/foo-1.0.0.tar.gz" + (begin + (mkdir-p "foo-1.0.0/foo.egg-info") + (with-output-to-file "foo-1.0.0/foo.egg-info/require= s.txt" + (lambda () + (display test-requires.txt))) + (parameterize ((current-output-port (%make-void-port= "rw+"))) + (system* "tar" "czvf" file-name "foo-1.0.0/")) + (delete-file-recursively "foo-1.0.0"))) + ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" + (begin + (mkdir "foo-1.0.0.dist-info") + (with-output-to-file "foo-1.0.0.dist-info/METADATA" + (lambda () + (display test-metadata))) + (let ((zip-file (string-append file-name ".zip"))) + ;; zip always adds a "zip" extension to the file i= t creates, + ;; so we need to rename it. + (system* "zip" "-q" zip-file "foo-1.0.0.dist-info/= METADATA") + (rename-file zip-file file-name)) + (delete-file-recursively "foo-1.0.0.dist-info"))) + (_ (error "Unexpected URL: " url))))) + (mock ((guix http-client) http-fetch + (lambda (url . rest) + (match url + ;; Note that the project name is Foo, so the proj= ect + ;; URL queried by the importer is /pypi/Foo/json + ("https://pypi.org/pypi/Foo/json" + (values (open-input-string test-json-3) + (string-length test-json-3))) + ("https://example.com/foo-1.0.0-py2.py3-none-any.= whl" #f) + (_ (error "Unexpected URL: " url))))) + (match (pypi->guix-package "Foo") + (('package + ('name "python-foo") ;; The guix package name is + ;; computed from the pypi + ;; project name: Foo -> foo = -> + ;; python-foo + ('version "1.0.0") + ('source ('origin + ('method 'url-fetch) + ;; If the importer were too simple, it + ;; would have put '(pypi-uri "Foo" + ;; 'version) here, but as indicated by + ;; test-json-4, the package releases a= re + ;; usually published with /foo- URLs, = so + ;; we would get a 404 Not Found respon= se + ;; when building the package. + ('uri ('pypi-uri "foo" 'version)) + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'python-build-system) + ('propagated-inputs ('list 'python-bar 'python-ba= z)) + ('native-inputs ('list 'python-pytest)) + ('home-page "http://example.com") + ('synopsis "summary") + ('description "summary") + ('license 'license:lgpl2.0)) + (string=3D? (bytevector->nix-base32-string + test-source-hash) + hash)) + (x + (error "Failed: ~S" x))))))))) + +(test-equal "pypi->guix-package, package name is kebab-case but the downlo= ad URI is snake_case (like flake8-array-spacing)" + ;; This test is similar to the previous one + "" + (call-with-output-string + (lambda (port) + (parameterize ((guix-warning-port port)) + ;; Replace network resources with sample data. + (mock ((guix import utils) url-fetch + (lambda (url file-name) + ;; Everything is foo_bar here: + (match url + ("https://example.com/foo_bar-1.0.0.tar.gz" + (begin + (mkdir-p "foo_bar-1.0.0/foo_bar.egg-info") + (with-output-to-file "foo_bar-1.0.0/foo_bar.egg-info= /requires.txt" + (lambda () + (display test-requires.txt))) + (parameterize ((current-output-port (%make-void-port= "rw+"))) + (system* "tar" "czvf" file-name "foo_bar-1.0.0/")) + (delete-file-recursively "foo_bar-1.0.0"))) + ("https://example.com/foo_bar-1.0.0-py2.py3-none-any.wh= l" + (begin + (mkdir "foo_bar-1.0.0.dist-info") + (with-output-to-file "foo_bar-1.0.0.dist-info/METADA= TA" + (lambda () + (display test-metadata))) + (let ((zip-file (string-append file-name ".zip"))) + ;; zip always adds a "zip" extension to the file i= t creates, + ;; so we need to rename it. + (system* "zip" "-q" zip-file "foo_bar-1.0.0.dist-i= nfo/METADATA") + (rename-file zip-file file-name)) + (delete-file-recursively "foo_bar-1.0.0.dist-info"))) + (_ (error "Unexpected URL: " url))))) + (mock ((guix http-client) http-fetch + (lambda (url . rest) + (match url + ("https://pypi.org/pypi/foo-bar/json" ; (!) + (values (open-input-string test-json-4) + (string-length test-json-4))) + ("https://example.com/foo_bar-1.0.0-py2.py3-none-= any.whl" #f) + (_ (error "Unexpected URL: " url))))) + (match (pypi->guix-package "foo-bar") + (('package + ('name "python-foo-bar") + ('version "1.0.0") + ('source ('origin + ('method 'url-fetch) + ('uri ('pypi-uri "foo_bar" 'version)) + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'python-build-system) + ('propagated-inputs ('list 'python-bar 'python-ba= z)) + ('native-inputs ('list 'python-pytest)) + ('home-page "http://example.com") + ('synopsis "summary") + ('description "summary") + ('license 'license:lgpl2.0)) + (string=3D? (bytevector->nix-base32-string + test-source-hash) + hash)) + (x + (error "Failed: ~S" x))))))))) + +(test-equal "pypi->guix-package, package name is foo but the download URI = uses goo" + ;; A warning should be emitted with a hint about the issue + "warning: project name foo does not appear verbatim in the PyPI URI +hint: The PyPI URI is: `https://example.com/goo-1.0.0.tar.gz'. You should= review the pypi-uri +declaration in the generated package. You may need to replace \"foo\" wit= h a substring of the PyPI +URI that identifies the package. + +" + (call-with-output-string + (lambda (port) + (parameterize ((guix-warning-port port) + (current-error-port port)) + ;; Replace network resources with sample data. + (mock ((guix import utils) url-fetch + (lambda (url file-name) + (match url + ("https://example.com/goo-1.0.0.tar.gz" + (begin + (mkdir-p "goo-1.0.0/goo.egg-info/") + (with-output-to-file "goo-1.0.0/goo.egg-info/require= s.txt" + (lambda () + (display "wrong data to make sure we're testing = wheels "))) + (parameterize ((current-output-port (%make-void-port= "rw+"))) + (system* "tar" "czvf" file-name "goo-1.0.0/")) + (delete-file-recursively "goo-1.0.0") + (set! test-source-hash + (call-with-input-file file-name port-sha256)))) + ("https://example.com/goo-1.0.0-py2.py3-none-any.whl" + (begin + (mkdir "goo-1.0.0.dist-info") + (with-output-to-file "goo-1.0.0.dist-info/METADATA" + (lambda () + (display test-metadata))) + (let ((zip-file (string-append file-name ".zip"))) + ;; zip always adds a "zip" extension to the file i= t creates, + ;; so we need to rename it. + (system* "zip" "-q" zip-file "goo-1.0.0.dist-info/= METADATA") + (rename-file zip-file file-name)) + (delete-file-recursively "goo-1.0.0.dist-info"))) + (_ (error "Unexpected URL: " url))))) + (mock ((guix http-client) http-fetch + (lambda (url . rest) + (match url + ("https://pypi.org/pypi/foo/json" + (values (open-input-string test-json-5) + (string-length test-json-5))) + ("https://example.com/goo-1.0.0-py2.py3-none-any.= whl" #f) + (_ (error "Unexpected URL: " url))))) + ;; Not clearing the memoization cache here would mean = returning the value + ;; computed in the previous test. + (invalidate-memoization! pypi->guix-package) + (match (pypi->guix-package "foo") + (('package + ('name "python-foo") + ('version "1.0.0") + ('source ('origin + ('method 'url-fetch) + ;; The importer can=E2=80=99t guess th= at we should + ;; replace with '(pypi-uri "goo" + ;; 'version), so it defaults to "foo" = with + ;; a warning. + ('uri ('pypi-uri "foo" 'version)) + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'python-build-system) + ('propagated-inputs ('list 'python-bar 'python-ba= z)) + ('native-inputs ('list 'python-pytest)) + ('home-page "http://example.com") + ('synopsis "summary") + ('description "summary") + ('license 'license:lgpl2.0)) + (string=3D? (bytevector->nix-base32-string + test-source-hash) + hash)) + (x + (error "Failed: ~S" x))))))))) + (test-end "pypi") =2D-=20 2.34.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCAAdFiEEq4yIHjMvkliPpwQnO7C8EjLYuCwFAmHwKzEACgkQO7C8EjLY uCyHywwAgxzKM/qvom+KBcAaV4Oe2s1DUHVY0CBMttUWdu4vcJVce8GSuLzRVIgi DZoZLFNT/WKe6Pw4EjphDyz9AzKgOAkgqF0I2w1NBHJS7BZ2Yuvt4mR0erAaArFs nttInBvGLOirfgbyKHcJ7pSBjm8RYVz9wV+m6Jl4Y+HsYu/yU/3TdLEYdPA7iVl5 L46UI3owFCTa+9QUTS2W69PSxnz2gwuZ83A6LrDo6DuQV+nBhDXnvzkSsCrfbOYv ifoLV+Jm+YwszF3BQ2adLDm2NTUAmxDbqxZXi5Z54ElgbiEXTsGqXiivE0c5ty+p bttmSKNRIMcujvn4jJlPypKyYwt96QSrtGU43VleqffXAuOsXmfdnbZVhyWa6nDY ne+D6Sx9EkX9XtgO4iGd9O7zJZuiaeBi/jCsXdJKGCyS4scOn2DjEY2inWjo+vW9 R7rNYfr05P9HQuMbjqlYtvOcY3dvRP5h3MxltSanfbRoXYfdlAbxMzGIAIWOPNZ+ Fu9mOBaD =YASa -----END PGP SIGNATURE----- --==-=-=--