blob: b0bc167cdfa58ad4892b448e4c43d868ad7401e4 [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
Patrick Williams96e4b4e2025-02-03 15:49:15 -050031def 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 Williams92b42cb2022-09-03 06:53:57 -050039PYPI_SRC_URI ?= "${@pypi_src_uri(d)}"
40
41HOMEPAGE ?= "https://pypi.python.org/pypi/${PYPI_PACKAGE}/"
42SECTION = "devel/python"
43SRC_URI:prepend = "${PYPI_SRC_URI} "
44S = "${WORKDIR}/${PYPI_PACKAGE}-${PV}"
45
Andrew Geissler220dafd2023-10-04 10:18:08 -050046# Replace any '_' characters in the pypi URI with '-'s to follow the PyPi website naming conventions
Patrick Williams96e4b4e2025-02-03 15:49:15 -050047UPSTREAM_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
54UPSTREAM_CHECK_URI ?= "https://pypi.org/simple/${@pypi_normalize(d)}"
55UPSTREAM_CHECK_REGEX ?= "${UPSTREAM_CHECK_PYPI_PACKAGE}-(?P<pver>(\d+[\.\-_]*)+).(tar\.gz|tgz|zip|tar\.bz2)"
Patrick Williams92b42cb2022-09-03 06:53:57 -050056
57CVE_PRODUCT ?= "python:${PYPI_PACKAGE}"