From c0b365566a38ea26be78218c46928cf6651ca525 Mon Sep 17 00:00:00 2001 From: John Ingve Olsen Date: Wed, 20 Nov 2024 15:26:56 +0100 Subject: [PATCH] Nest Settings2D within Settings.color This commit moves the generated Settings2D datamodel frontend from `settings_2d.py` to `settings2d.py`, as that is the snake case name that our datamodel frontend generator produces, and we need to import this file into the generated Settings datamodel frontend. --- .flake8 | 2 +- .../datamodel_frontend_generator.py | 8 +++-- modules/zivid/__init__.py | 2 +- modules/zivid/camera.py | 2 +- modules/zivid/experimental/calibration.py | 2 +- modules/zivid/frame_2d.py | 2 +- modules/zivid/projection.py | 2 +- modules/zivid/settings.py | 29 ++++++++++++------- .../zivid/{settings_2d.py => settings2d.py} | 0 test/calibration/test_intrinsics.py | 2 +- test/converters/test_convert_settings_2d.py | 4 +-- test/test_settings.py | 29 +++++++++++++++++++ 12 files changed, 63 insertions(+), 21 deletions(-) rename modules/zivid/{settings_2d.py => settings2d.py} (100%) diff --git a/.flake8 b/.flake8 index 1868a18d..8e236723 100644 --- a/.flake8 +++ b/.flake8 @@ -25,7 +25,7 @@ show-source = True ### D107: Missing docstring in __init__ per-file-ignores = settings.py:D101,D102,D106,D107 - settings_2d.py:D101,D102,D106,D107 + settings2d.py:D101,D102,D106,D107 camera_state.py:D101,D102,D106,D107 camera_info.py:D101,D102,D106,D107 camera_intrinsics.py:D101,D102,D106,D107 diff --git a/continuous-integration/code-generation/datamodel_frontend_generator.py b/continuous-integration/code-generation/datamodel_frontend_generator.py index 0a887634..2ea7c37c 100644 --- a/continuous-integration/code-generation/datamodel_frontend_generator.py +++ b/continuous-integration/code-generation/datamodel_frontend_generator.py @@ -823,8 +823,12 @@ def _generate_datamodel_frontend( def generate_all_datamodels(dest_dir: Path) -> None: for internal_class, filename, extra_imports in [ - (_zivid.Settings, "settings.py", ["datetime", "collections.abc"]), - (_zivid.Settings2D, "settings_2d.py", ["datetime", "collections.abc"]), + (_zivid.Settings2D, "settings2d.py", ["datetime", "collections.abc"]), + ( + _zivid.Settings, + "settings.py", + ["datetime", "collections.abc", "zivid.settings2d"], + ), (_zivid.CameraInfo, "camera_info.py", []), (_zivid.CameraState, "camera_state.py", ["collections.abc"]), (_zivid.FrameInfo, "frame_info.py", ["datetime"]), diff --git a/modules/zivid/__init__.py b/modules/zivid/__init__.py index 07d8ad02..43974e09 100644 --- a/modules/zivid/__init__.py +++ b/modules/zivid/__init__.py @@ -20,7 +20,7 @@ from zivid.point_cloud import PointCloud from zivid.sdk_version import SDKVersion from zivid.settings import Settings -from zivid.settings_2d import Settings2D +from zivid.settings2d import Settings2D from zivid.camera_info import CameraInfo from zivid.camera_intrinsics import CameraIntrinsics from zivid.matrix4x4 import Matrix4x4 diff --git a/modules/zivid/camera.py b/modules/zivid/camera.py index 57a41e12..b314d991 100644 --- a/modules/zivid/camera.py +++ b/modules/zivid/camera.py @@ -11,7 +11,7 @@ _to_network_configuration, ) from zivid.settings import Settings, _to_internal_settings -from zivid.settings_2d import Settings2D, _to_internal_settings2d +from zivid.settings2d import Settings2D, _to_internal_settings2d class Camera: diff --git a/modules/zivid/experimental/calibration.py b/modules/zivid/experimental/calibration.py index f657e4b6..f1ba4f66 100644 --- a/modules/zivid/experimental/calibration.py +++ b/modules/zivid/experimental/calibration.py @@ -7,7 +7,7 @@ from zivid.camera_intrinsics import _to_camera_intrinsics from zivid.frame import Frame from zivid.settings import Settings, _to_internal_settings -from zivid.settings_2d import Settings2D, _to_internal_settings2d +from zivid.settings2d import Settings2D, _to_internal_settings2d def intrinsics(camera, settings=None): diff --git a/modules/zivid/frame_2d.py b/modules/zivid/frame_2d.py index edf9e68a..50acc39f 100644 --- a/modules/zivid/frame_2d.py +++ b/modules/zivid/frame_2d.py @@ -1,7 +1,7 @@ """Contains the Frame class.""" import _zivid -from zivid.settings_2d import _to_settings2d +from zivid.settings2d import _to_settings2d from zivid.camera_info import _to_camera_info from zivid.camera_state import _to_camera_state from zivid.frame_info import _to_frame_info diff --git a/modules/zivid/projection.py b/modules/zivid/projection.py index 4285bde1..c93578a8 100644 --- a/modules/zivid/projection.py +++ b/modules/zivid/projection.py @@ -2,7 +2,7 @@ import _zivid from zivid.frame_2d import Frame2D -from zivid.settings_2d import Settings2D, _to_internal_settings2d +from zivid.settings2d import Settings2D, _to_internal_settings2d class ProjectedImage: diff --git a/modules/zivid/settings.py b/modules/zivid/settings.py index 9de28854..af540dc2 100644 --- a/modules/zivid/settings.py +++ b/modules/zivid/settings.py @@ -3,6 +3,7 @@ # pylint: disable=too-many-lines,protected-access,too-few-public-methods,too-many-arguments,line-too-long,missing-function-docstring,missing-class-docstring,redefined-builtin,too-many-branches,too-many-boolean-expressions import datetime import collections.abc +import zivid.settings2d import _zivid @@ -2707,7 +2708,7 @@ def valid_values(cls): def __init__( self, acquisitions=None, - color=_zivid.Settings.Color().value, + color=None, engine=_zivid.Settings.Engine().value, diagnostics=None, processing=None, @@ -2733,11 +2734,11 @@ def __init__( ) ) - if isinstance(color, _zivid.Settings2D) or color is None: - self._color = _zivid.Settings.Color(color) + if isinstance(color, zivid.settings2d.Settings2D) or color is None: + self._color = color else: raise TypeError( - "Unsupported type, expected: _zivid.Settings2D or None, got {value_type}".format( + "Unsupported type, expected: zivid.settings2d.Settings2D or None, got {value_type}".format( value_type=type(color) ) ) @@ -2785,7 +2786,7 @@ def acquisitions(self): @property def color(self): - return self._color.value + return self._color @property def engine(self): @@ -2827,11 +2828,11 @@ def acquisitions(self, value): @color.setter def color(self, value): - if isinstance(value, _zivid.Settings2D) or value is None: - self._color = _zivid.Settings.Color(value) + if isinstance(value, zivid.settings2d.Settings2D) or value is None: + self._color = value else: raise TypeError( - "Unsupported type, expected: zivid.Settings or None, got {value_type}".format( + "Unsupported type, expected: zivid.settings2d.Settings2D or None, got {value_type}".format( value_type=type(value) ) ) @@ -3159,7 +3160,11 @@ def _to_settings(internal_settings): internal_settings.region_of_interest ), sampling=_to_settings_sampling(internal_settings.sampling), - color=internal_settings.color.value, + color=( + zivid.settings2d._to_settings2d(internal_settings.color.value) + if internal_settings.color.value is not None + else None + ), engine=internal_settings.engine.value, ) @@ -3556,7 +3561,11 @@ def _to_internal_settings(settings): temp_acquisitions.append(_to_internal_settings_acquisition(value)) internal_settings.acquisitions = temp_acquisitions - internal_settings.color = _zivid.Settings.Color(settings.color) + internal_settings.color = _zivid.Settings.Color( + zivid.settings2d._to_internal_settings2d(settings.color) + if settings.color is not None + else None + ) internal_settings.engine = _zivid.Settings.Engine(settings._engine.value) internal_settings.diagnostics = _to_internal_settings_diagnostics( diff --git a/modules/zivid/settings_2d.py b/modules/zivid/settings2d.py similarity index 100% rename from modules/zivid/settings_2d.py rename to modules/zivid/settings2d.py diff --git a/test/calibration/test_intrinsics.py b/test/calibration/test_intrinsics.py index e0e5baad..0f0252b9 100644 --- a/test/calibration/test_intrinsics.py +++ b/test/calibration/test_intrinsics.py @@ -26,7 +26,7 @@ def test_intrinsics(shared_file_camera): def test_intrinsics_with_settings_2d(shared_file_camera): from zivid.experimental.calibration import intrinsics - from zivid.settings_2d import Settings2D + from zivid.settings2d import Settings2D camera_intrinsics = intrinsics( camera=shared_file_camera, diff --git a/test/converters/test_convert_settings_2d.py b/test/converters/test_convert_settings_2d.py index c73f9b76..859031fc 100644 --- a/test/converters/test_convert_settings_2d.py +++ b/test/converters/test_convert_settings_2d.py @@ -1,7 +1,7 @@ def test_to_internal_settings_to_settings_modified(): import datetime from zivid import Settings2D - from zivid.settings_2d import _to_settings2d, _to_internal_settings2d + from zivid.settings2d import _to_settings2d, _to_internal_settings2d modified_settings = Settings2D( acquisitions=[ @@ -17,7 +17,7 @@ def test_to_internal_settings_to_settings_modified(): def test_to_internal_settings_to_settings_default(): from zivid import Settings2D - from zivid.settings_2d import _to_settings2d, _to_internal_settings2d + from zivid.settings2d import _to_settings2d, _to_internal_settings2d default_settings = Settings2D() converted_settings = _to_settings2d(_to_internal_settings2d(default_settings)) diff --git a/test/test_settings.py b/test/test_settings.py index 27522b6c..5908c3e1 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -6,6 +6,8 @@ def test_default_settings(application): settings = zivid.Settings() + assert settings.color is None + assert isinstance(settings.acquisitions, list) assert len(settings.acquisitions) == 0 assert settings.engine is None @@ -128,6 +130,33 @@ def test_default_settings(application): assert settings.region_of_interest.depth.range is None +def test_set_color_settings(): + from zivid import Settings, Settings2D + + settings = Settings() + assert settings.color is None + + settings.color = Settings2D() + assert settings.color is not None + assert isinstance(settings.color, Settings2D) + assert settings.color == Settings2D() + + settings = Settings(color=Settings2D()) + assert settings.color is not None + assert isinstance(settings.color, Settings2D) + assert settings.color == Settings2D() + + settings = Settings(color=Settings2D(acquisitions=(Settings2D.Acquisition(),))) + assert settings.color is not None + assert isinstance(settings.color, Settings2D) + assert len(settings.color.acquisitions) == 1 + + settings = Settings() + settings.color = Settings2D() + settings.color.acquisitions.append(Settings2D.Acquisition()) + assert len(settings.color.acquisitions) == 1 + + def test_set_acquisition_list(): from zivid import Settings