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 | |
Patrick Williams | 96e4b4e | 2025-02-03 15:49:15 -0500 | [diff] [blame] | 31 | def pypi_normalize(d): |
| 32 | """" |
| 33 | Normalize the package names to match PEP625 (https://peps.python.org/pep-0625/). |
| 34 | For non-compliant packages, maintainers can set UPSTREAM_CHECK_PYPI_PACKAGE to override the normalization |
| 35 | """ |
| 36 | import re |
| 37 | return re.sub(r"[-_.]+", "-", d.getVar('PYPI_PACKAGE')).lower() |
| 38 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 39 | PYPI_SRC_URI ?= "${@pypi_src_uri(d)}" |
| 40 | |
| 41 | HOMEPAGE ?= "https://pypi.python.org/pypi/${PYPI_PACKAGE}/" |
| 42 | SECTION = "devel/python" |
| 43 | SRC_URI:prepend = "${PYPI_SRC_URI} " |
| 44 | S = "${WORKDIR}/${PYPI_PACKAGE}-${PV}" |
| 45 | |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 46 | # Replace any '_' characters in the pypi URI with '-'s to follow the PyPi website naming conventions |
Patrick Williams | 96e4b4e | 2025-02-03 15:49:15 -0500 | [diff] [blame] | 47 | UPSTREAM_CHECK_PYPI_PACKAGE ?= "${@pypi_normalize(d)}" |
| 48 | |
| 49 | # Use the simple repository API rather than the potentially unstable project URL |
| 50 | # More information on the pypi API specification is avaialble here: |
| 51 | # https://packaging.python.org/en/latest/specifications/simple-repository-api/ |
| 52 | # |
| 53 | # NOTE: All URLs for the simple API MUST request canonical normalized URLs per the spec |
| 54 | UPSTREAM_CHECK_URI ?= "https://pypi.org/simple/${@pypi_normalize(d)}" |
| 55 | UPSTREAM_CHECK_REGEX ?= "${UPSTREAM_CHECK_PYPI_PACKAGE}-(?P<pver>(\d+[\.\-_]*)+).(tar\.gz|tgz|zip|tar\.bz2)" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 56 | |
| 57 | CVE_PRODUCT ?= "python:${PYPI_PACKAGE}" |