Show a patch.

GET /api/1.1/patches/20858/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20858,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20858/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20858/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240809005914.20662-9-laurent.pinchart@ideasonboard.com>",
    "date": "2024-08-09T00:59:12",
    "name": "[08/10] utils: codegen: gen-controls.py: Move helper classes to separate file",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "9f3244c65f12d153498cd7809094daedfe73065a",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20858/mbox/",
    "series": [
        {
            "id": 4506,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4506/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4506",
            "date": "2024-08-09T00:59:04",
            "name": "libcamera: Improve code generation for controls",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4506/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20858/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20858/checks/",
    "tags": {},
    "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 4FDEEBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  9 Aug 2024 00:59:56 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D0F44633BF;\n\tFri,  9 Aug 2024 02:59:55 +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 ABE41633C0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2024 02:59:50 +0200 (CEST)",
            "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B99C583F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2024 02:58:56 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Gmjkn5QP\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1723165137;\n\tbh=QLOZcqushEoVrUTD8zs45EtV+xtVBVXO3eX7CZghrcg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Gmjkn5QPPvIQlOeIteGjdHUn9+bu8urAwd2P08pVDOrbnoGLyJ25culKECKmKGzWe\n\t78iIRso9X6lOOXdTQ9JwhYuDmy6nS4SvwOnmwDS28+IghQOL5DqiRtp6ipha3Q1DcG\n\tJ9Kb4Vm7cQ/UWPf6lSHmHbIJdjpKhnLON3iljjxc=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH 08/10] utils: codegen: gen-controls.py: Move helper classes\n\tto separate file",
        "Date": "Fri,  9 Aug 2024 03:59:12 +0300",
        "Message-ID": "<20240809005914.20662-9-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.44.2",
        "In-Reply-To": "<20240809005914.20662-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20240809005914.20662-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The ControlEnum and Control helper classes defined in gen-controls.py\nare useful for other generator scripts. Move them to a separate file to\nmake it possible to share them.\n\nExtend the Python build environment to add the path to the new Python\nmodule to PYTHONPATH, and use it when invoking the gen-controls.py\nscript.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/meson.build |   1 +\n src/libcamera/meson.build     |   3 +-\n utils/codegen/controls.py     | 112 ++++++++++++++++++++++++++++++++++\n utils/codegen/gen-controls.py | 105 +------------------------------\n 4 files changed, 116 insertions(+), 105 deletions(-)\n create mode 100644 utils/codegen/controls.py",
    "diff": "diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex d90a8615e52d..a969a95dbf7a 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -88,6 +88,7 @@ foreach mode, entry : controls_map\n                                      command : [gen_controls, '-o', '@OUTPUT@',\n                                                 '--mode', mode, '-t', template_file,\n                                                 '-r', ranges_file, '@INPUT@'],\n+                                     env : py_build_env,\n                                      install : true,\n                                      install_dir : libcamera_headers_install_dir)\n endforeach\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 3fd3a87e9f95..aa9ab0291854 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -151,7 +151,8 @@ foreach mode, inout_files : controls_mode_files\n                                      output : output_file,\n                                      command : [gen_controls, '-o', '@OUTPUT@',\n                                                 '--mode', mode, '-t', template_file,\n-                                                '-r', ranges_file, '@INPUT@'])\n+                                                '-r', ranges_file, '@INPUT@'],\n+                                     env : py_build_env)\n endforeach\n \n libcamera_public_sources += control_sources\ndiff --git a/utils/codegen/controls.py b/utils/codegen/controls.py\nnew file mode 100644\nindex 000000000000..7bafee599c80\n--- /dev/null\n+++ b/utils/codegen/controls.py\n@@ -0,0 +1,112 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2019, Google Inc.\n+#\n+# Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n+#\n+# Helper classes to handle source code generation for libcamera controls\n+\n+\n+class ControlEnum(object):\n+    def __init__(self, data):\n+        self.__data = data\n+\n+    @property\n+    def description(self):\n+        \"\"\"The enum description\"\"\"\n+        return self.__data.get('description')\n+\n+    @property\n+    def name(self):\n+        \"\"\"The enum name\"\"\"\n+        return self.__data.get('name')\n+\n+    @property\n+    def value(self):\n+        \"\"\"The enum value\"\"\"\n+        return self.__data.get('value')\n+\n+\n+class Control(object):\n+    def __init__(self, name, data, vendor):\n+        self.__name = name\n+        self.__data = data\n+        self.__enum_values = None\n+        self.__size = None\n+        self.__vendor = vendor\n+\n+        enum_values = data.get('enum')\n+        if enum_values is not None:\n+            self.__enum_values = [ControlEnum(enum) for enum in enum_values]\n+\n+        size = self.__data.get('size')\n+        if size is not None:\n+            if len(size) == 0:\n+                raise RuntimeError(f'Control `{self.__name}` size must have at least one dimension')\n+\n+            # Compute the total number of elements in the array. If any of the\n+            # array dimension is a string, the array is variable-sized.\n+            num_elems = 1\n+            for dim in size:\n+                if type(dim) is str:\n+                    num_elems = 0\n+                    break\n+\n+                dim = int(dim)\n+                if dim <= 0:\n+                    raise RuntimeError(f'Control `{self.__name}` size must have positive values only')\n+\n+                num_elems *= dim\n+\n+            self.__size = num_elems\n+\n+    @property\n+    def description(self):\n+        \"\"\"The control description\"\"\"\n+        return self.__data.get('description')\n+\n+    @property\n+    def enum_values(self):\n+        \"\"\"The enum values, if the control is an enumeration\"\"\"\n+        if self.__enum_values is None:\n+            return\n+        for enum in self.__enum_values:\n+            yield enum\n+\n+    @property\n+    def enum_values_count(self):\n+        \"\"\"The number of enum values, if the control is an enumeration\"\"\"\n+        if self.__enum_values is None:\n+            return 0\n+        return len(self.__enum_values)\n+\n+    @property\n+    def is_enum(self):\n+        \"\"\"Is the control an enumeration\"\"\"\n+        return self.__enum_values is not None\n+\n+    @property\n+    def vendor(self):\n+        \"\"\"The vendor string, or None\"\"\"\n+        return self.__vendor\n+\n+    @property\n+    def name(self):\n+        \"\"\"The control name (CamelCase)\"\"\"\n+        return self.__name\n+\n+    @property\n+    def type(self):\n+        typ = self.__data.get('type')\n+        size = self.__data.get('size')\n+\n+        if typ == 'string':\n+            return 'std::string'\n+\n+        if self.__size is None:\n+            return typ\n+\n+        if self.__size:\n+            return f\"Span<const {typ}, {self.__size}>\"\n+        else:\n+            return f\"Span<const {typ}>\"\ndiff --git a/utils/codegen/gen-controls.py b/utils/codegen/gen-controls.py\nindex 685ef7a00d5f..2968eb9a5d4e 100755\n--- a/utils/codegen/gen-controls.py\n+++ b/utils/codegen/gen-controls.py\n@@ -12,110 +12,7 @@ import os\n import sys\n import yaml\n \n-\n-class ControlEnum(object):\n-    def __init__(self, data):\n-        self.__data = data\n-\n-    @property\n-    def description(self):\n-        \"\"\"The enum description\"\"\"\n-        return self.__data.get('description')\n-\n-    @property\n-    def name(self):\n-        \"\"\"The enum name\"\"\"\n-        return self.__data.get('name')\n-\n-    @property\n-    def value(self):\n-        \"\"\"The enum value\"\"\"\n-        return self.__data.get('value')\n-\n-\n-class Control(object):\n-    def __init__(self, name, data, vendor):\n-        self.__name = name\n-        self.__data = data\n-        self.__enum_values = None\n-        self.__size = None\n-        self.__vendor = vendor\n-\n-        enum_values = data.get('enum')\n-        if enum_values is not None:\n-            self.__enum_values = [ControlEnum(enum) for enum in enum_values]\n-\n-        size = self.__data.get('size')\n-        if size is not None:\n-            if len(size) == 0:\n-                raise RuntimeError(f'Control `{self.__name}` size must have at least one dimension')\n-\n-            # Compute the total number of elements in the array. If any of the\n-            # array dimension is a string, the array is variable-sized.\n-            num_elems = 1\n-            for dim in size:\n-                if type(dim) is str:\n-                    num_elems = 0\n-                    break\n-\n-                dim = int(dim)\n-                if dim <= 0:\n-                    raise RuntimeError(f'Control `{self.__name}` size must have positive values only')\n-\n-                num_elems *= dim\n-\n-            self.__size = num_elems\n-\n-    @property\n-    def description(self):\n-        \"\"\"The control description\"\"\"\n-        return self.__data.get('description')\n-\n-    @property\n-    def enum_values(self):\n-        \"\"\"The enum values, if the control is an enumeration\"\"\"\n-        if self.__enum_values is None:\n-            return\n-        for enum in self.__enum_values:\n-            yield enum\n-\n-    @property\n-    def enum_values_count(self):\n-        \"\"\"The number of enum values, if the control is an enumeration\"\"\"\n-        if self.__enum_values is None:\n-            return 0\n-        return len(self.__enum_values)\n-\n-    @property\n-    def is_enum(self):\n-        \"\"\"Is the control an enumeration\"\"\"\n-        return self.__enum_values is not None\n-\n-    @property\n-    def vendor(self):\n-        \"\"\"The vendor string, or None\"\"\"\n-        return self.__vendor\n-\n-    @property\n-    def name(self):\n-        \"\"\"The control name (CamelCase)\"\"\"\n-        return self.__name\n-\n-    @property\n-    def type(self):\n-        typ = self.__data.get('type')\n-        size = self.__data.get('size')\n-\n-        if typ == 'string':\n-            return 'std::string'\n-\n-        if self.__size is None:\n-            return typ\n-\n-        if self.__size:\n-            return f\"Span<const {typ}, {self.__size}>\"\n-        else:\n-            return f\"Span<const {typ}>\"\n+from controls import Control\n \n \n def snake_case(s):\n",
    "prefixes": [
        "08/10"
    ]
}