Skip to contentSkip to conversation

pip_install_wheel: install wheel with a glob

PATCH In review Ross Burton 3 participants 3 messages Mar 9, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pip_install_wheel: install wheel with a glob

Now that the build systems that use pip_install_wheel are all building their wheel into a directory that we knew was empty before, we can just install *.whl and not need to know the precise names.

By design a pyproject.toml will always build a single wheel, so there shouldn't be any way for this to end up installing more than expected.

This obsoletes PIP_INSTALL_PACKAGE and PYPA_WHEEL, neither of which are needed anymore.

---
 meta/classes/pip_install_wheel.bbclass | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
meta/classes/pip_install_wheel.bbclass +8 -12
index 954a6b750f..3861dae75a 100644
@@ -1,20 +1,10 @@
 DEPENDS:append = " python3-pip-native"
 
-def guess_pip_install_package_name(d):
-    import re
-    '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'''
-    name = d.getVar('PYPI_PACKAGE') or re.sub(r"^python3-", "", d.getVar('BPN'))
-    return name.replace('-', '_')
-
-PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}"
-
 # The directory where wheels should be written too. Build classes
 # will ideally [cleandirs] this but we don't do that here in case
 # a recipe wants to install prebuilt wheels.
 PIP_INSTALL_DIST_PATH ?= "${WORKDIR}/dist"
 
-PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-*-*.whl"
-
 PIP_INSTALL_ARGS = "\
     -vvvv \
     --ignore-installed \
@@ -29,8 +19,14 @@ PIP_INSTALL_PYTHON = "python3"
 PIP_INSTALL_PYTHON:class-native = "nativepython3"
 
 pip_install_wheel_do_install () {
-    nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PYPA_WHEEL} ||
-      bbfatal_log "Failed to pip install wheel. Check the logs."
+    COUNT=$(find ${PIP_INSTALL_DIST_PATH} -name '*.whl' | wc -l)
+    if test $COUNT -eq 0; then
+        bbfatal No wheels found in ${PIP_INSTALL_DIST_PATH}
+    elif test $COUNT -gt 1; then
+        bbfatal More than one wheel found in ${PIP_INSTALL_DIST_PATH}, this should not happen
+    fi
+
+    nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PIP_INSTALL_DIST_PATH}/*.whl
 
     cd ${D}
     for i in ${D}${bindir}/* ${D}${sbindir}/*; do
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Ross Burton

Now that the build systems that use pip_install_wheel are all building their wheel into a directory that we knew was empty before, we can just install *.whl and not need to know the precise names.

By design a pyproject.toml will always build a single wheel, so there shouldn't be any way for this to end up installing more than expected.

This obsoletes PIP_INSTALL_PACKAGE and PYPA_WHEEL, neither of which are needed anymore.

this looks a better approach, we can unbold ton of workaround on meta-openembedded with this

Quoted 59 lines
---
 meta/classes/pip_install_wheel.bbclass | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
meta/classes/pip_install_wheel.bbclass +8 -13
index 954a6b750f..3861dae75a 100644
@@ -1,20 +1,10 @@
 DEPENDS:append = " python3-pip-native"
 
-def guess_pip_install_package_name(d):
-    import re
-    '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'''
-    name = d.getVar('PYPI_PACKAGE') or re.sub(r"^python3-", "", d.getVar('BPN'))
-    return name.replace('-', '_')
-
-PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}"
-
 # The directory where wheels should be written too. Build classes
 # will ideally [cleandirs] this but we don't do that here in case
 # a recipe wants to install prebuilt wheels.
 PIP_INSTALL_DIST_PATH ?= "${WORKDIR}/dist"
 
-PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-*-*.whl"
-
 PIP_INSTALL_ARGS = "\
     -vvvv \
     --ignore-installed \
@@ -29,8 +19,14 @@ PIP_INSTALL_PYTHON = "python3"
 PIP_INSTALL_PYTHON:class-native = "nativepython3"
 
 pip_install_wheel_do_install () {
-    nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PYPA_WHEEL} ||
-      bbfatal_log "Failed to pip install wheel. Check the logs."
+    COUNT=$(find ${PIP_INSTALL_DIST_PATH} -name '*.whl' | wc -l)
+    if test $COUNT -eq 0; then
+        bbfatal No wheels found in ${PIP_INSTALL_DIST_PATH}
+    elif test $COUNT -gt 1; then
+        bbfatal More than one wheel found in ${PIP_INSTALL_DIST_PATH}, this should not happen
+    fi
+
+    nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PIP_INSTALL_DIST_PATH}/*.whl
 
     cd ${D}
     for i in ${D}${bindir}/* ${D}${sbindir}/*; do
--

2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#162975): https://lists.openembedded.org/g/openembedded-core/message/162975
Mute This Topic: https://lists.openembedded.org/mt/89666433/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 9 lines · Khem Raj
Quoted 8 lines · Ross Burton

Now that the build systems that use pip_install_wheel are all building their wheel into a directory that we knew was empty before, we can just install *.whl and not need to know the precise names.

By design a pyproject.toml will always build a single wheel, so there shouldn't be any way for this to end up installing more than expected.

Quoted 6 lines
Quoted 3 lines

This obsoletes PIP_INSTALL_PACKAGE and PYPA_WHEEL, neither of which are needed anymore.

this looks a better approach, we can unbold ton of workaround on meta-openembedded with this

Agreed. The second set of eyes on this is improving things dramatically.

Quoted 71 lines

Review

Quoted 7 lines
---
 meta/classes/pip_install_wheel.bbclass | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/meta/classes/pip_install_wheel.bbclass

meta/classes/pip_install_wheel.bbclass line 5

Quoted 9 lines

index 954a6b750f..3861dae75a 100644

meta/classes/pip_install_wheel.bbclass +0 -3
@@ -1,20 +1,10 @@
 DEPENDS:append = " python3-pip-native"
 
-def guess_pip_install_package_name(d):
-    import re
-    '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'

''

meta/classes/pip_install_wheel.bbclass line 6

Quoted 1 line
meta/classes/pip_install_wheel.bbclass +0 -1
-    name = d.getVar('PYPI_PACKAGE') or re.sub(r"^python3-", "",

d.getVar('BPN'))

Quoted 15 lines
meta/classes/pip_install_wheel.bbclass +0 -6
-    return name.replace('-', '_')
-
-PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}"
-
 # The directory where wheels should be written too. Build classes
 # will ideally [cleandirs] this but we don't do that here in case
 # a recipe wants to install prebuilt wheels.
 PIP_INSTALL_DIST_PATH ?= "${WORKDIR}/dist"
 
-PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-*-*.whl"
-
 PIP_INSTALL_ARGS = "\
     -vvvv \
     --ignore-installed \

meta/classes/pip_install_wheel.bbclass PIP_INSTALL_PYTHON = "python3" · line 26

Quoted 10 lines
meta/classes/pip_install_wheel.bbclass +5 -2
@@ -29,8 +19,14 @@ PIP_INSTALL_PYTHON = "python3"
 PIP_INSTALL_PYTHON:class-native = "nativepython3"
 
 pip_install_wheel_do_install () {
-    nativepython3 -m pip install ${PIP_INSTALL_ARGS} ${PYPA_WHEEL} ||
-      bbfatal_log "Failed to pip install wheel. Check the logs."
+    COUNT=$(find ${PIP_INSTALL_DIST_PATH} -name '*.whl' | wc -l)
+    if test $COUNT -eq 0; then
+        bbfatal No wheels found in ${PIP_INSTALL_DIST_PATH}
+    elif test $COUNT -gt 1; then
+        bbfatal More than one wheel found in ${PIP_INSTALL_DIST_PATH},

this should not happen

meta/classes/pip_install_wheel.bbclass PIP_INSTALL_PYTHON = "python3"

Quoted 3 lines
meta/classes/pip_install_wheel.bbclass +3 -0
+    fi
+
+    nativepython3 -m pip install ${PIP_INSTALL_ARGS}

${PIP_INSTALL_DIST_PATH}/*.whl

Quoted 9 lines
meta/classes/pip_install_wheel.bbclass +0 -1
     cd ${D}
     for i in ${D}${bindir}/* ${D}${sbindir}/*; do
--

2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#162981):
https://lists.openembedded.org/g/openembedded-core/message/162981
Mute This Topic: https://lists.openembedded.org/mt/89666433/924729
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-