Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Ross Burton <ross.burton@arm.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 1/2] classes/setuptools: use tomllib instead of regex to parse pyproject.toml
Date: Wed,  9 Sep 2026 22:55:36 +0100	[thread overview]
Message-ID: <20260909215537.51943-1-ross.burton@arm.com> (raw)

BitBake now vendors in tomli[1] for when the host Python is older than
3.11 so doesn't have tomllib. Rewrite the pyproject.toml parsing from
regexs to tomllib.

Also ensure that the functions in setuptools3 and setuptools_legacy are
identical, as they had diverged.

[1] bitbake 69810e0c0a ("lib/bb/_vendor: resync to add tomli")

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/classes-recipe/setuptools3.bbclass       | 24 +++++++++++----
 .../classes-recipe/setuptools3_legacy.bbclass | 29 ++++++++++++++-----
 2 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/meta/classes-recipe/setuptools3.bbclass b/meta/classes-recipe/setuptools3.bbclass
index b0e4ab5208c..d64e5bdba3a 100644
--- a/meta/classes-recipe/setuptools3.bbclass
+++ b/meta/classes-recipe/setuptools3.bbclass
@@ -13,19 +13,31 @@ SETUPTOOLS_BUILD_ARGS ?= ""
 SETUPTOOLS_SETUP_PATH ?= "${S}"
 
 python do_check_backend() {
+    """
+    Check if this package has a pyproject.toml that specifies a PEP517 build backend, so should be
+    using a different build class.
+    """
+
     if "pep517-backend" in (d.getVar("INSANE_SKIP") or "").split():
         return
 
-    import re
+    try:
+        import tomllib
+    except ImportError:
+        import bb._vendor.tomli as tomllib
+
     filename = d.expand("${SETUPTOOLS_SETUP_PATH}/pyproject.toml")
     if os.path.exists(filename):
-        for line in open(filename):
-            match = re.match(r"build-backend\s*=\s*\W([\w.]+)\W", line)
-            if not match: continue
+        with open(filename, "rb") as f:
+            toml = tomllib.load(f)
 
-            msg = f"inherits setuptools3 but has pyproject.toml with {match[1]}, use the correct class"
+        try:
+            backend = toml["build-system"]["build-backend"]
+            msg = f"inherits setuptools3 but has pyproject.toml specifying backend {backend}, use the correct class"
             oe.qa.handle_error("pep517-backend", msg, d)
-    oe.qa.exit_if_errors(d)
+            oe.qa.exit_if_errors(d)
+        except KeyError:
+            return
 }
 addtask check_backend after do_patch before do_configure
 
diff --git a/meta/classes-recipe/setuptools3_legacy.bbclass b/meta/classes-recipe/setuptools3_legacy.bbclass
index 6b51b9796bc..a70b80cb973 100644
--- a/meta/classes-recipe/setuptools3_legacy.bbclass
+++ b/meta/classes-recipe/setuptools3_legacy.bbclass
@@ -31,16 +31,31 @@ SETUPTOOLS_PYTHON:class-native = "nativepython3"
 SETUPTOOLS_SETUP_PATH ?= "${S}"
 
 python do_check_backend() {
-    import re
+    """
+    Check if this package has a pyproject.toml that specifies a PEP517 build backend, so should be
+    using a different build class.
+    """
+
+    if "pep517-backend" in (d.getVar("INSANE_SKIP") or "").split():
+        return
+
+    try:
+        import tomllib
+    except ImportError:
+        import bb._vendor.tomli as tomllib
+
     filename = d.expand("${SETUPTOOLS_SETUP_PATH}/pyproject.toml")
     if os.path.exists(filename):
-        for line in open(filename):
-            match = re.match(r"build-backend\s*=\s*\W([\w.]+)\W", line)
-            if not match: continue
+        with open(filename, "rb") as f:
+            toml = tomllib.load(f)
 
-            msg = f"inherits setuptools3_legacy but has pyproject.toml with {match[1]}, use the correct class"
-            if "pep517-backend" not in (d.getVar("INSANE_SKIP") or "").split():
-                oe.qa.handle_error("pep517-backend", msg, d)
+        try:
+            backend = toml["build-system"]["build-backend"]
+            msg = f"inherits setuptools3_legacy but has pyproject.toml specifying backend {backend}, use the correct class"
+            oe.qa.handle_error("pep517-backend", msg, d)
+            oe.qa.exit_if_errors(d)
+        except KeyError:
+            return
 }
 addtask check_backend after do_patch before do_configure
 
-- 
2.43.0



             reply	other threads:[~2026-09-09 21:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 21:55 Ross Burton [this message]
2026-09-09 21:55 ` [PATCH v2 2/2] classes/cargo-update-recipe-crates: use tomllib directly Ross Burton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909215537.51943-1-ross.burton@arm.com \
    --to=ross.burton@arm.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox