[libcamera-devel,v2,1/5] py: Fix CameraManager.version property
diff mbox series

Message ID 20230530120133.99033-2-tomi.valkeinen@ideasonboard.com
State Accepted
Headers show
Series
  • py: Misc changes & move to mainline pybind11
Related show

Commit Message

Tomi Valkeinen May 30, 2023, 12:01 p.m. UTC
The current CameraManager.version doesn't work at all (raises a
TypeError), as that's not how you use expose C++ static methods as
Python class methods.

Fix it.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/py/libcamera/py_main.cpp | 2 +-
 test/py/unittests.py         | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
index d14e18e2..c55495cc 100644
--- a/src/py/libcamera/py_main.cpp
+++ b/src/py/libcamera/py_main.cpp
@@ -105,7 +105,7 @@  PYBIND11_MODULE(_libcamera, m)
 			return cm;
 		})
 
-		.def_property_readonly("version", &PyCameraManager::version)
+		.def_property_readonly_static("version", [](py::object /* self */) { return PyCameraManager::version(); })
 		.def("get", &PyCameraManager::get, py::keep_alive<0, 1>())
 		.def_property_readonly("cameras", &PyCameraManager::cameras)
 
diff --git a/test/py/unittests.py b/test/py/unittests.py
index 6dea80fc..90b04330 100755
--- a/test/py/unittests.py
+++ b/test/py/unittests.py
@@ -68,6 +68,10 @@  class SimpleTestMethods(BaseTestCase):
         # I expected EBUSY, but looks like double release works fine
         self.assertZero(ret)
 
+    def test_version(self):
+        cm = libcam.CameraManager.singleton()
+        self.assertIsInstance(cm.version, str)
+
 
 class CameraTesterBase(BaseTestCase):
     cm: typing.Any