Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | def 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 Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 15 | # The PyPi package name (defaults to PN without the python3- prefix) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 16 | PYPI_PACKAGE ?= "${@pypi_package(d)}" |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 17 | # The file extension of the source archive |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 18 | PYPI_PACKAGE_EXT ?= "tar.gz" |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 19 | # An optional prefix for the download file in the case of name collisions |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 20 | PYPI_ARCHIVE_NAME_PREFIX ?= "" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 21 | |
| 22 | def pypi_src_uri(d): |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 23 | """ |
| 24 | Construct a source URL as per https://warehouse.pypa.io/api-reference/integration-guide.html#predictable-urls. |
| 25 | """ |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 26 | package = d.getVar('PYPI_PACKAGE') |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 27 | archive_name = d.expand('${PYPI_PACKAGE}-${PV}.${PYPI_PACKAGE_EXT}') |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 28 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 30 | |
| 31 | PYPI_SRC_URI ?= "${@pypi_src_uri(d)}" |
| 32 | |
| 33 | HOMEPAGE ?= "https://pypi.python.org/pypi/${PYPI_PACKAGE}/" |
| 34 | SECTION = "devel/python" |
| 35 | SRC_URI:prepend = "${PYPI_SRC_URI} " |
| 36 | S = "${WORKDIR}/${PYPI_PACKAGE}-${PV}" |
| 37 | |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 38 | # Replace any '_' characters in the pypi URI with '-'s to follow the PyPi website naming conventions |
| 39 | UPSTREAM_CHECK_PYPI_PACKAGE ?= "${@d.getVar('PYPI_PACKAGE').replace('_', '-')}" |
| 40 | UPSTREAM_CHECK_URI ?= "https://pypi.org/project/${UPSTREAM_CHECK_PYPI_PACKAGE}/" |
| 41 | UPSTREAM_CHECK_REGEX ?= "/${UPSTREAM_CHECK_PYPI_PACKAGE}/(?P<pver>(\d+[\.\-_]*)+)/" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 42 | |
| 43 | CVE_PRODUCT ?= "python:${PYPI_PACKAGE}" |