diff mbox series

[3/3] recipetool: Drop PYPI_PACKAGE if it matches BPN

Message ID 20261022183608.3500655-3-leon.anavi@konsulko.com
State New
Headers show
Series [1/3] recipetool: Support multi-line license | expand

Commit Message

Leon Anavi Oct. 22, 2026, 6:36 p.m. UTC
PYPI_PACKAGE was always added to recipes created for PyPI sources
because the recipe name is not known yet when the source URL is
processed. Since PYPI_PACKAGE is now the normalised package name
and pypi.bbclass derives it from BPN by default, it is redundant in
the common case.

Once the recipe name has been determined, drop PYPI_PACKAGE if it
matches the default value from pypi.bbclass.

Before:

devtool add python3-tibs https://pypi.org/project/tibs
grep ^PYPI_PACKAGE python3-tibs_2.0.2.bb
PYPI_PACKAGE = "tibs"

After:

devtool add python3-tibs https://pypi.org/project/tibs
grep ^PYPI_PACKAGE python3-tibs_2.0.2.bb

However, it still sets PYPI_PACKAGE and PYPI_PACKAGE_SDIST where
needed, for example in a recipe for python-magic:

devtool add python3-magic https://pypi.org/project/python-magic/
grep ^PYPI_PACKAGE python3-magic_0.4.27.bb
PYPI_PACKAGE = "python-magic"
PYPI_PACKAGE_SDIST = "python-magic"

AI-Generated: Uses Claude Code
Signed-off-by: Leon Anavi <leon.anavi@konsulko.com>
---
 meta/lib/oeqa/selftest/cases/recipetool.py       |  3 +++
 scripts/lib/recipetool/create.py                 | 14 ++++++++++++++
 scripts/lib/recipetool/create_buildsys_python.py |  3 ++-
 3 files changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index ca05e54593..54b7cb3a65 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -597,6 +597,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LICENSE'] = 'BSD-3-Clause'
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19'
         checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a'
+        checkvars['PYPI_PACKAGE'] = None
         checkvars['PYPI_PACKAGE_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
@@ -621,6 +622,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LICENSE'] = 'GPL-3.0-only'
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=1ebbd3e34237af26da5dc08a4e440464'
         checkvars['SRC_URI[sha256sum]'] = '81f7c0c5559becc8049470d86046b36e96113637bcbe4753ecef06977c00245d'
+        checkvars['PYPI_PACKAGE'] = None
         checkvars['PYPI_PACKAGE_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
@@ -644,6 +646,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LICENSE'] = 'BSD-2-Clause'
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE.txt;md5=b11cf936853a71258d4b57bb1849a3f9'
         checkvars['SRC_URI[sha256sum]'] = 'ab9c8f1080391e231812d20abf2657a69ee35574563b1014414f953964a95fa3'
+        checkvars['PYPI_PACKAGE'] = None
         checkvars['PYPI_PACKAGE_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index bf533a45cf..3baf19c7c2 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -795,6 +795,20 @@  def create_recipe(args):
         if name_pv and not realpv:
             realpv = name_pv
 
+    # PYPI_PACKAGE is not needed if it matches the default derived from BPN (see pypi.bbclass)
+    if pn and 'pypi' in classes and extravalues.get('PYPI_PACKAGE'):
+        bpn = pn
+        if bpn.endswith('-native'):
+            bpn = bpn[:-len('-native')]
+        if bpn.startswith('nativesdk-'):
+            bpn = bpn[len('nativesdk-'):]
+        for prefix in ('python-', 'python3-'):
+            if bpn.startswith(prefix):
+                bpn = bpn[len(prefix):]
+                break
+        if re.sub(r"[-_.]+", "-", bpn).lower() == extravalues['PYPI_PACKAGE']:
+            del extravalues['PYPI_PACKAGE']
+
     handle_license_vars(srctree_use, lines_before, handled, extravalues, tinfoil.config_data)
 
     if not outfile:
diff --git a/scripts/lib/recipetool/create_buildsys_python.py b/scripts/lib/recipetool/create_buildsys_python.py
index 4fc96db7e8..d53a6205bf 100644
--- a/scripts/lib/recipetool/create_buildsys_python.py
+++ b/scripts/lib/recipetool/create_buildsys_python.py
@@ -180,7 +180,8 @@  class PythonRecipeHandler(RecipeHandler):
             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))
             # 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
+            # but at this point we cannot know because the user can specify the output name of the recipe on the command line,
+            # so it is set here and dropped later in create_recipe() once the recipe name is known
             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