diff mbox series

[2/3] recipetool: Fix sdist name detection from PyPI

Message ID 20261022183608.3500655-2-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
The sdist name used to decide whether PYPI_PACKAGE_SDIST needs to
be set was determined incorrectly:

- For pypi.org project URLs the release filename was split on
  every '-', so python-magic-0.4.15.tar.gz resulted in
  PYPI_PACKAGE_SDIST = "python".

- For files.pythonhosted.org URLs the name was taken from
  determine_from_url(), which lowercases it and replaces '_' with
  '-'. For sphinxcontrib_svg2pdfconverter-2.0.0.tar.gz this set
  PYPI_PACKAGE_SDIST to the hyphenated name although the sdist
  uses the standard underscore form and the variable is not
  needed.

In both cases the generated recipe fetches from a non-existent URL.

Before:

devtool add python3-magic https://pypi.org/project/python-magic/
bitbake python3-magic -e | grep ^PYPI_PACKAGE
PYPI_PACKAGE="python-magic"
PYPI_PACKAGE_EXT="tar.gz"
PYPI_PACKAGE_SDIST="python"

devtool add python3-sphinxcontrib-svg2pdfconverter https://files.pythonhosted.org/packages/b9/05/11b12853b6a0398bd19d5464b68cb97dde21c354265ff2c1929f92ae03a9/sphinxcontrib_svg2pdfconverter-2.1.0.tar.gz
bitbake python3-sphinxcontrib-svg2pdfconverter -e | grep ^PYPI_PACKAGE
PYPI_PACKAGE="sphinxcontrib-svg2pdfconverter"
PYPI_PACKAGE_EXT="tar.gz"
PYPI_PACKAGE_SDIST="sphinxcontrib-svg2pdfconverter"

After:

devtool add python3-magic https://pypi.org/project/python-magic/
bitbake python3-magic -e | grep ^PYPI_PACKAGE
PYPI_PACKAGE="python-magic"
PYPI_PACKAGE_EXT="tar.gz"
PYPI_PACKAGE_SDIST="python-magic"

devtool add python3-sphinxcontrib-svg2pdfconverter https://files.pythonhosted.org/packages/b9/05/11b12853b6a0398bd19d5464b68cb97dde21c354265ff2c1929f92ae03a9/sphinxcontrib_svg2pdfconverter-2.1.0.tar.gz
bitbake python3-sphinxcontrib-svg2pdfconverter -e | grep ^PYPI_PACKAGE
PYPI_PACKAGE="sphinxcontrib-svg2pdfconverter"
PYPI_PACKAGE_EXT="tar.gz"
PYPI_PACKAGE_SDIST="sphinxcontrib_svg2pdfconverter"

Split only on the last '-' and use the name exactly as it appears
in the filename.

Fixes: 52779aa8b5 ("recipetool: set PYPI_PACKAGE_SDIST if needed")

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

Patch

diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 5a9fc8ea67..ca05e54593 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -511,6 +511,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
         checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
         checkvars['PYPI_PACKAGE'] = pn
+        checkvars['PYPI_PACKAGE_SDIST'] = pn
         inherits = ['setuptools3', 'pypi']
         self._test_recipe_contents(recipefile, checkvars, inherits)
 
@@ -533,6 +534,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
         checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
         checkvars['PYPI_PACKAGE'] = pn
+        checkvars['PYPI_PACKAGE_SDIST'] = pn
         inherits = ['setuptools3', "pypi"]
         self._test_recipe_contents(recipefile, checkvars, inherits)
 
@@ -547,6 +549,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
         checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
         checkvars['PYPI_PACKAGE'] = pn
+        checkvars['PYPI_PACKAGE_SDIST'] = pn
         inherits = ['setuptools3', "pypi"]
         self._test_recipe_contents(recipefile, checkvars, inherits)
 
@@ -572,6 +575,7 @@  class RecipetoolCreateTests(RecipetoolBase):
         checkvars = {}
         checkvars['LICENSE'] = 'MIT'
         checkvars['PYPI_PACKAGE'] = pn
+        checkvars['PYPI_PACKAGE_SDIST'] = pn
         inherits = ['setuptools3', "pypi"]
         self._test_recipe_contents(recipefile, checkvars, inherits)
 
@@ -593,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_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
         self._test_recipe_contents(recipefile, checkvars, inherits)
@@ -616,6 +621,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_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
         self._test_recipe_contents(recipefile, checkvars, inherits)
@@ -638,6 +644,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_SDIST'] = None
         inherits = ['python_setuptools_build_meta', 'pypi']
 
         self._test_recipe_contents(recipefile, checkvars, inherits)
diff --git a/scripts/lib/recipetool/create_buildsys_python.py b/scripts/lib/recipetool/create_buildsys_python.py
index 81ceaed47a..4fc96db7e8 100644
--- a/scripts/lib/recipetool/create_buildsys_python.py
+++ b/scripts/lib/recipetool/create_buildsys_python.py
@@ -162,7 +162,7 @@  class PythonRecipeHandler(RecipeHandler):
                 for release in reversed(data["releases"][version]):
                     if release["packagetype"] == "sdist":
                         fetch_uri = release["url"]
-                        sdist = release["filename"].rsplit("-")[0]
+                        sdist = release["filename"].rsplit("-", 1)[0]
                         break
             else:
                 logger.warning("Cannot handle pypi url %s: cannot fetch package information using %s", source, json_url)
@@ -171,8 +171,10 @@  class PythonRecipeHandler(RecipeHandler):
             match = re.match(r'^https?://files.pythonhosted.org/packages.*/(.*)-.*$', source)
             if match:
                 fetch_uri = source
-                pypi_package = match.group(1)
-                sdist, version = determine_from_url(fetch_uri)
+                # The sdist name as found in the filename, not normalised
+                sdist = match.group(1)
+                pypi_package = sdist
+                _, version = determine_from_url(fetch_uri)
 
         if match and not args.no_pypi:
             if required_version and version != required_version: