recipetool: Support multi-line license
PATCH 1/3 recipetool: Support multi-line license
Some Python packages put the full license text into the license field of PKG-INFO or pyproject.toml instead of a short identifier. Add a comment_lines() helper to PythonRecipeHandler which prefixes every continuation line with '#' to avoid the ParseError.
Fixes:
$ devtool add python3-tibs https://pypi.org/project/tibs bb.parse.ParseError: ParseError at .../python3-tibs_2.0.2.bb:9: unparsed line: 'Copyright (c) 2025 Scott Griffiths (...)' ERROR: Parsing newly created recipe failed
AI-Generated: Uses Claude Code
--- scripts/lib/recipetool/create_buildsys_python.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
scripts/lib/recipetool/create_buildsys_python.py +13 -2
@@ -123,6 +123,17 @@ class PythonRecipeHandler(RecipeHandler): """ return re.sub(r"[-_.]+", "-", s).lower() + @staticmethod + def comment_lines(s): + """ + Some Python packages put the full license text into the license + field of PKG-INFO or pyproject.toml instead of a short identifier. + Prefix follow-up lines with '#' so that multi-line values (e.g. + a full license text) remain a valid comment in the recipe. + """ + return "\n".join(("# " + line).rstrip() if i else line + for i, line in enumerate(s.splitlines())) + 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/...
@@ -675,7 +686,7 @@ class PythonSetupPyRecipeHandler(PythonRecipeHandler): if license_str: for i, line in enumerate(lines_before): if line.startswith('##LICENSE_PLACEHOLDER##'): - lines_before.insert(i, '# NOTE: License in setup.py/PKGINFO is: %s' % license_str) + lines_before.insert(i, '# NOTE: License in setup.py/PKGINFO is: %s' % self.comment_lines(license_str)) break if 'Classifier' in info:
@@ -914,7 +925,7 @@ class PythonPyprojectTomlRecipeHandler(PythonRecipeHandler): for i, line in enumerate(lines_before): if line.startswith("##LICENSE_PLACEHOLDER##"): lines_before.insert( - i, "# NOTE: License in pyproject.toml is: %s" % license_str + i, "# NOTE: License in pyproject.toml is: %s" % self.comment_lines(license_str) ) break
Signature · 1 line
2.47.3
PATCH 2/3 recipetool: Fix sdist name detection from PyPI
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.
AI-Generated: Uses Claude Code
--- meta/lib/oeqa/selftest/cases/recipetool.py | 7 +++++++ scripts/lib/recipetool/create_buildsys_python.py | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
meta/lib/oeqa/selftest/cases/recipetool.py +7 -0
@@ -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)
scripts/lib/recipetool/create_buildsys_python.py +5 -3
@@ -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:
Signature · 1 line
2.47.3
PATCH 3/3 recipetool: Drop PYPI_PACKAGE if it matches BPN
In reply to Leon AnaviPYPI_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
--- 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(-)
meta/lib/oeqa/selftest/cases/recipetool.py +3 -0
@@ -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']
scripts/lib/recipetool/create.py +14 -0
@@ -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:
scripts/lib/recipetool/create_buildsys_python.py +2 -1
@@ -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
Signature · 1 line
2.47.3
Re: [OE-core] [PATCH 3/3] recipetool: Drop PYPI_PACKAGE if it matches BPN
Quoted 15 lines · Leon Anavi via lists.openembedded.org
scripts/lib/recipetool/create.py +7
-0@@ -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-'):]
scripts/lib/recipetool/create.py def create_recipe(args): · line 814
Quoted 10 lines
scripts/lib/recipetool/create.py +7
-0+ 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:
This is adding buildsystem-specific logic into the generic create.py, which is continued will mean the logic is spread across multiple places.
I think it would be better to have a “cleanup” hook for the build system plugins, so the python-specific cleanup can remain in the python plugin.
Ross
Re: [OE-core] [PATCH 3/3] recipetool: Drop PYPI_PACKAGE if it matches BPN
Hi Ross,
Quoted 30 lines · Ross Burton
Review
Quoted 1 line · Leon Anavi via lists.openembedded.org
(quoted diff) +0
-0
b/scripts/lib/recipetool/create.pyscripts/lib/recipetool/create.py def create_recipe(args): · line 798
Quoted 8 lines
index
bf533a45cf..3baf19c7c2100644scripts/lib/recipetool/create.py +1
-0@@ -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 fromBPN (see pypi.bbclass)
scripts/lib/recipetool/create.py def create_recipe(args):
Quoted 11 lines
scripts/lib/recipetool/create.py +11
-0+ 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']:
scripts/lib/recipetool/create.py def create_recipe(args):
Quoted 3 lines
scripts/lib/recipetool/create.py +2
-0+ del extravalues['PYPI_PACKAGE'] + handle_license_vars(srctree_use, lines_before, handled, extravalues,tinfoil.config_data)
Quoted 1 line
Quoted 8 lines
Quoted 1 line
if not outfile:
This is adding buildsystem-specific logic into the generic
create.py, which is continued will mean the logic is spread across multiple places.I think it would be better to have a “cleanup” hook for the build system plugins, so the python-specific cleanup can remain in the python plugin.
Thank you for the code review. Following your suggestion, I have submitted version 2 of the patch, which includes a cleanup hook in create_buildsys_python.py. Please let me know if you have any remarks.
Best regards, Leon