import: pypi: Honor the 'upstream-name' package property.

Previously, when a PyPI package had a “-” followed by one or more digits in
its name, e.g., “AV-98”, the importer would interpret “98” as the version of
the package and thus mistake the “AV-98” package for the “av” package on PyPI.

  $ ./pre-inst-env guix refresh av-98
  following redirection to `https://pypi.org/pypi/av/json'...
  /home/yoctocell/src/guix/gnu/packages/web-browsers.scm:914:13: av-98 would be upgraded from 1.0.1 to 8.0.3

Setting the ‘upstream-name’ property to “AV-98” would solve the problem.

  $ ./pre-inst-env guix refresh av-98
  /home/yoctocell/src/guix/gnu/packages/web-browsers.scm:914:13: 1.0.1 is already the latest version of av-98

* guix/import/pypi.scm (guix-package->pypi-name): Honor ‘upstream-name’
property.
(make-pypi-sexp): Set ‘upstream-name’ property when appropriate.
* tests/pypi.scm (test-json): Rename to ...
(test-json-1): ... this.
(test-json-2): New variable
("guix-package->pypi-name, honor 'upstream-name'"): New test.
("pypi->guix-package, package name contains \"-\" followed by digits"):
Likewise.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Xinglu Chen 2021-09-27 22:11:20 +02:00 committed by Ludovic Courtès
parent e29c3e1856
commit 7b75f90c5b
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 113 additions and 13 deletions

View file

@ -9,6 +9,7 @@
;;; Copyright © 2020 Lars-Dominik Braun <ldb@leibniz-psychology.org>
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;;
;;; This file is part of GNU Guix.
;;;
@ -163,12 +164,13 @@ package on PyPI."
(hyphen-package-name->name+version
(basename (file-sans-extension url))))
(match (and=> (package-source package) origin-uri)
((? string? url)
(url->pypi-name url))
((lst ...)
(any url->pypi-name lst))
(#f #f)))
(or (assoc-ref (package-properties package) 'upstream-name)
(match (and=> (package-source package) origin-uri)
((? string? url)
(url->pypi-name url))
((lst ...)
(any url->pypi-name lst))
(#f #f))))
(define (wheel-url->extracted-directory wheel-url)
(match (string-split (basename wheel-url) #\-)
@ -423,6 +425,11 @@ return the unaltered list of upstream dependency names."
description license)
"Return the `package' s-expression for a python package with the given NAME,
VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(define (maybe-upstream-name name)
(if (string-match ".*\\-[0-9]+" (pk name))
`((properties ,`'(("upstream-name" . ,name))))
'()))
(call-with-temporary-output-file
(lambda (temp port)
(and (url-fetch source-url temp)
@ -461,6 +468,7 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE."
(sha256
(base32
,(guix-hash-url temp)))))
,@(maybe-upstream-name name)
(build-system python-build-system)
,@(maybe-inputs required-inputs 'propagated-inputs)
,@(maybe-inputs native-inputs 'native-inputs)