1# Common infrastructure for Python packages that use PEP-517 compliant packaging. 2# https://www.python.org/dev/peps/pep-0517/ 3# 4# This class will build a wheel in do_compile, and use pypa/installer to install 5# it in do_install. 6 7DEPENDS:append = " python3-installer-native" 8 9# Where to execute the build process from 10PEP517_SOURCE_PATH ?= "${S}" 11 12# The PEP517 build API entry point 13PEP517_BUILD_API ?= "unset" 14 15# The directory where wheels will be written 16PEP517_WHEEL_PATH ?= "${WORKDIR}/dist" 17 18# The interpreter to use for installed scripts 19PEP517_INSTALL_PYTHON = "python3" 20PEP517_INSTALL_PYTHON:class-native = "nativepython3" 21 22# pypa/installer option to control the bytecode compilation 23INSTALL_WHEEL_COMPILE_BYTECODE ?= "--compile-bytecode=0" 24 25# PEP517 doesn't have a specific configure step, so set an empty do_configure to avoid 26# running base_do_configure. 27python_pep517_do_configure () { 28 : 29} 30 31# When we have Python 3.11 we can parse pyproject.toml to determine the build 32# API entry point directly 33python_pep517_do_compile () { 34 cd ${PEP517_SOURCE_PATH} 35 nativepython3 -c "import ${PEP517_BUILD_API} as api; api.build_wheel('${PEP517_WHEEL_PATH}')" 36} 37do_compile[cleandirs] += "${PEP517_WHEEL_PATH}" 38 39python_pep517_do_install () { 40 COUNT=$(find ${PEP517_WHEEL_PATH} -name '*.whl' | wc -l) 41 if test $COUNT -eq 0; then 42 bbfatal No wheels found in ${PEP517_WHEEL_PATH} 43 elif test $COUNT -gt 1; then 44 bbfatal More than one wheel found in ${PEP517_WHEEL_PATH}, this should not happen 45 fi 46 47 nativepython3 -m installer ${INSTALL_WHEEL_COMPILE_BYTECODE} --interpreter "${USRBINPATH}/env ${PEP517_INSTALL_PYTHON}" --destdir=${D} ${PEP517_WHEEL_PATH}/*.whl 48} 49 50# A manual do_install that just uses unzip for bootstrapping purposes. Callers should DEPEND on unzip-native. 51python_pep517_do_bootstrap_install () { 52 install -d ${D}${PYTHON_SITEPACKAGES_DIR} 53 unzip -d ${D}${PYTHON_SITEPACKAGES_DIR} ${PEP517_WHEEL_PATH}/*.whl 54} 55 56EXPORT_FUNCTIONS do_configure do_compile do_install 57