blob: c6bbe8119a683e4b08999fe629b699463b37adac [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7def pypi_package(d):
8 bpn = d.getVar('BPN')
9 if bpn.startswith('python-'):
10 return bpn[7:]
11 elif bpn.startswith('python3-'):
12 return bpn[8:]
13 return bpn
14
Patrick Williams44b3caf2024-04-12 16:51:14 -050015# The PyPi package name (defaults to PN without the python3- prefix)
Patrick Williams92b42cb2022-09-03 06:53:57 -050016PYPI_PACKAGE ?= "${@pypi_package(d)}"
Patrick Williams44b3caf2024-04-12 16:51:14 -050017# The file extension of the source archive
Patrick Williams92b42cb2022-09-03 06:53:57 -050018PYPI_PACKAGE_EXT ?= "tar.gz"
Patrick Williams44b3caf2024-04-12 16:51:14 -050019# An optional prefix for the download file in the case of name collisions
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050020PYPI_ARCHIVE_NAME_PREFIX ?= ""
Patrick Williams92b42cb2022-09-03 06:53:57 -050021
22def pypi_src_uri(d):
Patrick Williams44b3caf2024-04-12 16:51:14 -050023 """
24 Construct a source URL as per https://warehouse.pypa.io/api-reference/integration-guide.html#predictable-urls.
25 """
Patrick Williams92b42cb2022-09-03 06:53:57 -050026 package = d.getVar('PYPI_PACKAGE')
Patrick Williams44b3caf2024-04-12 16:51:14 -050027 archive_name = d.expand('${PYPI_PACKAGE}-${PV}.${PYPI_PACKAGE_EXT}')
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050028 archive_downloadname = d.getVar('PYPI_ARCHIVE_NAME_PREFIX') + archive_name
29 return 'https://files.pythonhosted.org/packages/source/%s/%s/%s;downloadfilename=%s' % (package[0], package, archive_name, archive_downloadname)
Patrick Williams92b42cb2022-09-03 06:53:57 -050030
31PYPI_SRC_URI ?= "${@pypi_src_uri(d)}"
32
33HOMEPAGE ?= "https://pypi.python.org/pypi/${PYPI_PACKAGE}/"
34SECTION = "devel/python"
35SRC_URI:prepend = "${PYPI_SRC_URI} "
36S = "${WORKDIR}/${PYPI_PACKAGE}-${PV}"
37
Andrew Geissler220dafd2023-10-04 10:18:08 -050038# Replace any '_' characters in the pypi URI with '-'s to follow the PyPi website naming conventions
39UPSTREAM_CHECK_PYPI_PACKAGE ?= "${@d.getVar('PYPI_PACKAGE').replace('_', '-')}"
40UPSTREAM_CHECK_URI ?= "https://pypi.org/project/${UPSTREAM_CHECK_PYPI_PACKAGE}/"
41UPSTREAM_CHECK_REGEX ?= "/${UPSTREAM_CHECK_PYPI_PACKAGE}/(?P<pver>(\d+[\.\-_]*)+)/"
Patrick Williams92b42cb2022-09-03 06:53:57 -050042
43CVE_PRODUCT ?= "python:${PYPI_PACKAGE}"