diff options
Diffstat (limited to 'meta/classes/python_pep517.bbclass')
-rw-r--r-- | meta/classes/python_pep517.bbclass | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/meta/classes/python_pep517.bbclass b/meta/classes/python_pep517.bbclass new file mode 100644 index 0000000000..76660e70f8 --- /dev/null +++ b/meta/classes/python_pep517.bbclass | |||
@@ -0,0 +1,52 @@ | |||
1 | # Common infrastructure for Python packages that use PEP-517 compliant packaging. | ||
2 | # https://www.python.org/dev/peps/pep-0517/ | ||
3 | |||
4 | DEPENDS:append = " python3-pip-native" | ||
5 | |||
6 | # The directory where wheels should be written too. Build classes | ||
7 | # will ideally [cleandirs] this but we don't do that here in case | ||
8 | # a recipe wants to install prebuilt wheels. | ||
9 | PEP517_WHEEL_PATH ?= "${WORKDIR}/dist" | ||
10 | |||
11 | PIP_INSTALL_ARGS = "\ | ||
12 | -vvvv \ | ||
13 | --ignore-installed \ | ||
14 | --no-cache \ | ||
15 | --no-deps \ | ||
16 | --no-index \ | ||
17 | --root=${D} \ | ||
18 | --prefix=${prefix} \ | ||
19 | " | ||
20 | |||
21 | PEP517_INSTALL_PYTHON = "python3" | ||
22 | PEP517_INSTALL_PYTHON:class-native = "nativepython3" | ||
23 | |||
24 | python_pep517_do_install () { | ||
25 | COUNT=$(find ${PEP517_WHEEL_PATH} -name '*.whl' | wc -l) | ||
26 | if test $COUNT -eq 0; then | ||
27 | bbfatal No wheels found in ${PEP517_WHEEL_PATH} | ||
28 | elif test $COUNT -gt 1; then | ||
29 | bbfatal More than one wheel found in ${PEP517_WHEEL_PATH}, this should not happen | ||
30 | fi | ||
31 | |||
32 | nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PEP517_WHEEL_PATH}/*.whl | ||
33 | |||
34 | cd ${D} | ||
35 | for i in ${D}${bindir}/* ${D}${sbindir}/*; do | ||
36 | if [ -f "$i" ]; then | ||
37 | sed -i -e "1s,#!.*nativepython3,#!${USRBINPATH}/env ${PEP517_INSTALL_PYTHON}," $i | ||
38 | sed -i -e "s:${PYTHON}:${USRBINPATH}/env\ ${PEP517_INSTALL_PYTHON}:g" $i | ||
39 | sed -i -e "s:${STAGING_BINDIR_NATIVE}:${bindir}:g" $i | ||
40 | # Not everything we find may be Python, so ignore errors | ||
41 | nativepython3 -mpy_compile $(realpath --relative-to=${D} $i) || true | ||
42 | fi | ||
43 | done | ||
44 | } | ||
45 | |||
46 | # A manual do_install that just uses unzip for bootstrapping purposes. Callers should DEPEND on unzip-native. | ||
47 | python_pep517_do_bootstrap_install () { | ||
48 | install -d ${D}${PYTHON_SITEPACKAGES_DIR} | ||
49 | unzip -d ${D}${PYTHON_SITEPACKAGES_DIR} ${PEP517_WHEEL_PATH}/*.whl | ||
50 | } | ||
51 | |||
52 | EXPORT_FUNCTIONS do_install | ||