fix(devices): defer Aravis import-guard from Camera.__init__ to on_connect()
CI for csaxs_bec / test (pull_request) Successful in 1m59s
Read the Docs Deploy Trigger / trigger-rtd-webhook (push) Successful in 3s
CI for csaxs_bec / test (push) Successful in 2m0s

Camera.__init__ raised ImportError unconditionally whenever the Aravis
GObject-Introspection library wasn't importable, even with connect=False --
contradicting the module's own "lazy initialization" docstring and
breaking every unit test in CI, since Aravis is a system library (not
pip-installable) that CI never has installed. The test fixture builds a
real AlliedVisionAravisCamera(connect=False) and only mocks camera.cam
afterward, so the raise fired before mocking ever got a chance to run.

Move the guard into on_connect(), mirroring IDSCamera's working pattern
(its equivalent check lives in the object only built by on_connect(),
never at construction time). Construction is now independent of whether
Aravis is installed; on_connect() still raises the same clear error the
moment something actually tries to talk to hardware.
This commit was merged in pull request #279.
This commit is contained in:
x01dc
2026-07-28 10:46:50 +02:00
parent 2bd161cd63
commit c42595922d
@@ -46,12 +46,6 @@ class Camera:
"""
def __init__(self, camera_id: str, connect: bool = True):
if Aravis is None:
raise ImportError(
"The Aravis library is not installed, or its GObject Introspection typelib"
" is missing. Please check your Python environment (PyGObject) and Aravis"
" installation."
)
self.Aravis = Aravis
self.GLib = GLib
self.camera_id = camera_id
@@ -72,6 +66,12 @@ class Camera:
def on_connect(self):
"""Connect to the camera and initialize it."""
if self.Aravis is None:
raise ImportError(
"The Aravis library is not installed, or its GObject Introspection typelib"
" is missing. Please check your Python environment (PyGObject) and Aravis"
" installation."
)
if self._connected:
logger.warning("Camera is already connected.")
return