]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blame - meta/classes-recipe/python_pep517.bbclass
python3_pip517: just count wheels in the directory, not subdirectories
[thirdparty/openembedded/openembedded-core.git] / meta / classes-recipe / python_pep517.bbclass
CommitLineData
880c1ea3
RP
1#
2# Copyright OpenEmbedded Contributors
3#
081a391f
RP
4# SPDX-License-Identifier: MIT
5#
880c1ea3 6
3bdf64b9
RB
7# Common infrastructure for Python packages that use PEP-517 compliant packaging.
8# https://www.python.org/dev/peps/pep-0517/
d42664a5
RB
9#
10# This class will build a wheel in do_compile, and use pypa/installer to install
11# it in do_install.
3bdf64b9 12
202c2e3c 13DEPENDS:append = " python3-build-native python3-installer-native"
32a61afd 14
69944121
RB
15# Where to execute the build process from
16PEP517_SOURCE_PATH ?= "${S}"
17
d42664a5 18# The directory where wheels will be written
3bdf64b9 19PEP517_WHEEL_PATH ?= "${WORKDIR}/dist"
8e7ae424 20
202c2e3c
RB
21# Other options to pass to build
22PEP517_BUILD_OPTS ?= ""
35104958 23
d42664a5 24# The interpreter to use for installed scripts
3bdf64b9
RB
25PEP517_INSTALL_PYTHON = "python3"
26PEP517_INSTALL_PYTHON:class-native = "nativepython3"
32a61afd 27
d42664a5 28# pypa/installer option to control the bytecode compilation
f780f6d9
RB
29INSTALL_WHEEL_COMPILE_BYTECODE ?= "--compile-bytecode=0"
30
fd17edbd
RB
31# PEP517 doesn't have a specific configure step, so set an empty do_configure to avoid
32# running base_do_configure.
33python_pep517_do_configure () {
34 :
35}
36
862f68f3
RB
37# When we have Python 3.11 we can parse pyproject.toml to determine the build
38# API entry point directly
39python_pep517_do_compile () {
202c2e3c 40 nativepython3 -m build --no-isolation --wheel --outdir ${PEP517_WHEEL_PATH} ${PEP517_SOURCE_PATH} ${PEP517_BUILD_OPTS}
862f68f3
RB
41}
42do_compile[cleandirs] += "${PEP517_WHEEL_PATH}"
43
3bdf64b9 44python_pep517_do_install () {
0142da47 45 COUNT=$(find ${PEP517_WHEEL_PATH} -name '*.whl' -maxdepth 1 | wc -l)
e6e4c63b 46 if test $COUNT -eq 0; then
3bdf64b9 47 bbfatal No wheels found in ${PEP517_WHEEL_PATH}
e6e4c63b 48 elif test $COUNT -gt 1; then
3bdf64b9 49 bbfatal More than one wheel found in ${PEP517_WHEEL_PATH}, this should not happen
e6e4c63b
RB
50 fi
51
f780f6d9 52 nativepython3 -m installer ${INSTALL_WHEEL_COMPILE_BYTECODE} --interpreter "${USRBINPATH}/env ${PEP517_INSTALL_PYTHON}" --destdir=${D} ${PEP517_WHEEL_PATH}/*.whl
32a61afd
TO
53}
54
d5d702a2 55# A manual do_install that just uses unzip for bootstrapping purposes. Callers should DEPEND on unzip-native.
3bdf64b9 56python_pep517_do_bootstrap_install () {
d5d702a2 57 install -d ${D}${PYTHON_SITEPACKAGES_DIR}
3bdf64b9 58 unzip -d ${D}${PYTHON_SITEPACKAGES_DIR} ${PEP517_WHEEL_PATH}/*.whl
d5d702a2
RB
59}
60
fd17edbd 61EXPORT_FUNCTIONS do_configure do_compile do_install