* [PATCH v2 1/2] classes/setuptools: use tomllib instead of regex to parse pyproject.toml
@ 2026-09-09 21:55 Ross Burton
2026-09-09 21:55 ` [PATCH v2 2/2] classes/cargo-update-recipe-crates: use tomllib directly Ross Burton
0 siblings, 1 reply; 2+ messages in thread
From: Ross Burton @ 2026-09-09 21:55 UTC (permalink / raw)
To: openembedded-core
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH v2 2/2] classes/cargo-update-recipe-crates: use tomllib directly
2026-09-09 21:55 [PATCH v2 1/2] classes/setuptools: use tomllib instead of regex to parse pyproject.toml Ross Burton
@ 2026-09-09 21:55 ` Ross Burton
0 siblings, 0 replies; 2+ messages in thread
From: Ross Burton @ 2026-09-09 21:55 UTC (permalink / raw)
To: openembedded-core
Now that BitBake vendors in a copy of tomli for when the host Python is
too old to support tomllib, we can do the crate update logic directly
in the task instead of passing an large inline script to python3-native.
The only changes are the removal of nativepython3 and not relying on
bitbake's shell expansion to expand variable names.
[1] bitbake 69810e0c0a ("lib/bb/_vendor: resync to add tomli")
Signed-off-by: Ross Burton <ross.burton@arm.com>
---
.../cargo-update-recipe-crates.bbclass | 101 ++++++++++--------
1 file changed, 54 insertions(+), 47 deletions(-)
diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index 47e845c8221..e62039208c1 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -14,7 +14,6 @@
## To perform the update: bitbake -c update_crates recipe-name
addtask do_update_crates after do_patch
-do_update_crates[depends] = "python3-native:do_populate_sysroot"
do_update_crates[nostamp] = "1"
do_update_crates[doc] = "Update the recipe by reading Cargo.lock and write in ${THISDIR}/${BPN}-crates.inc"
@@ -23,58 +22,66 @@ RECIPE_UPGRADE_EXTRA_TASKS += "do_update_crates"
# The directory where to search for Cargo.lock files
CARGO_LOCK_SRC_DIR ??= "${S}"
-do_update_crates() {
- TARGET_FILE="${THISDIR}/${BPN}-crates.inc"
+python do_update_crates() {
+ cargo_lock_src_dir = d.getVar("CARGO_LOCK_SRC_DIR")
- nativepython3 - <<EOF
+ def get_crates(filename):
+ try:
+ import tomllib
+ except ImportError:
+ import bb._vendor.tomli as tomllib
-def get_crates(f):
- import tomllib
- c_list = '# from %s' % os.path.relpath(f, '${CARGO_LOCK_SRC_DIR}')
- c_list += '\nSRC_URI += " \\\'
- crates = tomllib.load(open(f, 'rb'))
+ c_list = '# from %s' % os.path.relpath(filename, cargo_lock_src_dir)
+ c_list += '\nSRC_URI += " \\'
+ with open(filename, 'rb') as fp:
+ crates = tomllib.load(fp)
- # Build a list with crates info that have crates.io in the source
- crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package']))
+ # Build a list with crates info that have crates.io in the source
+ crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package']))
- if not crates_candidates:
- print("WARNING: Unable to find any candidate crates that use crates.io")
- return None
+ if not crates_candidates:
+ print("WARNING: Unable to find any candidate crates that use crates.io")
+ return None
- # Update crates uri and their checksum, to avoid name clashing on the checksum
- # we need to rename crates with name and version to have a unique key
- cksum_list = ''
- for c in crates_candidates:
- rename = "%s-%s" % (c['name'], c['version'])
- c_list += '\n crate://crates.io/%s/%s \\\' % (c['name'], c['version'])
- if 'checksum' in c:
- cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum'])
+ # Update crates uri and their checksum, to avoid name clashing on the checksum
+ # we need to rename crates with name and version to have a unique key
+ cksum_list = ''
+ for c in crates_candidates:
+ rename = "%s-%s" % (c['name'], c['version'])
+ c_list += '\n crate://crates.io/%s/%s \\' % (c['name'], c['version'])
+ if 'checksum' in c:
+ cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum'])
- c_list += '\n"\n'
- c_list += cksum_list
- c_list += '\n'
- return c_list
+ c_list += '\n"\n'
+ c_list += cksum_list
+ c_list += '\n'
+ return c_list
-import os
-crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
-found = False
-for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
- # ignore git and patches directories
- if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.pc')):
- continue
- if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.git')):
- continue
- for file in files:
- if file == 'Cargo.lock':
- cargo_lock_path = os.path.join(root, file)
- c = get_crates(cargo_lock_path)
- if c is not None:
- crates += c
-if crates is None:
- raise ValueError("Unable to find any Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
-with open("${TARGET_FILE}", 'w') as f:
- f.write(crates)
-EOF
+ import os
- bbnote "Successfully update crates inside '${TARGET_FILE}'"
+ pn = d.getVar("PN")
+ crates = f"# Autogenerated with 'bitbake -c update_crates {pn}'\n\n"
+
+ found = False
+ for root, dirs, files in os.walk(cargo_lock_src_dir):
+ # ignore git and patches directories
+ if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')):
+ continue
+ if root.startswith(os.path.join(cargo_lock_src_dir, '.git')):
+ continue
+ for file in files:
+ if file == 'Cargo.lock':
+ cargo_lock_path = os.path.join(root, file)
+ c = get_crates(cargo_lock_path)
+ if c is not None:
+ crates += c
+
+ if crates is None:
+ raise ValueError(f"Unable to find any Cargo.lock in {cargo_lock_src_dir}")
+
+ target_file = d.expand("${THISDIR}/${BPN}-crates.inc")
+ with open(target_file, 'w') as f:
+ f.write(crates)
+
+ bb.note(f"Successfully updated crates inside {target_file}")
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-09 21:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09 21:55 [PATCH v2 1/2] classes/setuptools: use tomllib instead of regex to parse pyproject.toml Ross Burton
2026-09-09 21:55 ` [PATCH v2 2/2] classes/cargo-update-recipe-crates: use tomllib directly Ross Burton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox