Message ID | 20220517143325.71784-3-tomi.valkeinen@ideasonboard.com |
---|---|
State | Rejected |
Headers | show |
Series |
|
Related | show |
Hi Tomi, Thank you for the patch. On Tue, May 17, 2022 at 05:33:14PM +0300, Tomi Valkeinen wrote: > Add a 'pystubs' build target for building the python stubs. > > For now this needs to be ran manually. I didn't figure out how to > generate the stubs after the libcamera bindings are built. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/py/libcamera/meson.build | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build > index 38f619d0..32e74504 100644 > --- a/src/py/libcamera/meson.build > +++ b/src/py/libcamera/meson.build > @@ -60,6 +60,18 @@ run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py', > > install_data(['__init__.py'], install_dir : destdir) > > -# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files > +# \todo Generate stubs when building, and install them. > +# See https://peps.python.org/pep-0484/#stub-files > # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: > # $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera > +# The target below can be ran manually, but how to create a meson target that > +# is run if pycamera is built? > + > +stubgen = find_program('pybind11-stubgen', required : false) > + > +if stubgen.found() > + run_target('pystubs', > + depends: pycamera, > + env: {'PYTHONPATH': meson.project_build_root() / 'src' / 'py'}, > + command: [stubgen, '--no-setup-py', '-o', meson.project_build_root() / 'src' / 'py', 'libcamera']) > +endif
Quoting Tomi Valkeinen (2022-05-17 15:33:14) > Add a 'pystubs' build target for building the python stubs. > > For now this needs to be ran manually. I didn't figure out how to > generate the stubs after the libcamera bindings are built. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Hrm ... It sounds like this wants to be some sort of post-build step. Searching quickly seems to find only things like: https://github.com/mesonbuild/meson/issues/2957 Which seems to suggest a custom target (which is the full target, to build pycamera, and the stubs?) and have it depend on the pycamera shared_module(). But I'm not sure if that's a full understanding of what you're trying to achieve here. Anyway, having a target is better than expecting a user to execute a manual command successfully - (but I fear at the moment, this won't get used directly?) Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- > src/py/libcamera/meson.build | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build > index 38f619d0..32e74504 100644 > --- a/src/py/libcamera/meson.build > +++ b/src/py/libcamera/meson.build > @@ -60,6 +60,18 @@ run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py', > > install_data(['__init__.py'], install_dir : destdir) > > -# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files > +# \todo Generate stubs when building, and install them. > +# See https://peps.python.org/pep-0484/#stub-files > # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: > # $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera > +# The target below can be ran manually, but how to create a meson target that > +# is run if pycamera is built? > + > +stubgen = find_program('pybind11-stubgen', required : false) > + > +if stubgen.found() > + run_target('pystubs', > + depends: pycamera, > + env: {'PYTHONPATH': meson.project_build_root() / 'src' / 'py'}, > + command: [stubgen, '--no-setup-py', '-o', meson.project_build_root() / 'src' / 'py', 'libcamera']) > +endif > -- > 2.34.1 >
On Tue, May 17, 2022 at 07:07:27PM +0300, Laurent Pinchart via libcamera-devel wrote: > On Tue, May 17, 2022 at 05:33:14PM +0300, Tomi Valkeinen wrote: > > Add a 'pystubs' build target for building the python stubs. > > > > For now this needs to be ran manually. I didn't figure out how to > > generate the stubs after the libcamera bindings are built. > > > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > --- > > src/py/libcamera/meson.build | 14 +++++++++++++- > > 1 file changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build > > index 38f619d0..32e74504 100644 > > --- a/src/py/libcamera/meson.build > > +++ b/src/py/libcamera/meson.build > > @@ -60,6 +60,18 @@ run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py', > > > > install_data(['__init__.py'], install_dir : destdir) > > > > -# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files > > +# \todo Generate stubs when building, and install them. > > +# See https://peps.python.org/pep-0484/#stub-files > > # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: > > # $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera > > +# The target below can be ran manually, but how to create a meson target that > > +# is run if pycamera is built? > > + > > +stubgen = find_program('pybind11-stubgen', required : false) > > + > > +if stubgen.found() > > + run_target('pystubs', > > + depends: pycamera, > > + env: {'PYTHONPATH': meson.project_build_root() / 'src' / 'py'}, This requires meson 0.57. > > + command: [stubgen, '--no-setup-py', '-o', meson.project_build_root() / 'src' / 'py', 'libcamera']) > > +endif
On 17/05/2022 19:21, Kieran Bingham wrote: > Quoting Tomi Valkeinen (2022-05-17 15:33:14) >> Add a 'pystubs' build target for building the python stubs. >> >> For now this needs to be ran manually. I didn't figure out how to >> generate the stubs after the libcamera bindings are built. >> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > Hrm ... It sounds like this wants to be some sort of post-build step. > > Searching quickly seems to find only things like: > https://github.com/mesonbuild/meson/issues/2957 > > Which seems to suggest a custom target (which is the full target, to > build pycamera, and the stubs?) and have it depend on the pycamera > shared_module(). > > But I'm not sure if that's a full understanding of what you're trying to > achieve here. > > Anyway, having a target is better than expecting a user to execute a > manual command successfully - (but I fear at the moment, this won't get > used directly?) I think custom_target doesn't work, as this can only be built when doing a native build. You have to be able to use the produced bindings module to be able to run stubgen. I expect that the stubs would eventually be something that are committed to the repository, and updated when needed. As we also have the meson 0.57 requirement... Maybe I'll just leave this out for now. Tomi
Hi Tomi, On Wed, May 18, 2022 at 09:43:45AM +0300, Tomi Valkeinen wrote: > On 17/05/2022 19:21, Kieran Bingham wrote: > > Quoting Tomi Valkeinen (2022-05-17 15:33:14) > >> Add a 'pystubs' build target for building the python stubs. > >> > >> For now this needs to be ran manually. I didn't figure out how to > >> generate the stubs after the libcamera bindings are built. > >> > >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > > > Hrm ... It sounds like this wants to be some sort of post-build step. > > > > Searching quickly seems to find only things like: > > https://github.com/mesonbuild/meson/issues/2957 > > > > Which seems to suggest a custom target (which is the full target, to > > build pycamera, and the stubs?) and have it depend on the pycamera > > shared_module(). > > > > But I'm not sure if that's a full understanding of what you're trying to > > achieve here. > > > > Anyway, having a target is better than expecting a user to execute a > > manual command successfully - (but I fear at the moment, this won't get > > used directly?) > > I think custom_target doesn't work, as this can only be built when doing > a native build. You have to be able to use the produced bindings module > to be able to run stubgen. We could possibly disable it for cross-builds, using meson.is_cross_build() or meson.can_run_host_binaries() (see https://mesonbuild.com/Cross-compilation.html#introspection-and-system-checks). > I expect that the stubs would eventually be something that are committed > to the repository, and updated when needed. > > As we also have the meson 0.57 requirement... Maybe I'll just leave this > out for now. That's fine with me.
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 38f619d0..32e74504 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -60,6 +60,18 @@ run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py', install_data(['__init__.py'], install_dir : destdir) -# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files +# \todo Generate stubs when building, and install them. +# See https://peps.python.org/pep-0484/#stub-files # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: # $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera +# The target below can be ran manually, but how to create a meson target that +# is run if pycamera is built? + +stubgen = find_program('pybind11-stubgen', required : false) + +if stubgen.found() + run_target('pystubs', + depends: pycamera, + env: {'PYTHONPATH': meson.project_build_root() / 'src' / 'py'}, + command: [stubgen, '--no-setup-py', '-o', meson.project_build_root() / 'src' / 'py', 'libcamera']) +endif
Add a 'pystubs' build target for building the python stubs. For now this needs to be ran manually. I didn't figure out how to generate the stubs after the libcamera bindings are built. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> --- src/py/libcamera/meson.build | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)