{"id":18698,"url":"https://patchwork.libcamera.org/api/1.1/patches/18698/?format=json","web_url":"https://patchwork.libcamera.org/patch/18698/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230603075615.20663-14-tomi.valkeinen@ideasonboard.com>","date":"2023-06-03T07:56:15","name":"[libcamera-devel,v5,13/13] py: Improve stub type generation for PyCameraEvent","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b42e87234410e978d962e7b23f66d5d799eabb7e","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/1.1/people/109/?format=json","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18698/mbox/","series":[{"id":3904,"url":"https://patchwork.libcamera.org/api/1.1/series/3904/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3904","date":"2023-06-03T07:56:02","name":"py: New python bindings event handling","version":5,"mbox":"https://patchwork.libcamera.org/series/3904/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18698/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18698/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 3D106C32AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 Jun 2023 07:57:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0EC24628A1;\n\tSat,  3 Jun 2023 09:57:23 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B9AFA6287E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 Jun 2023 09:57:16 +0200 (CEST)","from desky.lan (91-154-35-171.elisa-laajakaista.fi [91.154.35.171])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 49F6A1AFA;\n\tSat,  3 Jun 2023 09:56:53 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1685779043;\n\tbh=w/FC3Gju+vqRcQk+qqVpMJf2jHZlmQ8sepFEn0xU0IQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=XJGUpUUQtOomymBKio0j4qUuLMox8iowadxeeUXmz1VjBxDXcMTc3wzY9KOsU7bIQ\n\tO8SpEtWnSMt3UK+RydAKXEeV7BI8nNIMZm7HT/Hsw0jxHiUXdnSOYaZm81JIUyKaNY\n\tRZ6lTnSyoHBErdzgPl9SpMhgxdds2jaQU8v5wNPSriaMfwtxFR0W7nH9Y+WiGMAZl/\n\tSjR2twJIiAPWvF+NATzZ0QQxkAAhqZe2vPm256DaXHXfYwd5ISAOUJPFTi/i3zl/tv\n\tMekw1JostEwqXPvLbNLxQf5mgHdK3ranxEu5xadZ8aj9F14dLbrl+9aJL66xaB2xdS\n\tEa7d18/8eX8wg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1685779013;\n\tbh=w/FC3Gju+vqRcQk+qqVpMJf2jHZlmQ8sepFEn0xU0IQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZhPAlRli4e2/PSUoJjGnY935TyJ7umAo6gFJv0wEJCAvgGLLsqNDOgwEKqQ7pqpON\n\twPiSV4JUDAQBW6aKozMcF7JvfIsA9qLGSeB1EqC86kBHOlgPoGYtxuST04m2ZeX3wj\n\tkF8jdksnU+yDylsa4QJg3yYILq/PkuefKmEzVjdk="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ZhPAlRli\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sat,  3 Jun 2023 10:56:15 +0300","Message-Id":"<20230603075615.20663-14-tomi.valkeinen@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230603075615.20663-1-tomi.valkeinen@ideasonboard.com>","References":"<20230603075615.20663-1-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 13/13] py: Improve stub type generation\n\tfor PyCameraEvent","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>"},"content":"We store the camera, request and fb fields in PyCameraEvent as\npy::objects, so that we keep the refs and keep-alives. When we\nreturn py::objects to the Python side, they, obviously, show up\nas \"objects\" when the stub generation is looking at the fields.\n\nFix this by manually casting the py::objects to the correct C++\ncounterparts, which causes pybind11 to assign the correct types for the\nproperties, helping stubgen to generate correct types.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/py/libcamera/py_main.cpp | 14 +++++++++++---\n 1 file changed, 11 insertions(+), 3 deletions(-)","diff":"diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp\nindex bc40849a..85303d71 100644\n--- a/src/py/libcamera/py_main.cpp\n+++ b/src/py/libcamera/py_main.cpp\n@@ -145,11 +145,19 @@ PYBIND11_MODULE(_libcamera, m)\n \t\t.value(\"RequestCompleted\", CameraEventType::RequestCompleted)\n \t\t.value(\"BufferCompleted\", CameraEventType::BufferCompleted);\n \n+\t/*\n+\t * For camera, request and fb fields, manually typecast to the C++ type,\n+\t * so that pybind11 assigns the actual type for the return value. This\n+\t * makes the stubs generated by pybind11-stubgen contain the correct type,\n+\t * instead of \"object\".\n+\t *\n+\t * Maybe there's a better way to do this...\n+\t */\n \tpyEvent\n \t\t.def_readonly(\"type\", &PyCameraEvent::type_)\n-\t\t.def_readonly(\"camera\", &PyCameraEvent::camera_)\n-\t\t.def_readonly(\"request\", &PyCameraEvent::request_)\n-\t\t.def_readonly(\"fb\", &PyCameraEvent::fb_);\n+\t\t.def_property_readonly(\"camera\", [](PyCameraEvent &self) { return self.camera_.cast<Camera *>(); })\n+\t\t.def_property_readonly(\"request\", [](PyCameraEvent &self) { return self.request_.cast<Request *>(); })\n+\t\t.def_property_readonly(\"fb\", [](PyCameraEvent &self) { return self.fb_.cast<FrameBuffer *>(); });\n \n \tpyCameraManager\n \t\t.def_static(\"singleton\", []() {\n","prefixes":["libcamera-devel","v5","13/13"]}