Yocto python packaging
Skill BenGardiner/bitbake-yocto-agent-skills/yocto-python-packaging
Agent skills for making and fixing bitbake stuff
npx -y skills add BenGardiner/bitbake-yocto-agent-skills --skill yocto-python-packagingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Packages Python modules using OpenEmbedded PEP 517 infrastructure for Yocto 5.0+. Use when writing recipes for pyproject.toml projects or resolving Scarthgap-specific Python build errors. Do not use for legacy setuptools recipes (pre-PEP 517) or non-Python Yocto components.
SKILL.md
4.1 KB, as published. Nobody here has run it
Yocto Python3 Packaging (Scarthgap/5.0+)
Follow these patterns to package modern Python modules using the OpenEmbedded PEP 517 build infrastructure.
1. Core Build System Selection
Do not use inherit setuptools3 for packages containing a pyproject.toml. Select the correct class based on the [build-system] defined in the source.
Map the build backend (in pyproject.toml) to the appropriate Yocto class to inherit:
hatchling.build->inherit python_hatchlingsetuptools.build_meta->inherit python_setuptools_build_metaflit_core.buildapi->inherit python_flit_corepoetry.core.masonry.api->inherit python_pep517
2. Error Resolution Procedures
Error: ModuleNotFoundError: No module named 'setuptools.command.bdist_wheel'
- Diagnosis: The recipe is likely using
inherit setuptools3on a package that requires a PEP 517 build frontend (likepython3-build-native). - Action: Switch to
inherit python_setuptools_build_meta. This ensurespython3-wheel-nativeandpython3-installer-nativeare present in the sysroot.
Error: Circular Dependencies in python3-build-native
- Diagnosis: Attempting to manually create native build-tool recipes that require themselves to install.
- Action: Always leverage the upstream
python_pep517.bbclass. It utilizes a "bootstrap" mechanism (Stage 0) to break the dependency loop between the installer and the builder. Do not attempt to overridepython3-build-nativemanually.
3. Dependency Management
Modern Python packaging differentiates between build-time and runtime dependencies. Implement them as follows:
- Build-time (
DEPENDS): Use for requirements in the native sysroot to create the wheel.- Example:
DEPENDS += "python3-hatchling-native"
- Example:
- Runtime (
RDEPENDS): Use for requirements on the target image for the package to function.- Example:
RDEPENDS:${PN} += "python3-compression python3-core"
- Example:
4. Best Practices for Scarthgap
Apply the following practices when developing recipes:
- Prefer PyPI: Use
inherit pypiwhenever possible to automateSRC_URIconstruction and versioning. - Verify Backend: Always check the source
pyproject.tomlbefore writing the recipe. If multiple backends are supported,hatchlingis the modern preference for many core utilities. - Use Layered Definitions: Ensure
meta-pythonis updated to the Scarthgap branch to avoid version mismatches between the class logic and the recipes.
5. Fetch Accurate PyPI Data via Python
When curl or jq are unavailable, use Python to reliably extract the correct source URLs and SHA256 hashes for Yocto recipes.
- Execute script:
(Replace./scripts/fetch_pypi_data.py <package_name> <version><package_name>and<version>with the target package details).
6. Fix SPDX Compliance via .bbappend
Patch upstream or external recipes to fix license issues without modifying their source by using a .bbappend in the local layer.
- Example command:
echo 'LICENSE = "BSD-3-Clause"' > meta-tcat/recipes-python/jupyter-console/python3-jupyter-console_%.bbappend
7. Anticipate Packaging Quirks and Provider Conflicts
- Static Assets: When dealing with UI, web, or Jupyter components, preemptively check
FILES:${PN}and prepare for static assets landing outside of the standard Pythonsite-packagesdirectory. - Conflicting Providers: Do not create competing recipes (e.g., a custom fork recipe alongside the original). Inspect the system's
core-image.bbfirst to understand existing provider constraints.- Apply custom forks via
SRC_URIpatches to the existing recipe. - Alternatively, utilize
PREFERRED_PROVIDERglobally rather than battling package manager conflicts in the image rootfs.
- Apply custom forks via