Skip to contentSkip to conversation

classes/pypi: change PYPI_PACKAGE to be normalised

RFC PATCH New Ross Burton 1 participant 4 messages Sep 28 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/4 classes/pypi: change PYPI_PACKAGE to be normalised

Currently the semantics of the PYPI_PACKAGE variable are slightly unexpected, as it is the name of the source distribution (tarball), not the logical package itself.

This meant many recipes had to set PYPI_PACKAGE and there were problems when we wanted to use PyPI APIs that expect the normalised package name, not whatever the sdist was called.

This commit changes the definition of PYPI_PACKAGE to be the normalised package name[1], so PySocks would be pysocks and boolean.py would be boolean-py.

This means we can use the correct package name in any PyPI API calls, which all expect a normalised name.

Some uploaded tarballs do not have normalised names, so add a new variable PYPI_PACKAGE_SDIST for the name of the sdist tarball. This defaults to the source distribution normalised[2] PYPI_PACKAGE, but can be overriden if needed.

Whilst this causes some churn in recipes, it mostly lets recipes remove lines.

[1] https://packaging.python.org/en/latest/specifications/name-normalization/
[2] https://packaging.python.org/en/latest/specifications/source-distribution-format/,

---
 meta/classes-recipe/pypi.bbclass | 59 +++++++++++++++++---------------
 1 file changed, 32 insertions(+), 27 deletions(-)
meta/classes-recipe/pypi.bbclass +32 -27
index 08788fcb9a9..e45e3115305 100644
@@ -7,28 +7,37 @@
 def pypi_default_package(d):
     """
     Return a reasonable guess for the PyPI package name by
-    stripping any python- prefix from PN.
+    stripping any python- prefix from PN and normalising it.
     """
     bpn = d.getVar('BPN')
     if bpn.startswith('python-'):
-        return bpn[7:]
+        return pypi_package_normalise(bpn[7:])
     elif bpn.startswith('python3-'):
-        return bpn[8:]
-    return bpn
+        return pypi_package_normalise(bpn[8:])
+    return pypi_package_normalise(bpn)
 
-# The PyPi package name (defaults to PN without the python3- prefix)
+# The PyPI package name, normalised as per
+# https://packaging.python.org/en/latest/specifications/name-normalization/.
+# Defaults to BPN without a python3- prefix.
 PYPI_PACKAGE ?= "${@pypi_default_package(d)}"
+
+# The name of the sdist. This defaults to the normalised name with underscores as per
+# https://packaging.python.org/en/latest/specifications/source-distribution-format/,
+# but can be overridden if needed.
+PYPI_PACKAGE_SDIST ?= "${@d.getVar("PYPI_PACKAGE").replace("-", "_")}"
+
 # The file extension of the source archive
 PYPI_PACKAGE_EXT ?= "tar.gz"
+
 # An optional prefix for the download file in the case of name collisions
 PYPI_ARCHIVE_NAME_PREFIX ?= ""
 
 def pypi_src_uri(d):
     """
-    Construct a source URL as per https://warehouse.pypa.io/api-reference/integration-guide.html#predictable-urls.
+    Construct a source URL as per https://docs.pypi.org/api/#predictable-urls.
     """
-    package = d.getVar('PYPI_PACKAGE')
-    archive_name = d.expand('${PYPI_PACKAGE}-${PV}.${PYPI_PACKAGE_EXT}')
+    package = d.getVar('PYPI_PACKAGE_SDIST')
+    archive_name = d.expand('${PYPI_PACKAGE_SDIST}-${PV}.${PYPI_PACKAGE_EXT}')
     url = 'https://files.pythonhosted.org/packages/source/%s/%s/%s' % (package[0], package, archive_name)
 
     download_prefix = d.getVar("PYPI_ARCHIVE_NAME_PREFIX")
@@ -37,34 +46,30 @@ def pypi_src_uri(d):
 
     return url
 
-def pypi_normalize(d):
-    """"
-    Normalize the package names to match PEP625 (https://peps.python.org/pep-0625/).
-    """
-    import re
-    return re.sub(r"[-_.]+", "-", d.getVar('PYPI_PACKAGE')).lower()
-
 PYPI_SRC_URI ?= "${@pypi_src_uri(d)}"
 
 HOMEPAGE ?= "https://pypi.python.org/pypi/${PYPI_PACKAGE}/"
 SECTION = "devel/python"
 SRC_URI:prepend = "${PYPI_SRC_URI} "
-S = "${UNPACKDIR}/${PYPI_PACKAGE}-${PV}"
+S = "${UNPACKDIR}/${PYPI_PACKAGE_SDIST}-${PV}"
 
-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:
+# More information on the PyPI API specification is available here:
 # https://packaging.python.org/en/latest/specifications/simple-repository-api/
 #
-# 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)${@pypi_normalize_regex(d)}-(?P<pver>(\d+(\.[\d\-]+)*(\.post\d+)?))\.(tar\.gz|tgz|zip|tar\.bz2)"
+# Use a case-insensitive regex wildcard instead of hyphen as the filenames may
+# or may not have been normalised.
+UPSTREAM_CHECK_URI ?= "https://pypi.org/simple/${PYPI_PACKAGE}/"
+UPSTREAM_CHECK_REGEX ?= "(?i)${@d.getVar("PYPI_PACKAGE").replace("-", "[_-]")}-(?P<pver>(\d+(\.[\d\-]+)*(\.post\d+)?))\.(tar\.gz|tgz|zip|tar\.bz2)"
 
 CVE_PRODUCT ?= "python:${PYPI_PACKAGE}"
 
 # Generate ecosystem-specific Package URL for SPDX
-SPDX_PACKAGE_URLS =+ "pkg:pypi/${@pypi_normalize(d)}@${PV} "
+SPDX_PACKAGE_URLS =+ "pkg:pypi/${PYPI_PACKAGE}@${PV} "
+
+def pypi_package_normalise(s):
+    """
+    Normalise the passed package name as per
+    https://packaging.python.org/en/latest/specifications/name-normalization/
+    """
+    import re
+    return re.sub(r"[-_.]+", "-", s).lower()
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 2/4 recipes: update for PYPI_PACKAGE changes

Remove now-redundant PYPI_PACKAGE values that were only needed because the sdist filename has been normalised.

Set PYPI_PACKAGE where the package name does not match the recipe name.

Set PYPI_PACKAGE_SDIST where the sdist is _not_ normalised currently.

---
 meta/recipes-devtools/python/python3-booleanpy_5.0.bb          | 2 +-
 .../recipes-devtools/python/python3-coherent-licensed_0.5.2.bb | 2 --
 meta/recipes-devtools/python/python3-cryptography-vectors.bb   | 2 --
 meta/recipes-devtools/python/python3-dbusmock_0.38.1.bb        | 2 +-
 meta/recipes-devtools/python/python3-flit-core_3.12.0.bb       | 2 --
 .../python/python3-hatch-build-scripts_1.0.0.bb                | 1 -
 .../python/python3-hatch-fancy-pypi-readme_25.1.0.bb           | 2 --
 meta/recipes-devtools/python/python3-hatch-vcs_0.5.0.bb        | 2 --
 .../python/python3-jsonschema-specifications_2025.9.1.bb       | 2 --
 meta/recipes-devtools/python/python3-libarchive-c_5.1.bb       | 2 ++
 .../python/python3-license-expression_30.4.4.bb                | 1 -
 meta/recipes-devtools/python/python3-magic_0.4.27.bb           | 1 +
 meta/recipes-devtools/python/python3-meson-python_0.21.1.bb    | 2 --
 meta/recipes-devtools/python/python3-more-itertools_10.8.0.bb  | 2 --
 meta/recipes-devtools/python/python3-pdm-backend_2.4.10.bb     | 2 --
 meta/recipes-devtools/python/python3-pdm-build-locked_0.3.8.bb | 2 --
 meta/recipes-devtools/python/python3-poetry-core_2.5.0.bb      | 2 --
 meta/recipes-devtools/python/python3-pyproject-hooks_1.3.3.bb  | 2 --
 .../python/python3-pyproject-metadata_0.12.1.bb                | 2 --
 meta/recipes-devtools/python/python3-pysocks_1.7.1.bb          | 2 +-
 meta/recipes-devtools/python/python3-pytest-subtests_0.15.0.bb | 2 --
 .../recipes-devtools/python/python3-rfc3339-validator_0.1.4.bb | 2 --
 meta/recipes-devtools/python/python3-roman-numerals_4.1.0.bb   | 1 -
 meta/recipes-devtools/python/python3-rpds-py_2026.6.3.bb       | 2 --
 meta/recipes-devtools/python/python3-ruamel-yaml_0.19.1.bb     | 2 --
 .../recipes-devtools/python/python3-semantic-version_2.10.0.bb | 2 --
 meta/recipes-devtools/python/python3-setuptools-rust_1.13.0.bb | 2 --
 meta/recipes-devtools/python/python3-setuptools-scm_10.2.3.bb  | 2 --
 .../recipes-devtools/python/python3-spdx-python-model_0.0.6.bb | 1 -
 meta/recipes-devtools/python/python3-spdx-tools_0.8.3.bb       | 2 ++
 meta/recipes-devtools/python/python3-sphinx-argparse_0.6.1.bb  | 2 --
 .../recipes-devtools/python/python3-sphinx-copybutton_0.5.2.bb | 2 ++
 meta/recipes-devtools/python/python3-sphinx-rtd-theme_3.1.0.bb | 2 --
 .../python/python3-sphinxcontrib-applehelp_2.0.0.bb            | 2 --
 .../python/python3-sphinxcontrib-devhelp_2.0.0.bb              | 2 --
 .../python/python3-sphinxcontrib-htmlhelp_2.1.0.bb             | 2 --
 .../python/python3-sphinxcontrib-jquery_4.1.bb                 | 2 ++
 .../python/python3-sphinxcontrib-jsmath_1.0.1.bb               | 2 ++
 .../python/python3-sphinxcontrib-qthelp_2.0.0.bb               | 2 --
 .../python/python3-sphinxcontrib-serializinghtml_2.0.0.bb      | 2 --
 .../python/python3-sphinxcontrib-svg2pdfconverter_2.1.0.bb     | 2 --
 meta/recipes-devtools/python/python3-subunit_1.4.4.bb          | 1 +
 .../python/python3-trove-classifiers_2026.9.21.13.bb           | 2 --
 .../python/python3-typing-extensions_4.16.0.bb                 | 3 ---
 meta/recipes-devtools/python/python3-uv-build_0.12.17.bb       | 2 --
 meta/recipes-devtools/python/python3-vcs-versioning_2.4.1.bb   | 1 -
 meta/recipes-devtools/qemu/python3-qemu-qmp_0.0.6.bb           | 2 --
 .../sbom-cve-check/python3-sbom-cve-check_1.3.5.bb             | 1 -
 48 files changed, 15 insertions(+), 74 deletions(-)
meta/recipes-devtools/python/python3-booleanpy_5.0.bb +1 -1
index a834cdef7bb..f95de3e135e 100644
@@ -6,7 +6,7 @@ LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=d118b5feceee598ebeca76e13395c2bd"
 
 SRC_URI[sha256sum] = "60cbc4bad079753721d32649545505362c754e121570ada4658b852a3a318d95"
 
-PYPI_PACKAGE = "boolean_py"
+PYPI_PACKAGE = "boolean-py"
 
 inherit pypi setuptools3
 
meta/recipes-devtools/python/python3-coherent-licensed_0.5.2.bb +0 -2
index 9148fe4e36a..6bb6629a016 100644
@@ -10,6 +10,4 @@ SRC_URI[sha256sum] = "d8071403ce742d3ac3592ddc4fb7057a46caffb415b928b4d52802e5f2
 
 inherit pypi python_flit_core
 
-PYPI_PACKAGE = "coherent_licensed"
-
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-cryptography-vectors.bb +0 -2
index 0f25199f68d..87302e1b2f3 100644
@@ -11,8 +11,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=8c3617db4fb6fae01f1d253ab91511e4 \
 require python3-cryptography-common.inc
 SRC_URI[sha256sum] = "90066d0f7351b12ebac2b4ce594ce0a6f05c19ad3068e4d5cfc64d9d2bec8d80"
 
-PYPI_PACKAGE = "cryptography_vectors"
-
 inherit pypi python_uv_build
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-dbusmock_0.38.1.bb +1 -1
index ecec075f6f2..12fc704f756 100644
@@ -6,7 +6,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=e6a600fd5e1d9cbde2d983680233ad02"
 
 SRC_URI[sha256sum] = "221b65e1c2e48de9fd11bf7e8c165adaf91648f49a11f390d086a498386f2984"
 
-PYPI_PACKAGE = "python_dbusmock"
+PYPI_PACKAGE = "python-dbusmock"
 
 inherit pypi python_setuptools_build_meta
 DEPENDS += "python3-setuptools-scm-native"
meta/recipes-devtools/python/python3-flit-core_3.12.0.bb +0 -2
index d6b37fe904b..786906b4b41 100644
@@ -16,8 +16,6 @@ inherit pypi python_flit_core
 DEPENDS:remove:class-native = " python3-build-native python3-installer-native"
 DEPENDS:append:class-native = " unzip-native"
 
-PYPI_PACKAGE = "flit_core"
-
 do_compile:class-native () {
     python_flit_core_do_manual_build
 }
meta/recipes-devtools/python/python3-hatch-build-scripts_1.0.0.bb +0 -1
index ba7d8b40ffc..3806e8589fa 100644
@@ -4,7 +4,6 @@ SECTION = "devel/python"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=9ad584cda56221c7eaf48c23a5874a2a"
 
-PYPI_PACKAGE = "hatch_build_scripts"
 SRC_URI[sha256sum] = "563735e2f265c9e1b92dece6f762309114505ffaf6e5d51d462eb6a3b4f14640"
 
 inherit pypi python_hatchling
meta/recipes-devtools/python/python3-hatch-fancy-pypi-readme_25.1.0.bb +0 -2
index 13cc07d76ca..9324db61501 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=ba5633c60bd3e243091013aa83b4d807"
 
 inherit pypi python_hatchling
 
-PYPI_PACKAGE = "hatch_fancy_pypi_readme"
-
 SRC_URI[sha256sum] = "9c58ed3dff90d51f43414ce37009ad1d5b0f08ffc9fc216998a06380f01c0045"
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-hatch-vcs_0.5.0.bb +0 -2
index b8df54a8b37..7fbe8769614 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=26501cfd0bbddf830ee820e95551fa3d"
 
 inherit pypi python_hatchling
 
-PYPI_PACKAGE = "hatch_vcs"
-
 SRC_URI[sha256sum] = "0395fa126940340215090c344a2bf4e2a77bcbe7daab16f41b37b98c95809ff9"
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-jsonschema-specifications_2025.9.1.bb +0 -2
index c324753ef2c..86fc3a67abf 100644
@@ -9,8 +9,6 @@ SRC_URI[sha256sum] = "b540987f239e745613c7a9176f3edb72b832a4ac465cf0271228839783
 
 inherit pypi python_hatchling
 
-PYPI_PACKAGE = "jsonschema_specifications"
-
 DEPENDS += "python3-hatch-vcs-native"
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-libarchive-c_5.1.bb +2 -0
index 6bb4e491042..791326ba24a 100644
@@ -13,6 +13,8 @@ SRC_URI += " \
 
 inherit pypi setuptools3 ptest-python-pytest
 
+PYPI_PACKAGE_SDIST = "libarchive-c"
+
 SRC_URI[sha256sum] = "7bcce24ea6c0fa3bc62468476c6d2f6264156db2f04878a372027c10615a2721"
 
 DEPENDS += "patchelf-native libarchive"
meta/recipes-devtools/python/python3-license-expression_30.4.4.bb +0 -1
index 5751542cb33..38db3951534 100644
@@ -7,7 +7,6 @@ LIC_FILES_CHKSUM = "file://apache-2.0.LICENSE;md5=86d3f3a95c324c9479bd8986968f43
 SRC_URI[sha256sum] = "73448f0aacd8d0808895bdc4b2c8e01a8d67646e4188f887375398c761f340fd"
 
 inherit pypi ptest-python-pytest python_setuptools_build_meta
-PYPI_PACKAGE = "license_expression"
 
 DEPENDS += "python3-setuptools-scm-native python3-wheel-native"
 
meta/recipes-devtools/python/python3-magic_0.4.27.bb +1 -0
index 2e561e69d71..f871b1c2cb8 100644
@@ -8,6 +8,7 @@ LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=61495c152d794e6be5799a9edca149e3"
 
 PYPI_PACKAGE = "python-magic"
+PYPI_PACKAGE_SDIST = "python-magic"
 
 inherit pypi setuptools3
 
meta/recipes-devtools/python/python3-meson-python_0.21.1.bb +0 -2
index 2c86f7fed41..4abe3d8414f 100644
@@ -10,8 +10,6 @@ DEPENDS = " \
 	python3-pyproject-metadata-native \
 "
 
-PYPI_PACKAGE = "meson_python"
-
 inherit pypi python_mesonpy
 SRC_URI[sha256sum] = "78b3345dcbc0fed7b939e7e37a9faab35bddaae07bf62e7542c8ad479c395af5"
 
meta/recipes-devtools/python/python3-more-itertools_10.8.0.bb +0 -2
index 32fcc5694be..053197ea5c7 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=3396ea30f9d21389d7857719816f83b5"
 
 SRC_URI[sha256sum] = "f638ddf8a1a0d134181275fb5d58b086ead7c6a72429ad725c67503f13ba30bd"
 
-PYPI_PACKAGE = "more_itertools"
-
 inherit pypi python_flit_core ptest-python-pytest
 
 RDEPENDS:${PN} += " \
meta/recipes-devtools/python/python3-pdm-backend_2.4.10.bb +0 -2
index 1458f514b49..2f68172a4ae 100644
@@ -8,6 +8,4 @@ SRC_URI[sha256sum] = "551b049379d4f270cba18f5bf73031cc229a4f883e085265465d326d4a
 
 inherit pypi python_pep517
 
-PYPI_PACKAGE = "pdm_backend"
-
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-pdm-build-locked_0.3.8.bb +0 -2
index 2b707a0a93b..fb42de5f67c 100644
@@ -7,6 +7,4 @@ SRC_URI[sha256sum] = "c2a608b288ed08618228880c2e6d6a616049c25eeb71786d06d1061d12
 
 inherit pypi python_pdm
 
-PYPI_PACKAGE = "pdm_build_locked"
-
 BBCLASSEXTEND += "native nativesdk"
meta/recipes-devtools/python/python3-poetry-core_2.5.0.bb +0 -2
index b0d3b8e2ada..a9ffc5682f1 100644
@@ -19,8 +19,6 @@ SRC_URI[sha256sum] = "81d04c9253b19d0604718268d781867c8f7b2128e5b25bbf1e84141eec
 
 inherit python_poetry_core pypi
 
-PYPI_PACKAGE = "poetry_core"
-
 RDEPENDS:${PN}:append:class-target = "\
     python3-compression \
     python3-core \
meta/recipes-devtools/python/python3-pyproject-hooks_1.3.3.bb +0 -2
index 5f1507a0345..bcf0efcf41a 100644
@@ -7,8 +7,6 @@ SRC_URI[sha256sum] = "defda19b854fa0d3bd4f76ea4ddcba8abd7dcfcdd585a6690ade050744
 
 inherit pypi python_flit_core
 
-PYPI_PACKAGE = "pyproject_hooks"
-
 BBCLASSEXTEND = "native nativesdk"
 
 # Bootstrap the native build
meta/recipes-devtools/python/python3-pyproject-metadata_0.12.1.bb +0 -2
index 9918cae0753..81fce2b2b8c 100644
@@ -12,8 +12,6 @@ HOMEPAGE = "https://github.com/FFY00/python-pyproject-metadata"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=310439af287b0fb4780b2ad6907c256c"
 
-PYPI_PACKAGE = "pyproject_metadata"
-
 inherit pypi python_flit_core
 
 SRC_URI[sha256sum] = "8809a4df6fe08279b39a8890669506ed3158e0617855ac9aff098fcbe772ae4c"
meta/recipes-devtools/python/python3-pysocks_1.7.1.bb +1 -1
index 207d15d7025..18d6edc8f26 100644
@@ -5,7 +5,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=1d457bcffb9661b45f799d4efee72f16"
 
 SRC_URI[sha256sum] = "3f8804571ebe159c380ac6de37643bb4685970655d3bba243530d6558b799aa0"
 
-PYPI_PACKAGE = "PySocks"
+PYPI_PACKAGE_SDIST = "PySocks"
 
 inherit pypi setuptools3
 
meta/recipes-devtools/python/python3-pytest-subtests_0.15.0.bb +0 -2
index a76c15119d5..99e0b0e2d07 100644
@@ -9,8 +9,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=242b4e17fa287dcf7aef372f6bc3dcb1"
 
 SRC_URI[sha256sum] = "cb495bde05551b784b8f0b8adfaa27edb4131469a27c339b80fd8d6ba33f887c"
 
-PYPI_PACKAGE = "pytest_subtests"
-
 inherit pypi python_setuptools_build_meta
 
 DEPENDS += "python3-setuptools-scm-native"
meta/recipes-devtools/python/python3-rfc3339-validator_0.1.4.bb +0 -2
index 06eb833f7a9..8561b012bed 100644
@@ -7,8 +7,6 @@ SRC_URI += "file://0001-Remove-usage-of-six.patch"
 
 SRC_URI[sha256sum] = "138a2abdf93304ad60530167e51d2dfb9549521a836871b88d7f4695d0022f6b"
 
-PYPI_PACKAGE = "rfc3339_validator"
-
 inherit pypi setuptools3
 
 RDEPENDS:${PN} += "\
meta/recipes-devtools/python/python3-roman-numerals_4.1.0.bb +0 -1
index 08af23d765c..d7aaea006a9 100644
@@ -4,7 +4,6 @@ LICENSE = "0BSD AND CC0-1.0"
 LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=bfcc8b16e42929aafeb9d414360bc2fd"
 
 SRC_URI[sha256sum] = "1af8b147eb1405d5839e78aeb93131690495fe9da5c91856cb33ad55a7f1e5b2"
-PYPI_PACKAGE = "roman_numerals"
 
 inherit pypi python_flit_core
 
meta/recipes-devtools/python/python3-rpds-py_2026.6.3.bb +0 -2
index 5898649c3bf..68d13ccb963 100644
@@ -10,8 +10,6 @@ require ${BPN}-crates.inc
 
 inherit pypi cargo-update-recipe-crates python_maturin ptest-python-pytest
 
-PYPI_PACKAGE = "rpds_py"
-
 RDEPENDS:${PN}-ptest += " \
     python3-iniconfig \
     python3-packaging \
meta/recipes-devtools/python/python3-ruamel-yaml_0.19.1.bb +0 -2
index c27649e35d8..3117f878cb0 100644
@@ -4,8 +4,6 @@ HOMEPAGE = "https://pypi.org/project/ruamel.yaml/"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=fae78348fee46c087389813e0ebf5ed7"
 
-PYPI_PACKAGE = "ruamel_yaml"
-
 inherit pypi python_setuptools_build_meta
 
 S = "${UNPACKDIR}/ruamel.yaml-${PV}"
meta/recipes-devtools/python/python3-semantic-version_2.10.0.bb +0 -2
index 64d1390475a..99c0c52e09b 100644
@@ -6,8 +6,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=4fb31e3c1c7eeb8b5e8c07657cdd54e2"
 
 SRC_URI[sha256sum] = "bdabb6d336998cbb378d4b9db3a4b56a1e3235701dc05ea2690d9a997ed5041c"
 
-PYPI_PACKAGE = "semantic_version"
-
 inherit pypi setuptools3
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-setuptools-rust_1.13.0.bb +0 -2
index ecb2169a3f6..f07533793cb 100644
@@ -12,8 +12,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=011cd92e702dd9e6b1a26157b6fd53f5"
 SRC_URI += "file://0001-setuptools_rust-rustc_info.py-do-not-add-unstable-op.patch"
 SRC_URI[sha256sum] = "f2afcf4baeee689910ce49cfa8aad4e08cce72f417449bcc32891b8664fdc726"
 
-PYPI_PACKAGE = "setuptools_rust"
-
 inherit cargo pypi python_setuptools_build_meta
 
 DEPENDS += "python3-setuptools-scm-native"
meta/recipes-devtools/python/python3-setuptools-scm_10.2.3.bb +0 -2
index 0af4bd24f5e..14a46d77c3b 100644
@@ -8,8 +8,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=838c366f69b72c5df05c96dff79b35f2"
 
 SRC_URI[sha256sum] = "f179ed3e2a63cf5823e5ee9aa9ca08386219400443a0553224d72dde3f206b44"
 
-PYPI_PACKAGE = "setuptools_scm"
-
 inherit pypi python_setuptools_build_meta
 
 DEPENDS += "\
meta/recipes-devtools/python/python3-spdx-python-model_0.0.6.bb +0 -1
index def12b20492..cebf27a11ce 100644
@@ -4,7 +4,6 @@ SECTION = "devel/python"
 LICENSE = "Apache-2.0"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327"
 
-PYPI_PACKAGE = "spdx_python_model"
 SRC_URI[sha256sum] = "f1938eb08d08218278122849bba123b8993a0171e9b4f5ea6af7aeb71f3204d7"
 
 SRC_URI += " \
meta/recipes-devtools/python/python3-spdx-tools_0.8.3.bb +2 -0
index 0f056793226..d58225f8baa 100644
@@ -10,6 +10,8 @@ BBCLASSEXTEND = "native nativesdk"
 
 inherit pypi python_setuptools_build_meta
 
+PYPI_PACKAGE_SDIST = "spdx-tools"
+
 DEPENDS += "python3-setuptools-scm-native"
 
 # Dependency required for pyspdxtools : python3-click
meta/recipes-devtools/python/python3-sphinx-argparse_0.6.1.bb +0 -2
index a60efa0fccc..c3af27584b3 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENSE.rst;md5=5c1cd8f13774629fee215681e66a1056"
 
 SRC_URI[sha256sum] = "f8be167aedf5670bd7c812ef515968ff4717c63cfc9cb4df5f34b54fd5649c37"
 
-PYPI_PACKAGE = "sphinx_argparse"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinx-copybutton_0.5.2.bb +2 -0
index 04418046617..246837bd983 100644
@@ -7,4 +7,6 @@ SRC_URI[sha256sum] = "4cf17c82fb9646d1bc9ca92ac280813a3b605d8c421225fd9913154103
 
 inherit setuptools3 pypi
 
+PYPI_PACKAGE_SDIST = "sphinx-copybutton"
+
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinx-rtd-theme_3.1.0.bb +0 -2
index 927664c5fbb..4afe6d2dfc5 100644
@@ -12,8 +12,6 @@ RDEPENDS:${PN} += " \
     python3-sphinxcontrib-jquery \
 "
 
-PYPI_PACKAGE = "sphinx_rtd_theme"
-
 SRC_URI[sha256sum] = "b44276f2c276e909239a4f6c955aa667aaafeb78597923b1c60babc76db78e4c"
 
 inherit setuptools3 pypi
meta/recipes-devtools/python/python3-sphinxcontrib-applehelp_2.0.0.bb +0 -2
index 686a4a17ae2..544b5ffc09a 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=c7715857042d4c8c0105999ca0c072c5"
 
 SRC_URI[sha256sum] = "2f29ef331735ce958efa4734873f084941970894c6090408b079c61b2e1c06d1"
 
-PYPI_PACKAGE = "sphinxcontrib_applehelp"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-devhelp_2.0.0.bb +0 -2
index 9f539737083..542e45d522f 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=fd30d9972a142c857a80c9f312e92b93"
 
 SRC_URI[sha256sum] = "411f5d96d445d1d73bb5d52133377b4248ec79db5c793ce7dbe59e074b4dd1ad"
 
-PYPI_PACKAGE = "sphinxcontrib_devhelp"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-htmlhelp_2.1.0.bb +0 -2
index 1a15ccd0c4a..944b990ae09 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=24dce5ef6a13563241c24bc366f48886"
 
 SRC_URI[sha256sum] = "c9e2916ace8aad64cc13a0d233ee22317f2b9025b9cf3295249fa985cc7082e9"
 
-PYPI_PACKAGE = "sphinxcontrib_htmlhelp"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-jquery_4.1.bb +2 -0
index d21e802582d..eca7225c909 100644
@@ -7,4 +7,6 @@ SRC_URI[sha256sum] = "1620739f04e36a2c779f1a131a2dfd49b2fd07351bf1968ced07436593
 
 inherit pypi python_flit_core
 
+PYPI_PACKAGE_SDIST = "sphinxcontrib-jquery"
+
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-jsmath_1.0.1.bb +2 -0
index c06ba1242f9..0e2b9d2b44c 100644
@@ -7,4 +7,6 @@ SRC_URI[sha256sum] = "a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153
 
 inherit pypi setuptools3
 
+PYPI_PACKAGE_SDIST = "sphinxcontrib-jsmath"
+
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-qthelp_2.0.0.bb +0 -2
index f51a0ba64b6..7b805f98ea3 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=f7a83b72ea86d04827575ec0b63430eb"
 
 SRC_URI[sha256sum] = "4fe7d0ac8fc171045be623aba3e2a8f613f8682731f9153bb2e40ece16b9bbab"
 
-PYPI_PACKAGE = "sphinxcontrib_qthelp"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-serializinghtml_2.0.0.bb +0 -2
index 63c55d36ae4..ae526fae45e 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENCE.rst;md5=32a84ac5cd3bbd10c4d479233ad588b6"
 
 SRC_URI[sha256sum] = "e9d912827f872c029017a53f0ef2180b327c3f7fd23c87229f7a8e8b70031d4d"
 
-PYPI_PACKAGE = "sphinxcontrib_serializinghtml"
-
 inherit pypi python_flit_core
 
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-devtools/python/python3-sphinxcontrib-svg2pdfconverter_2.1.0.bb +0 -2
index 6b5350f46cb..d17e2b924c4 100644
@@ -9,8 +9,6 @@ inherit pypi python_setuptools_build_meta
 
 DEPENDS += "python3-wheel-native"
 
-PYPI_PACKAGE = "sphinxcontrib_svg2pdfconverter"
-
 RDEPENDS:${PN} = "python3-sphinx"
 # Only support sphinxcontrib.rsvgconverter for now.
 # sphinxcontrib.cairosvgconverter depends on cairosvg module, no recipe yet
meta/recipes-devtools/python/python3-subunit_1.4.4.bb +1 -0
index 0ff02ef3b86..ff93d19df43 100644
@@ -5,6 +5,7 @@ LICENSE = "Apache-2.0 OR BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://COPYING;beginline=1;endline=20;md5=b1121e68d06c8d9ea544fcd895df0d39"
 
 PYPI_PACKAGE = "python-subunit"
+PYPI_PACKAGE_SDIST = "python-subunit"
 
 SRC_URI[sha256sum] = "1079363131aa1d3f45259237265bc2e61a77e35f20edfb6e3d1d2558a2cdea34"
 
meta/recipes-devtools/python/python3-trove-classifiers_2026.9.21.13.bb +0 -2
index b24753e381b..8dbf968310c 100644
@@ -5,8 +5,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327"
 
 SRC_URI[sha256sum] = "0a9ebc8d4e2f3e8a22848c5258033035bec17a3012ac3fea16dbaa764489eb71"
 
-PYPI_PACKAGE = "trove_classifiers"
-
 inherit pypi python_setuptools_build_meta ptest-python-pytest
 
 DEPENDS += " python3-calver-native"
meta/recipes-devtools/python/python3-typing-extensions_4.16.0.bb +0 -3
index cede81e1289..1e11251f5be 100644
@@ -12,9 +12,6 @@ SECTIONS = "libs"
 LICENSE = "PSF-2.0"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2"
 
-# The name on PyPi is slightly different.
-PYPI_PACKAGE = "typing_extensions"
-
 SRC_URI[sha256sum] = "dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"
 
 inherit pypi python_flit_core
meta/recipes-devtools/python/python3-uv-build_0.12.17.bb +0 -2
index 322ac35f488..9752956f491 100644
@@ -19,7 +19,5 @@ inherit pypi python_maturin cargo-update-recipe-crates pkgconfig
 
 DEPENDS += "zstd"
 
-PYPI_PACKAGE = "uv_build"
-
 BBCLASSEXTEND = "native"
 INSANE_SKIP:${PN} = "already-stripped"
meta/recipes-devtools/python/python3-vcs-versioning_2.4.1.bb +0 -1
index 36bb2856a0b..64905dea773 100644
@@ -11,7 +11,6 @@ SRC_URI += "\
     file://run-ptest \
 "
 
-PYPI_PACKAGE = "vcs_versioning"
 PTEST_PYTEST_DIR = "testing_vcs"
 
 inherit pypi python_setuptools_build_meta ptest-python-pytest
meta/recipes-devtools/qemu/python3-qemu-qmp_0.0.6.bb +0 -2
index 3b51a453b99..8d99297ac42 100644
@@ -8,8 +8,6 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=4cf66a4984120007c9881cc871cf49db"
 
 inherit pypi python_setuptools_build_meta
 
-PYPI_PACKAGE = "qemu_qmp"
-
 SRC_URI[sha256sum] = "a3c25d871fab549122b2340810de1f99481002c942a2132476b062aacdbf6e92"
 
 DEPENDS += "python3-setuptools-scm-native python3-wheel-native"
meta/recipes-devtools/sbom-cve-check/python3-sbom-cve-check_1.3.5.bb +0 -1
index 83d420835da..5396720fbd0 100644
@@ -4,7 +4,6 @@ SECTION = "devel/python"
 LICENSE = "GPL-2.0-or-later"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=570a9b3749dd0463a1778803b12a6dce"
 
-PYPI_PACKAGE = "sbom_cve_check"
 SRC_URI[sha256sum] = "9ed8b0e9c46015444cd3e30332d9558e0be5f5fec97f6df47c6760166a314167"
 
 inherit pypi python_hatchling
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 3/4 recipetool: set PYPI_PACKAGE_SDIST if needed

In reply to Ross Burton

Normalise the PyPI package name when setting PYPI_PACKAGE, and also set PYPI_PACKAGE_SDIST if required.

---
 .../lib/recipetool/create_buildsys_python.py   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
scripts/lib/recipetool/create_buildsys_python.py +16 -2
index 61979c842cf..1d8a3b8dfda 100644
@@ -115,6 +115,14 @@ class PythonRecipeHandler(RecipeHandler):
     def __init__(self):
         pass
 
+    @staticmethod
+    def pypi_normalise(s):
+        """
+        Normalize the package names.
+        https://packaging.python.org/en/latest/specifications/name-normalization/
+        """
+        return re.sub(r"[-_.]+", "-", s).lower()
+
     def process_url(self, args, classes, handled, extravalues):
         """
         Convert any pypi url https://pypi.org/project/<package>/<version> into https://files.pythonhosted.org/packages/source/...
@@ -143,6 +151,7 @@ class PythonRecipeHandler(RecipeHandler):
                 for release in reversed(data["releases"][version]):
                     if release["packagetype"] == "sdist":
                         fetch_uri = release["url"]
+                        sdist = release["filename"].rsplit("-")[0]
                         break
             else:
                 logger.warning("Cannot handle pypi url %s: cannot fetch package information using %s", source, json_url)
@@ -152,14 +161,19 @@ class PythonRecipeHandler(RecipeHandler):
             if match:
                 fetch_uri = source
                 pypi_package = match.group(1)
-                _, version = determine_from_url(fetch_uri)
+                sdist, version = determine_from_url(fetch_uri)
 
         if match and not args.no_pypi:
             if required_version and version != required_version:
                 raise Exception("Version specified using --version/-V (%s) and version specified in the url (%s) do not match" % (required_version, version))
-            # This is optionnal if BPN looks like "python-<pypi_package>" or "python3-<pypi_package>" (see pypi.bbclass)
+            # PYPI_PACKAGE is optional if BPN looks like "python-<pypi_package>" or "python3-<pypi_package>" (see pypi.bbclass)
             # but at this point we cannot know because because user can specify the output name of the recipe on the command line
+            pypi_package = self.pypi_normalise(pypi_package)
             extravalues["PYPI_PACKAGE"] = pypi_package
+            # Some sdists don't use normalised names, so check and set PYPI_PACKAGE_SDIST if needed
+            if sdist != pypi_package.replace("-", "_"):
+                extravalues["PYPI_PACKAGE_SDIST"] = sdist
+
             # If the tarball extension is not 'tar.gz' (default value in pypi.bblcass) whe should set PYPI_PACKAGE_EXT in the recipe
             pypi_package_ext = re.match(r'.*%s-%s\.(.*)$' % (pypi_package, version), fetch_uri)
             if pypi_package_ext:
Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH 4/4 recipetool: normalise python packages when constructing PN

In reply to Ross Burton

When constructing PN for python recipes, normalise the package name.

For example, the package boolean.py uses python3-boolean-py.bb instead of python3-boolean.py.bb.

---
 scripts/lib/recipetool/create_buildsys_python.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/recipetool/create_buildsys_python.py +1 -1
index 1d8a3b8dfda..0c5f44b9663 100644
@@ -238,7 +238,7 @@ class PythonRecipeHandler(RecipeHandler):
             if bbvar == "PN":
                 # by convention python recipes start with "python3-"
                 if not value.startswith('python'):
-                    value = 'python3-' + value
+                    value = 'python3-' + self.pypi_normalise(value)
 
             if bbvar not in extravalues and value:
                 extravalues[bbvar] = value
Signature · 1 line
2.43.0