import: pypi: Improve license detection.

A lot of python packages are generated with an #f license, despite the
license being on pypi and in metadata.  Fix this.

* gnu/import/pypi.scm (find-license): Add procedure.
(make-pypi-sexp): Use procedure find-license.

Change-Id: Ia8e476f85a4b9193a0634de7a9bd66e40dcf2d44
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
This commit is contained in:
Nicolas Graves 2025-09-16 14:23:54 +02:00 committed by Sharlatan Hellseher
parent e1cc126ed7
commit 73fe38fd56
No known key found for this signature in database
GPG key ID: 76D727BFF62CD2B5

View file

@ -631,9 +631,8 @@ VERSION."
(description ,(and=> (non-empty-string-or-false
(project-info-summary info))
beautify-description))
(license ,(license->symbol
(string->license
(project-info-license info)))))
(license ,(find-license (project-info-license info)
(project-info-classifiers info))))
(map upstream-input-name (upstream-source-inputs source)))))
(define pypi->guix-package
@ -686,6 +685,17 @@ source. To build it from source, refer to the upstream repository at
("MPL 2.0" license:mpl2.0)
(_ #f)))
(define (find-license license classifiers)
(license->symbol
(string->license
(if (and license (string? license) (not (string= license "")))
license
(let* ((license-prefix "License :: OSI Approved :: ")
(license (find (cut string-prefix? license-prefix <>)
classifiers)))
(and license (not (null? license))
(string-drop license (string-length license-prefix))))))))
(define pypi-package?
(url-predicate
(lambda (url)