From bcd687f73f4d273ee37b8bf6fda798af2911d177 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 13:48:25 +0100 Subject: [PATCH] Expand backwards compatibility --- src/instamatic/TEMController/TEMController.py | 3 +++ .../{TEMController.py => TEMController/__init__.py} | 10 ++-------- src/instamatic/TEMController/microscope.py | 10 ++++++++++ src/instamatic/TEMController/microscope_client.py | 3 +++ src/instamatic/config/autoconfig.py | 6 +++--- src/instamatic/server/tem_client.py | 2 +- tests/conftest.py | 6 +++--- tests/test_ctrl.py | 4 ++-- 8 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/instamatic/TEMController/TEMController.py rename src/instamatic/{TEMController.py => TEMController/__init__.py} (73%) create mode 100644 src/instamatic/TEMController/microscope.py create mode 100644 src/instamatic/TEMController/microscope_client.py diff --git a/src/instamatic/TEMController/TEMController.py b/src/instamatic/TEMController/TEMController.py new file mode 100644 index 00000000..fc633455 --- /dev/null +++ b/src/instamatic/TEMController/TEMController.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +from instamatic.controller import TEMController diff --git a/src/instamatic/TEMController.py b/src/instamatic/TEMController/__init__.py similarity index 73% rename from src/instamatic/TEMController.py rename to src/instamatic/TEMController/__init__.py index 02b4f779..4add11de 100644 --- a/src/instamatic/TEMController.py +++ b/src/instamatic/TEMController/__init__.py @@ -1,6 +1,6 @@ +# ruff: noqa: E402 from __future__ import annotations -# ruff: noqa: E402 import warnings from instamatic.utils.deprecated import VisibleDeprecationWarning, deprecated @@ -10,6 +10,7 @@ VisibleDeprecationWarning, ) + from instamatic.controller import get_instance, initialize from instamatic.microscope.base import MicroscopeBase @@ -19,10 +20,3 @@ def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: from instamatic.microscope import get_microscope return get_microscope(name=name, use_server=use_server) - - -@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') -def get_tem(interface: str) -> 'type[MicroscopeBase]': - from instamatic.microscope import get_microscope_class - - return get_microscope_class(interface=interface) diff --git a/src/instamatic/TEMController/microscope.py b/src/instamatic/TEMController/microscope.py new file mode 100644 index 00000000..5562732b --- /dev/null +++ b/src/instamatic/TEMController/microscope.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +from instamatic.utils.deprecated import deprecated + + +@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') +def get_tem(interface: str) -> 'type[MicroscopeBase]': + from instamatic.microscope import get_microscope_class + + return get_microscope_class(interface=interface) diff --git a/src/instamatic/TEMController/microscope_client.py b/src/instamatic/TEMController/microscope_client.py new file mode 100644 index 00000000..ca7755d9 --- /dev/null +++ b/src/instamatic/TEMController/microscope_client.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +from instamatic.microscope.client import MicroscopeClient diff --git a/src/instamatic/config/autoconfig.py b/src/instamatic/config/autoconfig.py index 6936f466..6047bb88 100644 --- a/src/instamatic/config/autoconfig.py +++ b/src/instamatic/config/autoconfig.py @@ -126,15 +126,15 @@ def main(): cam_name = None from instamatic.camera.camera import get_cam - from instamatic.controller import TEMController - from instamatic.microscope.microscope import get_microscope_class + from instamatic.TEMController.microscope import get_tem + from instamatic.TEMController.TEMController import TEMController if cam_connect: cam = get_cam(cam_name)() if cam_name else None else: cam = None - tem = get_microscope_class(tem_name)() + tem = get_tem(tem_name)() ctrl = TEMController(tem=tem, cam=cam) diff --git a/src/instamatic/server/tem_client.py b/src/instamatic/server/tem_client.py index bf591161..ce184193 100644 --- a/src/instamatic/server/tem_client.py +++ b/src/instamatic/server/tem_client.py @@ -1,7 +1,7 @@ from __future__ import annotations from instamatic import config -from instamatic.microscope.client import MicroscopeClient +from instamatic.TEMController.microscope_client import MicroscopeClient microscope_id = config.microscope.name diff --git a/tests/conftest.py b/tests/conftest.py index efe3eb56..9a71e297 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ # Actually importing the controller class breaks the tests if TYPE_CHECKING: - from instamatic.controller import TEMController + from instamatic.TEMController.TEMController import TEMController base_drc = Path(__file__).parent @@ -21,9 +21,9 @@ def pytest_configure(): @pytest.fixture(scope='module') def ctrl() -> 'TEMController': - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() # set instant stage movement for testing ctrl.tem._set_instant_stage_movement() diff --git a/tests/test_ctrl.py b/tests/test_ctrl.py index 123b34a9..8c262772 100644 --- a/tests/test_ctrl.py +++ b/tests/test_ctrl.py @@ -5,9 +5,9 @@ def test_setup(ctrl): - from instamatic import controller + from instamatic import TEMController - ctrl2 = controller.get_instance() + ctrl2 = TEMController.get_instance() assert ctrl2 is ctrl