Skip to contentSkip to conversation

python_hatchling: remove empty python sysroot dirs

PATCH Superseded Trevor Gamblin 2 participants 2 messages May 31, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python_hatchling: remove empty python sysroot dirs

In some cases, empty versioned directories are being left behind in sysroots from previous versions of packages. This appears to be found with recipes relying on hatchling, and causes errors at the do_compile step:

|   File "/workspace/yocto/manual/openembedded-core/build/tmp-glibc/work/core2-64-oe-linux/python3-iniconfig/2.0.0-r0/recipe-sysroot-native/usr/lib/python3.11/site-packages/packaging/version.py", line 197, in __init__
|     match = self._regex.search(version)
|             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| TypeError: expected string or bytes-like object, got 'NoneType'

To fix this error, add a do_prepare_recipe_sysroot postfunc in the python_hatchling class that removes any nested empty directories from the sysroots during build, so that dependent recipes don't get caught on them.

---
 meta/classes-recipe/python_hatchling.bbclass | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/classes-recipe/python_hatchling.bbclass +9 -0
index b9e6582eb5..a20e243161 100644
@@ -7,3 +7,12 @@
 inherit python_pep517 python3native python3-dir setuptools3-base
 
 DEPENDS += "python3-hatchling-native"
+
+# delete nested, empty directories from the python site-packages path. We don't use 
+# ${PYTHON_SITEPACKAGES_DIR} in the path specification so that python3-hatchling 
+# still builds OK
+hatchling_rm_emptydirs () {
+        find ${RECIPE_SYSROOT_NATIVE}/usr/lib/${PYTHON_DIR}/site-packages/* -depth -type d -empty -delete
+}
+
+do_prepare_recipe_sysroot[postfuncs] += " hatchling_rm_emptydirs"
Signature · 1 line
2.40.1
#1 lore raw
Quoted 27 lines · Trevor Gamblin

In some cases, empty versioned directories are being left behind in sysroots from previous versions of packages. This appears to be found with recipes relying on hatchling, and causes errors at the do_compile step:

Quoted 4 lines

File "/workspace/yocto/manual/openembedded-core/build/tmp-glibc/work/core2-64-oe-linux/python3-iniconfig/2.0.0-r0/recipe-sysroot-native/usr/lib/python3.11/site-packages/packaging/version.py", line 197, in __init__
match = self._regex.search(version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

To fix this error, add a do_prepare_recipe_sysroot postfunc in the python_hatchling class that removes any nested empty directories from the sysroots during build, so that dependent recipes don't get caught on them.

---
 meta/classes-recipe/python_hatchling.bbclass | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/classes-recipe/python_hatchling.bbclass +0 -0
index b9e6582eb5..a20e243161 100644
@@ -7,3 +7,12 @@
 inherit python_pep517 python3native python3-dir setuptools3-base
 

meta/classes-recipe/python_hatchling.bbclass line 18

Quoted 10 lines
meta/classes-recipe/python_hatchling.bbclass +9 -0
 DEPENDS += "python3-hatchling-native"
+
+# delete nested, empty directories from the python site-packages path. We don't use 
+# ${PYTHON_SITEPACKAGES_DIR} in the path specification so that python3-hatchling 
+# still builds OK
+hatchling_rm_emptydirs () {
+        find ${RECIPE_SYSROOT_NATIVE}/usr/lib/${PYTHON_DIR}/site-packages/* -depth -type d -empty -delete
+}
+
+do_prepare_recipe_sysroot[postfuncs] += " hatchling_rm_emptydirs"

Looking at the patch, this is the right direction I'm not 100% convinced the details are quite right.

Should we be clearing from RECIPE_SYSROOT or RECIPE_SYSROOT_NATIVE? Also, can we avoid hardcoding /usr/lib? That probably won't work for multilibs or some other combinations of settings some use.

Cheers,

Richard