[{"id":23181,"web_url":"https://patchwork.libcamera.org/comment/23181/","msgid":"<f4b46ade-e041-b009-cf5b-5e71fbbbd01f@ideasonboard.com>","date":"2022-05-27T06:56:07","subject":"Re: [libcamera-devel] [PATCH v2 18/19] py: Generate bindings for\n\tproperties","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"On 24/05/2022 14:46, Tomi Valkeinen wrote:\n> Generate bindings for properties in a very similar way as done for\n> controls. We do need to distinguish between the two, and thus I added\n> --properties flag to gen-py-controls.py.\n> \n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> ---\n>   src/py/libcamera/gen-py-controls.py           | 27 +++++++++++------\n>   src/py/libcamera/meson.build                  | 12 ++++++++\n>   .../libcamera/py_properties_generated.cpp.in  | 30 +++++++++++++++++++\n>   3 files changed, 60 insertions(+), 9 deletions(-)\n>   create mode 100644 src/py/libcamera/py_properties_generated.cpp.in\n> \n> diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py\n> index e3e1e178..a9264777 100755\n> --- a/src/py/libcamera/gen-py-controls.py\n> +++ b/src/py/libcamera/gen-py-controls.py\n> @@ -21,17 +21,19 @@ def find_common_prefix(strings):\n>       return prefix\n>   \n>   \n> -def generate_py(controls):\n> +def generate_py(controls, prop_mode):\n>       out = ''\n>   \n> +    mode_name = \"properties\" if prop_mode else \"controls\"\n> +\n>       for ctrl in controls:\n>           name, ctrl = ctrl.popitem()\n>   \n>           if ctrl.get('draft'):\n> -            ns = 'libcamera::controls::draft::'\n> +            ns = 'libcamera::{}::draft::'.format(mode_name)\n>               container = \"draft\"\n>           else:\n> -            ns = 'libcamera::controls::'\n> +            ns = 'libcamera::{}::'.format(mode_name)\n>               container = \"controls\"\n>   \n>           cpp_enum = name + 'Enum'\n> @@ -44,12 +46,17 @@ def generate_py(controls):\n>   \n>           out += '\\tpy::enum_<{}{}>({}, \\\"{}\\\")\\n'.format(ns, cpp_enum, container, cpp_enum)\n>   \n> -        if name == 'LensShadingMapMode':\n> -            prefix = 'LensShadingMapMode'\n> -        elif name == 'SceneFlicker':\n> -            # If we strip the prefix, we would get '50Hz', which is illegal name\n> -            prefix = ''\n> +        if not prop_mode:\n> +            # Adjustments for controls\n> +            if name == 'LensShadingMapMode':\n> +                prefix = 'LensShadingMapMode'\n> +            elif name == 'SceneFlicker':\n> +                # If we strip the prefix, we would get '50Hz', which is illegal name\n> +                prefix = ''\n> +            else:\n> +                prefix = find_common_prefix([e['name'] for e in enum])\n>           else:\n> +            # Adjustments for properties\n>               prefix = find_common_prefix([e['name'] for e in enum])\n>   \n>           for entry in enum:\n> @@ -79,12 +86,14 @@ def main(argv):\n>                           help='Input file name.')\n>       parser.add_argument('template', type=str,\n>                           help='Template file name.')\n> +    parser.add_argument('--properties', action='store_true', default=False,\n> +                        help='Generate bindings for properties instead of controls')\n>       args = parser.parse_args(argv[1:])\n>   \n>       data = open(args.input, 'rb').read()\n>       controls = yaml.safe_load(data)['controls']\n>   \n> -    data = generate_py(controls)\n> +    data = generate_py(controls, prop_mode=args.properties)\n>   \n>       data = fill_template(args.template, data)\n>   \n> diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\n> index e8010846..e0010353 100644\n> --- a/src/py/libcamera/meson.build\n> +++ b/src/py/libcamera/meson.build\n> @@ -32,6 +32,18 @@ pycamera_sources += custom_target('py_gen_controls',\n>                                     output : ['py_controls_generated.cpp'],\n>                                     command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@'])\n>   \n> +# Generate properties\n> +\n> +gen_py_property_enums_input_files = files([\n> +    '../../libcamera/property_ids.yaml',\n> +    'py_properties_generated.cpp.in',\n> +])\n> +\n> +pycamera_sources += custom_target('py_gen_properties',\n> +                                  input : gen_py_property_enums_input_files,\n> +                                  output : ['py_properties_generated.cpp'],\n> +                                  command : [gen_py_controls, '--properties', '-o', '@OUTPUT@', '@INPUT@'])\n> +\n>   # Generate formats\n>   \n>   gen_py_formats_input_files = files([\n> diff --git a/src/py/libcamera/py_properties_generated.cpp.in b/src/py/libcamera/py_properties_generated.cpp.in\n> new file mode 100644\n> index 00000000..044b2b2a\n> --- /dev/null\n> +++ b/src/py/libcamera/py_properties_generated.cpp.in\n> @@ -0,0 +1,30 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> + *\n> + * Python bindings - Auto-generated properties\n> + *\n> + * This file is auto-generated. Do not edit.\n> + */\n> +\n> +#include <libcamera/property_ids.h>\n> +\n> +#include <pybind11/smart_holder.h>\n> +\n> +namespace py = pybind11;\n> +\n> +class PyProperties\n> +{\n> +};\n> +\n> +class PyDraftProperties\n> +{\n> +};\n> +\n> +void init_py_properties_generated(py::module& m)\n> +{\n> +\tauto controls = py::class_<PyProperties>(m, \"properties\");\n> +\tauto draft = py::class_<PyDraftProperties>(controls, \"draft\");\n> +\n> +${controls}\n> +}\n\nWell. This was well tested. I never actually call \ninit_py_properties_generated()...\n\n  Tomi","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D4425BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 May 2022 06:56:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EEBF7633A1;\n\tFri, 27 May 2022 08:56:11 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9007F61FB6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 May 2022 08:56:10 +0200 (CEST)","from [192.168.1.111] (91-156-85-209.elisa-laajakaista.fi\n\t[91.156.85.209])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B077E31A;\n\tFri, 27 May 2022 08:56:09 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653634572;\n\tbh=mgtC8KGrI6dPWn2KbRGRGvkRhB/enAcVbK7ChhttSXA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=z0xpCBpJ2FFSWba+cGjCc0Zuh9/uwUH9kNbOf2KM97Ug9279pCtWQ87L5Aa2aa812\n\tmkmhvk4v2eO4B/s/+4Xq+2sLCCr+I7HbxGEXkgqz4z4f/GYJPnLF6yBzICUIGNUbXw\n\tK1CKouJfyb8ghN0Ri1FwO9lOXJso0/Z3l9S1ErjLJXcYc09k6qyYef+c1QCSSXz95s\n\tK4wCzYFORoNFj4tmlZo4wi0LNqvM7XgbMgwaP80JYeUN7VFzCoCaABaigJLSvXgbMD\n\tfn01rD/ZJCRmQi37iHUiJZn3JwbPFZK/tjta41Tlc2EeLMoliadVEy78yr3/p84D6M\n\tw9+1sKJVEtVzA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653634570;\n\tbh=mgtC8KGrI6dPWn2KbRGRGvkRhB/enAcVbK7ChhttSXA=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=eWNMyGCPt6EywzlvCeRfRo918kfMI+FLYjTRI6709DpwVURxQ2CduAfsjx0YLa+au\n\t8pimazRFjbLUs1gnHoAUvIl7KTKUB/daPt4lutHHC3HeuQVGNEfOeVo7E8+XZKQPgz\n\tUTubnqZwFnHODv9Hqdp13lgXusyRYBVVmkOnvvLg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"eWNMyGCP\"; dkim-atps=neutral","Message-ID":"<f4b46ade-e041-b009-cf5b-5e71fbbbd01f@ideasonboard.com>","Date":"Fri, 27 May 2022 09:56:07 +0300","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.9.1","Content-Language":"en-US","To":"libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>","References":"<20220524114610.41848-1-tomi.valkeinen@ideasonboard.com>\n\t<20220524114610.41848-19-tomi.valkeinen@ideasonboard.com>","In-Reply-To":"<20220524114610.41848-19-tomi.valkeinen@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2 18/19] py: Generate bindings for\n\tproperties","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":23194,"web_url":"https://patchwork.libcamera.org/comment/23194/","msgid":"<YpCwDOivDFLKyN4f@pendragon.ideasonboard.com>","date":"2022-05-27T11:03:40","subject":"Re: [libcamera-devel] [PATCH v2 18/19] py: Generate bindings for\n\tproperties","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Tue, May 24, 2022 at 02:46:09PM +0300, Tomi Valkeinen wrote:\n> Generate bindings for properties in a very similar way as done for\n> controls. We do need to distinguish between the two, and thus I added\n> --properties flag to gen-py-controls.py.\n> \n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> ---\n>  src/py/libcamera/gen-py-controls.py           | 27 +++++++++++------\n>  src/py/libcamera/meson.build                  | 12 ++++++++\n>  .../libcamera/py_properties_generated.cpp.in  | 30 +++++++++++++++++++\n>  3 files changed, 60 insertions(+), 9 deletions(-)\n>  create mode 100644 src/py/libcamera/py_properties_generated.cpp.in\n> \n> diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py\n> index e3e1e178..a9264777 100755\n> --- a/src/py/libcamera/gen-py-controls.py\n> +++ b/src/py/libcamera/gen-py-controls.py\n> @@ -21,17 +21,19 @@ def find_common_prefix(strings):\n>      return prefix\n>  \n>  \n> -def generate_py(controls):\n> +def generate_py(controls, prop_mode):\n>      out = ''\n>  \n> +    mode_name = \"properties\" if prop_mode else \"controls\"\n\ns/\"/'/g where applicable.\n\n> +\n>      for ctrl in controls:\n>          name, ctrl = ctrl.popitem()\n>  \n>          if ctrl.get('draft'):\n> -            ns = 'libcamera::controls::draft::'\n> +            ns = 'libcamera::{}::draft::'.format(mode_name)\n>              container = \"draft\"\n>          else:\n> -            ns = 'libcamera::controls::'\n> +            ns = 'libcamera::{}::'.format(mode_name)\n>              container = \"controls\"\n>  \n>          cpp_enum = name + 'Enum'\n> @@ -44,12 +46,17 @@ def generate_py(controls):\n>  \n>          out += '\\tpy::enum_<{}{}>({}, \\\"{}\\\")\\n'.format(ns, cpp_enum, container, cpp_enum)\n>  \n> -        if name == 'LensShadingMapMode':\n> -            prefix = 'LensShadingMapMode'\n> -        elif name == 'SceneFlicker':\n> -            # If we strip the prefix, we would get '50Hz', which is illegal name\n> -            prefix = ''\n> +        if not prop_mode:\n> +            # Adjustments for controls\n> +            if name == 'LensShadingMapMode':\n> +                prefix = 'LensShadingMapMode'\n> +            elif name == 'SceneFlicker':\n> +                # If we strip the prefix, we would get '50Hz', which is illegal name\n> +                prefix = ''\n> +            else:\n> +                prefix = find_common_prefix([e['name'] for e in enum])\n>          else:\n> +            # Adjustments for properties\n>              prefix = find_common_prefix([e['name'] for e in enum])\n>  \n>          for entry in enum:\n> @@ -79,12 +86,14 @@ def main(argv):\n>                          help='Input file name.')\n>      parser.add_argument('template', type=str,\n>                          help='Template file name.')\n> +    parser.add_argument('--properties', action='store_true', default=False,\n> +                        help='Generate bindings for properties instead of controls')\n\nI'm tempted to instead add a --mode argument that wouldtake either\n'controls' or 'properties' as a value, and pass the mode name to\ngenerate_py(). I don't mind too much, so either way,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>      args = parser.parse_args(argv[1:])\n>  \n>      data = open(args.input, 'rb').read()\n>      controls = yaml.safe_load(data)['controls']\n>  \n> -    data = generate_py(controls)\n> +    data = generate_py(controls, prop_mode=args.properties)\n>  \n>      data = fill_template(args.template, data)\n>  \n> diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\n> index e8010846..e0010353 100644\n> --- a/src/py/libcamera/meson.build\n> +++ b/src/py/libcamera/meson.build\n> @@ -32,6 +32,18 @@ pycamera_sources += custom_target('py_gen_controls',\n>                                    output : ['py_controls_generated.cpp'],\n>                                    command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@'])\n>  \n> +# Generate properties\n> +\n> +gen_py_property_enums_input_files = files([\n> +    '../../libcamera/property_ids.yaml',\n> +    'py_properties_generated.cpp.in',\n> +])\n> +\n> +pycamera_sources += custom_target('py_gen_properties',\n> +                                  input : gen_py_property_enums_input_files,\n> +                                  output : ['py_properties_generated.cpp'],\n> +                                  command : [gen_py_controls, '--properties', '-o', '@OUTPUT@', '@INPUT@'])\n> +\n>  # Generate formats\n>  \n>  gen_py_formats_input_files = files([\n> diff --git a/src/py/libcamera/py_properties_generated.cpp.in b/src/py/libcamera/py_properties_generated.cpp.in\n> new file mode 100644\n> index 00000000..044b2b2a\n> --- /dev/null\n> +++ b/src/py/libcamera/py_properties_generated.cpp.in\n> @@ -0,0 +1,30 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> + *\n> + * Python bindings - Auto-generated properties\n> + *\n> + * This file is auto-generated. Do not edit.\n> + */\n> +\n> +#include <libcamera/property_ids.h>\n> +\n> +#include <pybind11/smart_holder.h>\n> +\n> +namespace py = pybind11;\n> +\n> +class PyProperties\n> +{\n> +};\n> +\n> +class PyDraftProperties\n> +{\n> +};\n> +\n> +void init_py_properties_generated(py::module& m)\n> +{\n> +\tauto controls = py::class_<PyProperties>(m, \"properties\");\n> +\tauto draft = py::class_<PyDraftProperties>(controls, \"draft\");\n> +\n> +${controls}\n> +}","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 521F9BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 May 2022 11:03:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD5AD633A2;\n\tFri, 27 May 2022 13:03:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 85C1A633A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 May 2022 13:03:48 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [46.183.103.8])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8FF7631A;\n\tFri, 27 May 2022 13:03:47 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653649430;\n\tbh=8jo8keFJS4z1cG4ktp63q4VfJZ4lXCZhDplo9uKi9ig=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=C0HsqO2VSN7ecVO4a0CZgbA8UFW7+PQXzcUmuYvW60kv0JxcnkvN6U2bgkiFEPNop\n\trOKeFsClYsgLJy08jiW8ZYEaXDTC7cU5q71MlIAzqkrW4K3tsXNrcheFQiNm1uvzvg\n\tfQqD+35Yx2bz5WbKTOWUkFLhzLzG1o5fmVYRRL8AWopBw1hM4e1fwZdWgMlZT6OwIg\n\td9PMskhg694MelKJCYvz1pO2zNYfqtaG+dCZ/V26z/muNjm41JhO1AsrJFMI4WeH32\n\tHRq/6CH2fF4uZhSrLmKeti9w4Iu1KDM2FWuwLLflA3nlWICFF2bQHmy4YTc+lj0Dwb\n\tZRCCkHd6aaLDQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653649428;\n\tbh=8jo8keFJS4z1cG4ktp63q4VfJZ4lXCZhDplo9uKi9ig=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fWPELtiuMqJ/0qCI8R4/WHQjDam0ed/mPbLNufGHa+LtdEBCmAWperfNiqb+4FxA/\n\tJgnVfbKBA/+nymCtoyxwGS3XR5YQ1qlHTwEU7/xceKx6cUQdPk+/RvSbAHG4yPFKNX\n\tdr8zhyJhZUpZhivzBkEUsO11CMR8ak8Mk/FkvJuc="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"fWPELtiu\"; dkim-atps=neutral","Date":"Fri, 27 May 2022 14:03:40 +0300","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<YpCwDOivDFLKyN4f@pendragon.ideasonboard.com>","References":"<20220524114610.41848-1-tomi.valkeinen@ideasonboard.com>\n\t<20220524114610.41848-19-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220524114610.41848-19-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 18/19] py: Generate bindings for\n\tproperties","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]