diff mbox series

[v2,4/4] pypi: improve upstream check regex

Message ID 20260904133815.778303-4-ross.burton@arm.com
State Accepted, archived
Commit d6a3f68e1967f3fbc4aed027513a89cc2196fe24
Headers show
Series [v2,1/4] python/*: remove spurious CLEANBROKENs | expand

Commit Message

Ross Burton Sept. 4, 2026, 1:38 p.m. UTC
Currently the upstream release checker fetches the Simple API release
index which lists all of the uploaded files.  However the naming rules
have evolved over time[1] so matching the value of PYPI_PACKAGE fails if
the sdist filename was not normalised but then is normalised.

Remove UPSTREAM_CHECK_PYPI_PACKAGE which is realistically unused[2] and
instead transform the PYPI_PACKAGE into a regular expression that
handles both - and _ being used in the filename.

Change the version number match so that it handles .postN suffixes, as
defined in the Version Specifiers documentation[3]. We don't want to
match any alphanumeric characters as this would also match development
snapshots and release candidates.

Finally escape the . between the version and the extension, so this
matches a literal . and not any character.

Across oe-core and meta-oe this improves the upstream detection quite
significantly:

- 93 recipes move from a broken check to up-to-date
- 21 recipes move from a broken check to needing an update
- 30 recipes move from up-to-date to needing an update

[1] Specifically PEP-0427 introduced normalisation of special characters
    to underscores and lowercasing.
[2] No users in oe-core, three in meta-oe which are no longer needed
    after this change.
[3] https://packaging.python.org/en/latest/specifications/version-specifiers/

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/classes-recipe/pypi.bbclass | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/pypi.bbclass b/meta/classes-recipe/pypi.bbclass
index eb13ffe7e71..08788fcb9a9 100644
--- a/meta/classes-recipe/pypi.bbclass
+++ b/meta/classes-recipe/pypi.bbclass
@@ -39,8 +39,7 @@  def pypi_src_uri(d):
 
 def pypi_normalize(d):
     """"
-        Normalize the package names to match PEP625 (https://peps.python.org/pep-0625/).
-        For non-compliant packages, maintainers can set UPSTREAM_CHECK_PYPI_PACKAGE to override the normalization
+    Normalize the package names to match PEP625 (https://peps.python.org/pep-0625/).
     """
     import re
     return re.sub(r"[-_.]+", "-", d.getVar('PYPI_PACKAGE')).lower()
@@ -52,7 +51,10 @@  SECTION = "devel/python"
 SRC_URI:prepend = "${PYPI_SRC_URI} "
 S = "${UNPACKDIR}/${PYPI_PACKAGE}-${PV}"
 
-UPSTREAM_CHECK_PYPI_PACKAGE ?= "${PYPI_PACKAGE}"
+def pypi_normalize_regex(d):
+    # Use a regex wildcard instead of hyphen as the filenames
+    # may or may not have been normalised properly.
+    return pypi_normalize(d).replace("-", "[_-]")
 
 # Use the simple repository API rather than the potentially unstable project URL
 # More information on the pypi API specification is avaialble here:
@@ -60,7 +62,7 @@  UPSTREAM_CHECK_PYPI_PACKAGE ?= "${PYPI_PACKAGE}"
 #
 # NOTE: All URLs for the simple API MUST request canonical normalized URLs per the spec
 UPSTREAM_CHECK_URI ?= "https://pypi.org/simple/${@pypi_normalize(d)}/"
-UPSTREAM_CHECK_REGEX ?= "(?i)${UPSTREAM_CHECK_PYPI_PACKAGE}-(?P<pver>(\d+[\.\-_]*)+).(tar\.gz|tgz|zip|tar\.bz2)"
+UPSTREAM_CHECK_REGEX ?= "(?i)${@pypi_normalize_regex(d)}-(?P<pver>(\d+(\.[\d\-]+)*(\.post\d+)?))\.(tar\.gz|tgz|zip|tar\.bz2)"
 
 CVE_PRODUCT ?= "python:${PYPI_PACKAGE}"