[v2,1/2] setuptools3.bbclass: add check for pyproject.toml

Message ID 20220225040329.813595-1-tim.orling@konsulko.com
State New
Headers show
Series [v2,1/2] setuptools3.bbclass: add check for pyproject.toml | expand

Commit Message

Tim Orling Feb. 25, 2022, 4:03 a.m. UTC
From: Tim Orling <ticotimo@gmail.com>

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>
---
Changes in v2:
    fix whitespace errors

 meta/classes/setuptools3.bbclass | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Tim Orling Feb. 25, 2022, 4:47 a.m. UTC | #1
Hold off on this one

On Thu, Feb 24, 2022 at 8:04 PM Tim Orling <ticotimo@gmail.com> wrote:

> From: Tim Orling <ticotimo@gmail.com>
>
> 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>
> ---
> Changes in v2:
>     fix whitespace errors
>
>  meta/classes/setuptools3.bbclass | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/meta/classes/setuptools3.bbclass
> b/meta/classes/setuptools3.bbclass
> index 12561340b07..12d662fb49c 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"]
>

This needs results in KeyError when the source has pyproject.toml but not
[buiid-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
>
>

Patch

diff --git a/meta/classes/setuptools3.bbclass b/meta/classes/setuptools3.bbclass
index 12561340b07..12d662fb49c 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 \