python_mesonpy.bbclass: New class
PATCH v2 1/4 python_mesonpy.bbclass: New class
Some python modules (e.g. SciPy, scikit-image) use meson-python (a.k.a. mesonpy) in pyproject.toml:
[build-system]
build-backend = 'mesonpy'
This class, together with python3-meson-python and its dependencies will allow building such modules.
--- meta-python/classes/python_mesonpy.bbclass | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 meta-python/classes/python_mesonpy.bbclass
meta-python/classes/python_mesonpy.bbclass new file +17 -0
@@ -0,0 +1,17 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +inherit setuptools3-base python3targetconfig python_pep517 meson-common + +DEPENDS += "python3-wheel-native python3-meson-python-native" + +PEP517_BUILD_OPTS = '--config-setting=setup-args="${MESONOPTS} ${MESON_SOURCEPATH} ${B} ${MESON_CROSS_FILE} ${EXTRA_OEMESON}"' + +export MESONPY_BUILD = "${B}" + +# Python pyx -> c -> so build leaves absolute build paths in the code +INSANE_SKIP:${PN} += "buildpaths" +INSANE_SKIP:${PN}-src += "buildpaths"
Signature · 1 line
2.39.2
PATCH v2 2/4 python3-patchelf: New recipe
Dummy module to indicate the presence of patchelf. Used by python3-meson-python.
The CMakeLists.txt file is a crippled copy from this patchelf python module's sources, removing almost everything, and adding a dummy install target, so do_install() doesn't fail.
--- .../python/python3-patchelf/CMakeLists.txt | 7 +++++ .../python/python3-patchelf/patchelf.patch | 11 +++++++ .../python/python3-patchelf_0.17.2.1.bb | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-patchelf/CMakeLists.txt create mode 100644 meta-python/recipes-devtools/python/python3-patchelf/patchelf.patch create mode 100644 meta-python/recipes-devtools/python/python3-patchelf_0.17.2.1.bb
meta-python/recipes-devtools/python/python3-patchelf/CMakeLists.txt new file +7 -0
@@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.6) + +project(PatchelfPythonDistributions) + +install(CODE " + message(STATUS \"Install patchelf project\") +")
meta-python/recipes-devtools/python/python3-patchelf/patchelf.patch new file +11 -0
@@ -0,0 +1,11 @@ +--- patchelf-0.17.2.1/setup.py.old 2023-03-13 10:12:55.951514413 +0100 ++++ patchelf-0.17.2.1/setup.py 2023-03-13 10:13:18.877751074 +0100 +@@ -95,8 +95,6 @@ + version=get_version(), + cmdclass=cmdclass, + +- scripts=["bin/patchelf"], +- + url="https://github.com/NixOS/patchelf", + project_urls={ + "Source Code": "https://github.com/mayeut/patchelf-pypi",
meta-python/recipes-devtools/python/python3-patchelf_0.17.2.1.bb new file +31 -0
@@ -0,0 +1,31 @@ +# This is a dummy package needed by python3-meson-python +SUMMARY = "A small utility to modify the dynamic linker and RPATH of ELF executables." +LICENSE = "GPL-3.0-or-later & Apache-2.0" +LIC_FILES_CHKSUM = " \ + file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327 \ + file://COPYING;md5=d32239bcb673463ab874e80d47fae504 \ +" + +DEPENDS = "python3-scikit-build-native" + +PYPI_PACKAGE = "patchelf" +PYPI_ARCHIVE_NAME_PREFIX = "pypi-" + +inherit pypi python_setuptools_build_meta +SRC_URI[sha256sum] = "a6eb0dd452ce4127d0d5e1eb26515e39186fa609364274bc1b0b77539cfa7031" + +SRC_URI += " \ + file://CMakeLists.txt \ + file://patchelf.patch \ +" + +addtask do_patchbuild after do_patch before do_configure + +do_patchbuild () { + rm -f ${S}/CMakeLists.txt + cp ${WORKDIR}/CMakeLists.txt ${S}/ +} + +RDEPENDS:${PN} = "patchelf" + +BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.39.2
Re: [oe] [meta-python][PATCH v2 2/4] python3-patchelf: New recipe
Quoted 1 line · Zoltan Boszormenyi via lists.openembedded.org
+# This is a dummy package needed by python3-meson-python
I’m not sure I’d call this a dummy package.
Quoted 1 line
+DEPENDS = "python3-scikit-build-native"
If you’re not building native code with cmake then you don’t need this, just switch skbuild to setuptools.
meta-python/recipes-devtools/python/python3-patchelf_0.17.2.1.bb line 27
Quoted 11 lines
meta-python/recipes-devtools/python/python3-patchelf_0.17.2.1.bb new file +11
-0+SRC_URI += " \ + file://CMakeLists.txt \ + file://patchelf.patch \ +" + +addtask do_patchbuild after do_patch before do_configure + +do_patchbuild () { + rm -f ${S}/CMakeLists.txt + cp ${WORKDIR}/CMakeLists.txt ${S}/ +}
Use subdir=${S} to put the CMakeLists.txt in the right place instead of doing this.
However, this recipe doesn’t build patchelf and doesn’t have any python code. So what’s the point of it?
If there are packages which depend on this, either patch out that dependency (as we can just DEPEND on patchelf-native) or write the few lines of pyproject.toml to ship an empty package directly.
Ross
PATCH v2 3/4 python3-pyproject-metadata: New recipe
In reply to Zoltán BöszörményiDependency of python3-meson-python.
--- .../python/python3-pyproject-metadata_0.7.1.bb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-pyproject-metadata_0.7.1.bb
meta-python/recipes-devtools/python/python3-pyproject-metadata_0.7.1.bb new file +10 -0
@@ -0,0 +1,10 @@ +SUMMARY = "PEP 621 metadata parsing" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE;md5=310439af287b0fb4780b2ad6907c256c" + +PYPI_PACKAGE = "pyproject-metadata" + +inherit pypi python_setuptools_build_meta +SRC_URI[sha256sum] = "0a94f18b108b9b21f3a26a3d541f056c34edcb17dc872a144a15618fed7aef67" + +BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.39.2
Re: [oe] [meta-python][PATCH v2 3/4] python3-pyproject-metadata: New recipe
Quoted 1 line · Zoltan Boszormenyi via lists.openembedded.org
+PYPI_PACKAGE = "pyproject-metadata”
This can be removed as that’s the default value.
Ross
PATCH v2 4/4 python3-meson-python: New recipe
In reply to Zoltán BöszörményiUsed by inherit python_mesonpy.
--- .../remove-hardcoded-setup-args.patch | 123 ++++++++++++++++++ .../use-installed-mesonpy.patch | 9 ++ .../python3-meson-python_0.13.0.pre0.bb | 28 ++++ 3 files changed, 160 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-meson-python/remove-hardcoded-setup-args.patch create mode 100644 meta-python/recipes-devtools/python/python3-meson-python/use-installed-mesonpy.patch create mode 100644 meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb
meta-python/recipes-devtools/python/python3-meson-python/remove-hardcoded-setup-args.patch new file +123 -0
@@ -0,0 +1,123 @@ +--- meson_python-0.13.0.pre0/mesonpy/__init__.py.old 1970-01-01 01:00:00.000000000 +0100 ++++ meson_python-0.13.0.pre0/mesonpy/__init__.py 2023-03-13 21:26:52.263117416 +0100 +@@ -669,8 +669,6 @@ + self._build_dir = pathlib.Path(build_dir).absolute() if build_dir else (self._working_dir / 'build') + self._editable_verbose = editable_verbose + self._install_dir = self._working_dir / 'install' +- self._meson_native_file = self._source_dir / '.mesonpy-native-file.ini' +- self._meson_cross_file = self._source_dir / '.mesonpy-cross-file.ini' + self._meson_args: MesonArgs = collections.defaultdict(list) + self._env = os.environ.copy() + +@@ -679,32 +677,6 @@ + if ninja_path is not None: + self._env.setdefault('NINJA', str(ninja_path)) + +- # setuptools-like ARCHFLAGS environment variable support +- if sysconfig.get_platform().startswith('macosx-'): +- archflags = self._env.get('ARCHFLAGS') +- if archflags is not None: +- arch, *other = filter(None, (x.strip() for x in archflags.split('-arch'))) +- if other: +- raise ConfigError(f'Multi-architecture builds are not supported but $ARCHFLAGS={archflags!r}') +- macver, _, nativearch = platform.mac_ver() +- if arch != nativearch: +- x = self._env.setdefault('_PYTHON_HOST_PLATFORM', f'macosx-{macver}-{arch}') +- if not x.endswith(arch): +- raise ConfigError(f'$ARCHFLAGS={archflags!r} and $_PYTHON_HOST_PLATFORM={x!r} do not agree') +- family = 'aarch64' if arch == 'arm64' else arch +- cross_file_data = textwrap.dedent(f''' +- [binaries] +- c = ['cc', '-arch', {arch!r}] +- cpp = ['c++', '-arch', {arch!r}] +- [host_machine] +- system = 'Darwin' +- cpu = {arch!r} +- cpu_family = {family!r} +- endian = 'little' +- ''') +- self._meson_cross_file.write_text(cross_file_data) +- self._meson_args['setup'].extend(('--cross-file', os.fspath(self._meson_cross_file))) +- + # load config -- PEP 621 support is optional + self._config = tomllib.loads(self._source_dir.joinpath('pyproject.toml').read_text()) + self._pep621 = 'project' in self._config +@@ -749,19 +721,6 @@ + [binaries] + python = '{sys.executable}' + ''') +- native_file_mismatch = ( +- not self._meson_native_file.exists() +- or self._meson_native_file.read_text() != native_file_data +- ) +- if native_file_mismatch: +- try: +- self._meson_native_file.write_text(native_file_data) +- except OSError: +- # if there are permission errors or something else in the source +- # directory, put the native file in the working directory instead +- # (this won't survive multiple calls -- Meson will have to be reconfigured) +- self._meson_native_file = self._working_dir / '.mesonpy-native-file.ini' +- self._meson_native_file.write_text(native_file_data) + + # Don't reconfigure if build directory doesn't have meson-private/coredata.data + # (means something went wrong) +@@ -784,7 +743,7 @@ + def _proc(self, *args: str) -> None: + """Invoke a subprocess.""" + print('{cyan}{bold}+ {}{reset}'.format(' '.join(args), **_STYLES)) +- r = subprocess.run(list(args), env=self._env, cwd=self._build_dir) ++ r = subprocess.run(' '.join(list(args)).split(), env=self._env, cwd=self._build_dir) + if r.returncode != 0: + raise SystemExit(r.returncode) + +@@ -800,22 +759,6 @@ + """ + sys_paths = mesonpy._introspection.SYSCONFIG_PATHS + setup_args = [ +- f'--prefix={sys.base_prefix}', +- os.fspath(self._source_dir), +- os.fspath(self._build_dir), +- f'--native-file={os.fspath(self._meson_native_file)}', +- # TODO: Allow configuring these arguments +- '-Ddebug=false', +- '-Doptimization=2', +- +- # XXX: This should not be needed, but Meson is using the wrong paths +- # in some scenarios, like on macOS. +- # https://github.com/mesonbuild/meson-python/pull/87#discussion_r1047041306 +- '--python.purelibdir', +- sys_paths['purelib'], +- '--python.platlibdir', +- sys_paths['platlib'], +- + # user args + *self._meson_args['setup'], + ] +@@ -905,8 +848,7 @@ + editable_verbose: bool = False, + ) -> Iterator[Project]: + """Creates a project instance pointing to a temporary working directory.""" +- with tempfile.TemporaryDirectory(prefix='.mesonpy-', dir=os.fspath(source_dir)) as tmpdir: +- yield cls(source_dir, tmpdir, build_dir, meson_args, editable_verbose) ++ yield cls(source_dir, build_dir, build_dir, meson_args, editable_verbose) + + @functools.lru_cache() + def _info(self, name: str) -> Dict[str, Any]: +@@ -1105,15 +1047,7 @@ + for key, value in config_settings.items() + } + +- builddir_value = config_settings.get('builddir', {}) +- if len(builddir_value) > 0: +- if len(builddir_value) != 1: +- raise ConfigError('Only one value for configuration entry "builddir" can be specified') +- builddir = builddir_value[0] +- if not isinstance(builddir, str): +- raise ConfigError(f'Configuration entry "builddir" should be a string not {type(builddir)}') +- else: +- builddir = None ++ builddir = os.environ.get('MESONPY_BUILD') + + def _validate_string_collection(key: str) -> None: + assert isinstance(config_settings, Mapping)
meta-python/recipes-devtools/python/python3-meson-python/use-installed-mesonpy.patch new file +9 -0
@@ -0,0 +1,9 @@ +--- meson_python-0.13.0.pre0/pyproject.toml.old 2023-03-14 08:55:19.092987968 +0100 ++++ meson_python-0.13.0.pre0/pyproject.toml 2023-03-14 08:55:40.108672980 +0100 +@@ -1,6 +1,5 @@ + [build-system] + build-backend = 'mesonpy' +-backend-path = ['.'] + requires = [ + 'meson>=0.63.3', + 'pyproject-metadata>=0.7.1',
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb new file +28 -0
@@ -0,0 +1,28 @@ +SUMMARY = "Meson Python build backend (PEP 517)" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE;md5=d580b27e67cc0892a5b005b0be114b60" + +DEPENDS = " \ + meson-native ninja-native python3-ninja-native \ + python3-pyproject-metadata-native \ + python3-patchelf-native \ +" + +PYPI_PACKAGE = "meson_python" + +inherit pypi python_mesonpy +SRC_URI[sha256sum] = "8d537a0304709c31c11ffa34872a62a4c06a6a6c24fc862b7fb4306f3e881b95" + +DEPENDS:remove:class-native = "python3-meson-python-native" + +SRC_URI:append:class-native = "file://remove-hardcoded-setup-args.patch" +SRC_URI:append:class-nativesdk = "file://use-installed-mesonpy.patch" +SRC_URI:append:class-target = "file://use-installed-mesonpy.patch" + +RDEPENDS:${PN} = " \ + meson ninja python3-ninja \ + python3-pyproject-metadata \ + python3-patchelf \ +" + +BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.39.2
Re: [oe] [meta-python][PATCH v2 4/4] python3-meson-python: New recipe
Quoted 1 line · Zoltan Boszormenyi via lists.openembedded.org
+++
b/meta-python/recipes-devtools/python/python3-meson-python/remove-hardcoded-setup-args.patch
This patch has no explanation, upstream-status, or signed-off-by.
Quoted 1 line
+++
b/meta-python/recipes-devtools/python/python3-meson-python/use-installed-mesonpy.patch
Ditto.
Quoted 16 lines
meta-python/recipes-devtools/python/python3-meson-python/use-installed-mesonpy.patch new file +9
-0@@ -0,0 +1,9 @@ +--- meson_python-0.13.0.pre0/pyproject.toml.old 2023-03-14 08:55:19.092987968 +0100 ++++ meson_python-0.13.0.pre0/pyproject.toml 2023-03-14 08:55:40.108672980 +0100 +@@ -1,6 +1,5 @@ + [build-system] + build-backend = 'mesonpy' +-backend-path = ['.'] + requires = [ + 'meson>=0.63.3', + 'pyproject-metadata>=0.7.1',meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb new file +0
-0
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb line 6
Quoted 6 lines
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb new file +6
-0@@ -0,0 +1,28 @@ +SUMMARY = "Meson Python build backend (PEP 517)" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE;md5=d580b27e67cc0892a5b005b0be114b60" + +DEPENDS = " \ + meson-native ninja-native python3-ninja-native \
The python_mesonpy class depends on meson and ninja, so those can be removed.
Also the python3-ninja recipe is another waste of time and space, and should be removed.
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb line 18
Quoted 1 line
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb new file +1
-0+SRC_URI:append:class-native = "file://remove-hardcoded-setup-args.patch"
This might break nativesdk where we also write cross files.
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb line 26
Quoted 5 lines
meta-python/recipes-devtools/python/python3-meson-python_0.13.0.pre0.bb new file +5
-0+RDEPENDS:${PN} = " \ + meson ninja python3-ninja \ + python3-pyproject-metadata \ + python3-patchelf \ +"
Does mesonpy actually look for patchelf and ninja modules *at runtime*, or does it just use $PATH? If the latter you can depend on the actual binaries instead of the wrappers.
Ross
Quoted 1 line · Zoltan Boszormenyi via lists.openembedded.org
+inherit setuptools3-base python3targetconfig
python_pep517meson-common
I still don’t see why you need to split the meson class up.
Ross
2023. 03. 20. 15:46 keltezéssel, Ross Burton írta:
Quoted 3 lines · Zoltan Boszormenyi via lists.openembedded.org
Quoted 1 line
+inherit setuptools3-base python3targetconfig
python_pep517meson-commonI still don’t see why you need to split the meson class up.
See the other thread. For some reason, meson always wins regardless of the inheritance order, so do_configure has meson_do_configure instead of pep517_do_configure, etc.
Quoted 2 lines
Ross
Quoted 9 lines · Böszörményi Zoltán
2023. 03. 20. 15:46 keltezéssel, Ross Burton írta:
Quoted 3 lines · Zoltan Boszormenyi via lists.openembedded.org
Quoted 1 line
+inherit setuptools3-base python3targetconfig
python_pep517meson-commonI still don’t see why you need to split the meson class up.
See the other thread. For some reason, meson always wins regardless of the inheritance order, so
do_configurehasmeson_do_configureinstead ofpep517_do_configure, etc.
Add a new do_configure to your class which simply calls the right one.
Ross
2023. 03. 20. 17:26 keltezéssel, Ross Burton írta:
Quoted 9 lines · Böszörményi Zoltán
Quoted 7 lines
2023. 03. 20. 15:46 keltezéssel, Ross Burton írta:
Quoted 3 lines · Zoltan Boszormenyi via lists.openembedded.org
Quoted 1 line
+inherit setuptools3-base python3targetconfig
python_pep517meson-commonI still don’t see why you need to split the meson class up.
See the other thread. For some reason, meson always wins regardless of the inheritance order, so
do_configurehasmeson_do_configureinstead ofpep517_do_configure, etc.Add a new
do_configureto your class which simply calls the right one.
It still doesn't work. meson_do_qa_configure fails with this:
ERROR: python3-meson-python-native-0.13.0.pre0-r0 do_configure: Error executing a python function in exec_func_python() autogenerated:
The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>
0001:
*** 0002:meson_do_qa_configure(d)
0003:
File: '/data2/dtd-yocto-4.2/conf/../layers/openembedded-core/meta/classes-recipe/meson.bbclass', lineno: 163, function: meson_do_qa_configure
0159:
0160:python meson_do_qa_configure() {
0161: import re
0162: warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
*** 0163: with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
0164: log = logfile.read()
0165: for (prop, value) in warn_re.findall(log):
0166: bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
0167:}
Exception: FileNotFoundError: [Errno 2] No such file or directory: '/data2/dtd-yocto-4.2/tmp-sicom-glibc/work/x86_64-linux/python3-meson-python-native/0.13.0.pre0-r0/build/meson-logs/meson-log.txt'
ERROR: Logfile of failure stored in: /data2/dtd-yocto-4.2/tmp-sicom-glibc/work/x86_64-linux/python3-meson-python-native/0.13.0.pre0-r0/temp/log.do_configure.3235105
ERROR: Task (virtual:native:/data2/dtd-yocto-4.2/conf/../layers/meta-sicom/recipes-support/python3/python3-meson-python_0.13.0.pre0.bb:do_configure) failed with exit code '1'
Naturally, as running meson's configure stage went from do_configure to do_compile indirectly via "nativepython3 -m build ..."
Sorry, there seems to be no way around it but splitting out the environment setup from meson.bbclass into meson-common class. If you don't like the "-common" naming, I can rename it to meson-env.bbclass or something like that.
I will still rework python3-meson-python to not require the dummy patchelf python module and review other comments and make necessary changes.
Thanks.
A message that is not in the archive (sent off-list or not yet received): [email protected]
2023. 03. 22. 9:18 keltezéssel, Zoltan Boszormenyi via lists.openembedded.org írta:
Quoted 4 lines
2023. 03. 20. 17:26 keltezéssel, Ross Burton írta:
Quoted 3 lines · Böszörményi Zoltán
Quoted 2 lines
2023. 03. 20. 15:46 keltezéssel, Ross Burton írta:
Quoted 1 line · Zoltan Boszormenyi via lists.openembedded.org
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
+inherit setuptools3-base python3targetconfig
python_pep517meson-commonI still don’t see why you need to split the meson class up.
See the other thread. For some reason, meson always wins regardless of the inheritance order, so
do_configurehasmeson_do_configureinstead ofpep517_do_configure, etc.Add a new
do_configureto your class which simply calls the right one.It still doesn't work.
meson_do_qa_configurefails with this: [...]
This construct also doesn't work
===================================
inherit meson
do_configure[postfuncs]:remove = "meson_do_qa_configure"
===================================
It results in an "unparsed line" error. So, I have to re-iterate this:
Quoted 8 lines
Sorry, there seems to be no way around it but splitting out the environment setup from meson.bbclass into meson-common class. If you don't like the "-common" naming, I can rename it to meson-env.bbclass or something like that.
I will still rework python3-meson-python to not require the dummy patchelf python module and review other comments and make necessary changes.