diff options
author | Ross Burton <ross.burton@arm.com> | 2024-02-09 15:39:50 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-02-10 14:13:24 +0000 |
commit | c472b4ce5990080e258a409cec0cab4cdb1a37f8 (patch) | |
tree | 415bde9e134397f89595f0a9d4a0a7d23c412c87 | |
parent | 398f27cc0bbaee53ea2a96e7ec7e95c95e0747f7 (diff) | |
download | poky-c472b4ce5990080e258a409cec0cab4cdb1a37f8.tar.gz |
recipetool: don't dump stack traces if a toml parser can't be found
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.
(From OE-Core rev: 1a3ba4c312844d80ae382912b319e60ad8b30737)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | scripts/lib/recipetool/create_buildsys_python.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/lib/recipetool/create_buildsys_python.py b/scripts/lib/recipetool/create_buildsys_python.py index 60c5903450..a589343cfb 100644 --- a/scripts/lib/recipetool/create_buildsys_python.py +++ b/scripts/lib/recipetool/create_buildsys_python.py | |||
@@ -573,12 +573,15 @@ class PythonSetupPyRecipeHandler(PythonRecipeHandler): | |||
573 | if 'buildsystem' in handled: | 573 | if 'buildsystem' in handled: |
574 | return False | 574 | return False |
575 | 575 | ||
576 | logger.debug("Trying setup.py parser") | ||
577 | |||
576 | # Check for non-zero size setup.py files | 578 | # Check for non-zero size setup.py files |
577 | setupfiles = RecipeHandler.checkfiles(srctree, ['setup.py']) | 579 | setupfiles = RecipeHandler.checkfiles(srctree, ['setup.py']) |
578 | for fn in setupfiles: | 580 | for fn in setupfiles: |
579 | if os.path.getsize(fn): | 581 | if os.path.getsize(fn): |
580 | break | 582 | break |
581 | else: | 583 | else: |
584 | logger.debug("No setup.py found") | ||
582 | return False | 585 | return False |
583 | 586 | ||
584 | # setup.py is always parsed to get at certain required information, such as | 587 | # setup.py is always parsed to get at certain required information, such as |
@@ -799,12 +802,15 @@ class PythonPyprojectTomlRecipeHandler(PythonRecipeHandler): | |||
799 | if 'buildsystem' in handled: | 802 | if 'buildsystem' in handled: |
800 | return False | 803 | return False |
801 | 804 | ||
805 | logger.debug("Trying pyproject.toml parser") | ||
806 | |||
802 | # Check for non-zero size setup.py files | 807 | # Check for non-zero size setup.py files |
803 | setupfiles = RecipeHandler.checkfiles(srctree, ["pyproject.toml"]) | 808 | setupfiles = RecipeHandler.checkfiles(srctree, ["pyproject.toml"]) |
804 | for fn in setupfiles: | 809 | for fn in setupfiles: |
805 | if os.path.getsize(fn): | 810 | if os.path.getsize(fn): |
806 | break | 811 | break |
807 | else: | 812 | else: |
813 | logger.debug("No pyproject.toml found") | ||
808 | return False | 814 | return False |
809 | 815 | ||
810 | setupscript = os.path.join(srctree, "pyproject.toml") | 816 | setupscript = os.path.join(srctree, "pyproject.toml") |
@@ -816,14 +822,16 @@ class PythonPyprojectTomlRecipeHandler(PythonRecipeHandler): | |||
816 | try: | 822 | try: |
817 | import tomli as tomllib | 823 | import tomli as tomllib |
818 | except ImportError: | 824 | except ImportError: |
819 | logger.exception("Neither 'tomllib' nor 'tomli' could be imported. Please use python3.11 or above or install tomli module") | 825 | logger.error("Neither 'tomllib' nor 'tomli' could be imported, cannot scan pyproject.toml.") |
820 | return False | ||
821 | except Exception: | ||
822 | logger.exception("Failed to parse pyproject.toml") | ||
823 | return False | 826 | return False |
824 | 827 | ||
825 | with open(setupscript, "rb") as f: | 828 | try: |
826 | config = tomllib.load(f) | 829 | with open(setupscript, "rb") as f: |
830 | config = tomllib.load(f) | ||
831 | except Exception: | ||
832 | logger.exception("Failed to parse pyproject.toml") | ||
833 | return False | ||
834 | |||
827 | build_backend = config["build-system"]["build-backend"] | 835 | build_backend = config["build-system"]["build-backend"] |
828 | if build_backend in self.build_backend_map: | 836 | if build_backend in self.build_backend_map: |
829 | classes.append(self.build_backend_map[build_backend]) | 837 | classes.append(self.build_backend_map[build_backend]) |