recipetool: don't dump stack traces if a toml parser can't be found
PATCH 1/2 recipetool: don't dump stack traces if a toml parser can't be found
From: Ross Burton <[email protected]>
If we can't find tomllib or tomli then we can just tell the user politely that we can't parse the pyproject.toml file, there's no need to dump exception stack traces.
Move the parser exception handler to catch the actual parse, as otherwise it will never be used.
Whilst here, also add some debug statements to make it clear what of the handlers is being called.
--- .../lib/recipetool/create_buildsys_python.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
scripts/lib/recipetool/create_buildsys_python.py +14 -6
@@ -573,12 +573,15 @@ class PythonSetupPyRecipeHandler(PythonRecipeHandler): if 'buildsystem' in handled: return False + logger.debug("Trying setup.py parser") + # Check for non-zero size setup.py files setupfiles = RecipeHandler.checkfiles(srctree, ['setup.py']) for fn in setupfiles: if os.path.getsize(fn): break else: + logger.debug("No setup.py found") return False # setup.py is always parsed to get at certain required information, such as
@@ -799,12 +802,15 @@ class PythonPyprojectTomlRecipeHandler(PythonRecipeHandler): if 'buildsystem' in handled: return False + logger.debug("Trying pyproject.toml parser") + # Check for non-zero size setup.py files setupfiles = RecipeHandler.checkfiles(srctree, ["pyproject.toml"]) for fn in setupfiles: if os.path.getsize(fn): break else: + logger.debug("No pyproject.toml found") return False setupscript = os.path.join(srctree, "pyproject.toml")
@@ -816,14 +822,16 @@ class PythonPyprojectTomlRecipeHandler(PythonRecipeHandler): try: import tomli as tomllib except ImportError: - logger.exception("Neither 'tomllib' nor 'tomli' could be imported. Please use python3.11 or above or install tomli module") - return False - except Exception: - logger.exception("Failed to parse pyproject.toml") + logger.error("Neither 'tomllib' nor 'tomli' could be imported, cannot scan pyproject.toml.") return False - with open(setupscript, "rb") as f: - config = tomllib.load(f) + try: + with open(setupscript, "rb") as f: + config = tomllib.load(f) + except Exception: + logger.exception("Failed to parse pyproject.toml") + return False + build_backend = config["build-system"]["build-backend"] if build_backend in self.build_backend_map: classes.append(self.build_backend_map[build_backend])
Signature · 1 line
2.34.1
PATCH 2/2 oeqa/selftest/recipetool: downgrade meson version used to not use pyproject.toml
From: Ross Burton <[email protected]>
recipetool's pyproject.toml parsing needs tomllib (python 3.11+) or tomli (not a hard dependency), so is prone to failing depending on the host configuration.
Downgrade the Meson release used for the checks to 0.52.1, which was the last release before moving to pyproject.toml.
--- meta/lib/oeqa/selftest/cases/recipetool.py | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-)
meta/lib/oeqa/selftest/cases/recipetool.py +12 -16
@@ -451,21 +451,20 @@ class RecipetoolCreateTests(RecipetoolBase): self._test_recipe_contents(recipefile, checkvars, inherits) def test_recipetool_create_github(self): - # This test require python 3.11 or above for the tomllib module or tomli module to be installed - needTomllib(self) - - # Basic test to see if github URL mangling works + # Basic test to see if github URL mangling works. Deliberately use an + # older release of Meson so that 1) this verifies we don't grab HEAD and + # 2) this release is pre-pyproject.toml. temprecipe = os.path.join(self.tempdir, 'recipe') os.makedirs(temprecipe) - recipefile = os.path.join(temprecipe, 'meson_git.bb') - srcuri = 'https://github.com/mesonbuild/meson;rev=1.3.1' + recipefile = os.path.join(temprecipe, 'python3-meson_git.bb') + srcuri = 'https://github.com/mesonbuild/meson;rev=0.52.1' cmd = ['recipetool', 'create', '-o', temprecipe, srcuri] result = runCmd(cmd) self.assertTrue(os.path.isfile(recipefile), msg="recipe %s not created for command %s, output %s" % (recipefile, " ".join(cmd), result.output)) checkvars = {} - checkvars['LICENSE'] = set(['Apache-2.0', 'Proprietary', 'Unknown']) - checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=1.3' - inherits = ['python_setuptools_build_meta'] + checkvars['LICENSE'] = set(['Apache-2.0', "Unknown"]) + checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=0.52' + inherits = ['setuptools3'] self._test_recipe_contents(recipefile, checkvars, inherits) def test_recipetool_create_python3_setuptools(self):
@@ -679,21 +678,18 @@ class RecipetoolCreateTests(RecipetoolBase): self._test_recipe_contents(recipefile, checkvars, inherits) def test_recipetool_create_github_tarball(self): - # This test require python 3.11 or above for the tomllib module or tomli module to be installed - needTomllib(self) - # Basic test to ensure github URL mangling doesn't apply to release tarballs temprecipe = os.path.join(self.tempdir, 'recipe') os.makedirs(temprecipe) - pv = '1.3.1' - recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv) + pv = '0.52.1' + recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv) srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv) result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) self.assertTrue(os.path.isfile(recipefile)) checkvars = {} - checkvars['LICENSE'] = set(['Apache-2.0', 'Proprietary', 'Unknown']) + checkvars['LICENSE'] = set(['Apache-2.0']) checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz' - inherits = ['python_setuptools_build_meta'] + inherits = ['setuptools3'] self._test_recipe_contents(recipefile, checkvars, inherits) def _test_recipetool_create_git(self, srcuri, branch=None):
Signature · 1 line
2.34.1
Patchtest results for [PATCH][master-next 2/2] oeqa/selftest/recipetool: downgrade meson version used to not use pyproject.toml
Thank you for your submission. Patchtest identified one or more issues with the patch. Please see the log below for more information:
---
Testing patch /home/patchtest/share/mboxes/master-next-2-2-oeqa-selftest-recipetool-downgrade-meson-version-used-to-not-use-pyproject.toml.patch
FAIL: test shortlog length: Edit shortlog so that it is 90 characters or less (currently 98 characters) (test_mbox.TestMbox.test_shortlog_length)
PASS: pretest pylint (test_python_pylint.PyLint.pretest_pylint)
PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test pylint (test_python_pylint.PyLint.test_pylint)
PASS: test shortlog format (test_mbox.TestMbox.test_shortlog_format)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)
SKIP: pretest src uri left files: Patch cannot be merged (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: Patch cannot be merged (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)
---
Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this email with an explanation of why the patch should be accepted. If you believe these results are due to an error in patchtest, please submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category under 'Yocto Project Subprojects'). For more information on specific failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank you!