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