Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame^] | 1 | DEPENDS:append = " python3-pip-native" |
| 2 | |
| 3 | def guess_pip_install_package_name(d): |
| 4 | '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode''' |
| 5 | return (d.getVar('PYPI_PACKAGE') or d.getVar('PN')).replace('-', '_') |
| 6 | |
| 7 | PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}" |
| 8 | PIP_INSTALL_DIST_PATH ?= "${B}/dist" |
| 9 | PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-${PV}-*.whl" |
| 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 | pip_install_wheel_do_install:prepend () { |
| 22 | install -d ${D}${PYTHON_SITEPACKAGES_DIR} |
| 23 | } |
| 24 | |
| 25 | export PYPA_WHEEL |
| 26 | |
| 27 | PIP_INSTALL_PYTHON = "python3" |
| 28 | PIP_INSTALL_PYTHON:class-native = "nativepython3" |
| 29 | |
| 30 | pip_install_wheel_do_install () { |
| 31 | nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PYPA_WHEEL} || |
| 32 | bbfatal_log "Failed to pip install wheel. Check the logs." |
| 33 | |
| 34 | for i in ${D}${bindir}/* ${D}${sbindir}/*; do |
| 35 | if [ -f "$i" ]; then |
| 36 | sed -i -e "1s,#!.*nativepython3,#!${USRBINPATH}/env ${PIP_INSTALL_PYTHON}," $i |
| 37 | sed -i -e "s:${PYTHON}:${USRBINPATH}/env\ ${PIP_INSTALL_PYTHON}:g" $i |
| 38 | sed -i -e "s:${STAGING_BINDIR_NATIVE}:${bindir}:g" $i |
| 39 | # Recompile after modifying it |
| 40 | cd ${D} |
| 41 | file=`echo $i | sed 's:^${D}/::'` |
| 42 | ${STAGING_BINDIR_NATIVE}/python3-native/python3 -c "from py_compile import compile; compile('$file')" |
| 43 | cd - |
| 44 | fi |
| 45 | done |
| 46 | } |
| 47 | |
| 48 | EXPORT_FUNCTIONS do_install |