* [PATCH 1/2] setuptools3.bbclass: add check for pyproject.toml
@ 2022-02-24 4:11 Tim Orling
2022-02-24 4:12 ` [PATCH 2/2] pip_install_wheel: improved wheel filename guess Tim Orling
0 siblings, 1 reply; 3+ messages in thread
From: Tim Orling @ 2022-02-24 4:11 UTC (permalink / raw)
To: openembedded-core; +Cc: Tim Orling
With help from Peter Kjellerstedt <peter.kjellerstedt@axis.com> via IRC.
Add a check for pyproject.toml in ${S} and if so check if it has a
[build-system] build-backend. Give the user a helpful warning that
the recipe should be changed to one of the PEP-517 classes (instead of
setuptools3.bbclass).
Add SETUPTOOLS_SKIP_BUILD_BACKEND_CHECK variable to skip this check (and
avoid the warning). This is needed for e.g.
python3-setuptools-rust-native which does not build cleanly with
setuptools_build_meta.bbclass
[YOCTO #14736]
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
meta/classes/setuptools3.bbclass | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/meta/classes/setuptools3.bbclass b/meta/classes/setuptools3.bbclass
index 12561340b07..b137cf0ce48 100644
--- a/meta/classes/setuptools3.bbclass
+++ b/meta/classes/setuptools3.bbclass
@@ -18,6 +18,38 @@ setuptools3_do_configure() {
:
}
+SETUPTOOLS_SKIP_BUILD_BACKEND_CHECK ?= "0"
+
+python check_for_pyprojecttoml_build_backend() {
+ import os
+ import tomli
+ from pathlib import Path
+
+ if d.getVar('SETUPTOOLS_SKIP_BUILD_BACKEND_CHECK') == "1":
+ bb.debug(3, "Skipping check for build-backend in pyproject.toml")
+ return 0
+ pyprojecttoml_file = Path(d.getVar('S'), 'pyproject.toml')
+ if pyprojecttoml_file.exists():
+ bb.debug(3, "pyproject.toml found: %s" % pyprojecttoml_file)
+ with open(pyprojecttoml_file, "rb") as f:
+ pyprojecttoml_dict = tomli.load(f)
+ build_system = pyprojecttoml_dict["build-system"]
+ if build_system:
+ bb.debug(3, "[build-system] found in pyproject.toml")
+ backend = build_system.get('build-backend')
+ if backend:
+ bb.debug(3, "build-backend found: %s" % backend)
+ if backend == "flit_core.buildapi":
+ bb.warn("The source has a pyproject.toml which declares 'flit_core.buildapi' as a build backend, please consider 'inherit flit_core' instead of inheriting setuptools3.")
+ elif backend == "setuptools.build_meta":
+ bb.warn("The source has a pyproject.toml which declares 'setuptools.build_meta' as a build backend, please consider 'inherit setuptools_build_meta' instead of inheriting setuptools3.")
+ elif backend == "poetry.core.masonry.api":
+ bb.warn("The source has a pyproject.toml which declares 'poetry.core.masonry.api' as a build backend, please consider 'inherit poetry_core' from meta-python instead of inheriting setuptools3.")
+ else:
+ bb.warn("The source has a pyproject.toml which declares '%s' as a build backend, but this is not currently supported in oe-core." % backend)
+}
+do_configure[prefuncs] += "check_for_pyprojecttoml_build_backend"
+
setuptools3_do_compile() {
cd ${SETUPTOOLS_SETUP_PATH}
NO_FETCH_BUILD=1 \
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] pip_install_wheel: improved wheel filename guess
2022-02-24 4:11 [PATCH 1/2] setuptools3.bbclass: add check for pyproject.toml Tim Orling
@ 2022-02-24 4:12 ` Tim Orling
2022-02-24 13:33 ` [OE-core] " Peter Kjellerstedt
0 siblings, 1 reply; 3+ messages in thread
From: Tim Orling @ 2022-02-24 4:12 UTC (permalink / raw)
To: openembedded-core; +Cc: Tim Orling
Rather than only use PYPI_PACKAGE as a guess, fall back on PN for cases
where a recipe does not inherit pypi.
Wheels can only have alphanumeric characters in the 'distribution'
name [1]. Any other characters are replaced with an underscore. Provide a
function to replace dash with underscore.
[1] https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
meta/classes/pip_install_wheel.bbclass | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/meta/classes/pip_install_wheel.bbclass b/meta/classes/pip_install_wheel.bbclass
index f0312e0b1eb..e0f0b97ad13 100644
--- a/meta/classes/pip_install_wheel.bbclass
+++ b/meta/classes/pip_install_wheel.bbclass
@@ -1,6 +1,15 @@
DEPENDS:append = " python3-pip-native"
-PIP_INSTALL_PACKAGE ?= "${PYPI_PACKAGE}"
+def guess_pip_install_package_name(d):
+ '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'''
+ package = ""
+ if not d.getVar('PYPI_PACKAGE'):
+ package = (d.getVar('PN').replace('-', '_'))
+ else:
+ package = (d.getVar('PYPI_PACKAGE').replace('-', '_'))
+ return package
+
+PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}"
PIP_INSTALL_DIST_PATH ?= "${B}/dist"
PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-${PV}-*.whl"
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [OE-core] [PATCH 2/2] pip_install_wheel: improved wheel filename guess
2022-02-24 4:12 ` [PATCH 2/2] pip_install_wheel: improved wheel filename guess Tim Orling
@ 2022-02-24 13:33 ` Peter Kjellerstedt
0 siblings, 0 replies; 3+ messages in thread
From: Peter Kjellerstedt @ 2022-02-24 13:33 UTC (permalink / raw)
To: Tim Orling, openembedded-core; +Cc: Tim Orling
> -----Original Message-----
> From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Tim Orling
> Sent: den 24 februari 2022 05:12
> To: openembedded-core@lists.openembedded.org
> Cc: Tim Orling <tim.orling@konsulko.com>
> Subject: [OE-core] [PATCH 2/2] pip_install_wheel: improved wheel filename guess
>
> Rather than only use PYPI_PACKAGE as a guess, fall back on PN for cases
> where a recipe does not inherit pypi.
>
> Wheels can only have alphanumeric characters in the 'distribution'
> name [1]. Any other characters are replaced with an underscore. Provide a
> function to replace dash with underscore.
>
> [1] https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode
>
> Signed-off-by: Tim Orling <tim.orling@konsulko.com>
> ---
> meta/classes/pip_install_wheel.bbclass | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/meta/classes/pip_install_wheel.bbclass b/meta/classes/pip_install_wheel.bbclass
> index f0312e0b1eb..e0f0b97ad13 100644
> --- a/meta/classes/pip_install_wheel.bbclass
> +++ b/meta/classes/pip_install_wheel.bbclass
> @@ -1,6 +1,15 @@
> DEPENDS:append = " python3-pip-native"
>
> -PIP_INSTALL_PACKAGE ?= "${PYPI_PACKAGE}"
> +def guess_pip_install_package_name(d):
> + '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'''
> + package = ""
> + if not d.getVar('PYPI_PACKAGE'):
> + package = (d.getVar('PN').replace('-', '_'))
> + else:
> + package = (d.getVar('PYPI_PACKAGE').replace('-', '_'))
> + return package
You can simplify the above to:
+def guess_pip_install_package_name(d):
+ '''https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode'''
+ return (d.getVar('PYPI_PACKAGE') or d.getVar('PN')).replace('-', '_')
> +
> +PIP_INSTALL_PACKAGE ?= "${@guess_pip_install_package_name(d)}"
> PIP_INSTALL_DIST_PATH ?= "${B}/dist"
> PYPA_WHEEL ??= "${PIP_INSTALL_DIST_PATH}/${PIP_INSTALL_PACKAGE}-${PV}-*.whl"
>
> --
> 2.30.2
//Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-24 13:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 4:11 [PATCH 1/2] setuptools3.bbclass: add check for pyproject.toml Tim Orling
2022-02-24 4:12 ` [PATCH 2/2] pip_install_wheel: improved wheel filename guess Tim Orling
2022-02-24 13:33 ` [OE-core] " Peter Kjellerstedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).