blob: 7cdb9c8f9dfcd994ddbd233d783b031f53b23251 [file] [log] [blame]
Andrew Geissler9aee5002022-03-30 16:27:02 +00001# 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
Andrew Geissler615f2f12022-07-15 14:00:58 -05007DEPENDS:append = " python3-picobuild-native python3-installer-native"
Andrew Geissler9aee5002022-03-30 16:27:02 +00008
9# Where to execute the build process from
10PEP517_SOURCE_PATH ?= "${S}"
11
Andrew Geissler9aee5002022-03-30 16:27:02 +000012# The directory where wheels will be written
13PEP517_WHEEL_PATH ?= "${WORKDIR}/dist"
14
Andrew Geissler615f2f12022-07-15 14:00:58 -050015PEP517_PICOBUILD_OPTS ?= ""
16
Andrew Geissler9aee5002022-03-30 16:27:02 +000017# The interpreter to use for installed scripts
18PEP517_INSTALL_PYTHON = "python3"
19PEP517_INSTALL_PYTHON:class-native = "nativepython3"
20
21# pypa/installer option to control the bytecode compilation
22INSTALL_WHEEL_COMPILE_BYTECODE ?= "--compile-bytecode=0"
23
24# PEP517 doesn't have a specific configure step, so set an empty do_configure to avoid
25# running base_do_configure.
26python_pep517_do_configure () {
27 :
28}
29
30# When we have Python 3.11 we can parse pyproject.toml to determine the build
31# API entry point directly
32python_pep517_do_compile () {
Andrew Geissler615f2f12022-07-15 14:00:58 -050033 nativepython3 -m picobuild --source ${PEP517_SOURCE_PATH} --dest ${PEP517_WHEEL_PATH} --wheel ${PEP517_PICOBUILD_OPTS}
Andrew Geissler9aee5002022-03-30 16:27:02 +000034}
35do_compile[cleandirs] += "${PEP517_WHEEL_PATH}"
36
37python_pep517_do_install () {
38 COUNT=$(find ${PEP517_WHEEL_PATH} -name '*.whl' | wc -l)
39 if test $COUNT -eq 0; then
40 bbfatal No wheels found in ${PEP517_WHEEL_PATH}
41 elif test $COUNT -gt 1; then
42 bbfatal More than one wheel found in ${PEP517_WHEEL_PATH}, this should not happen
43 fi
44
45 nativepython3 -m installer ${INSTALL_WHEEL_COMPILE_BYTECODE} --interpreter "${USRBINPATH}/env ${PEP517_INSTALL_PYTHON}" --destdir=${D} ${PEP517_WHEEL_PATH}/*.whl
46}
47
48# A manual do_install that just uses unzip for bootstrapping purposes. Callers should DEPEND on unzip-native.
49python_pep517_do_bootstrap_install () {
50 install -d ${D}${PYTHON_SITEPACKAGES_DIR}
51 unzip -d ${D}${PYTHON_SITEPACKAGES_DIR} ${PEP517_WHEEL_PATH}/*.whl
52}
53
54EXPORT_FUNCTIONS do_configure do_compile do_install