From c64517a4f8f3b7097c863d68b0b25007a660f9b4 Mon Sep 17 00:00:00 2001 From: Torben Schiz Date: Tue, 18 Jun 2024 15:22:15 +0200 Subject: [PATCH] Fix h5py optional --- .github/workflows/run-unit-tests.yml | 6 +----- micro_manager/__init__.py | 15 +++++++++++++-- micro_manager/snapshot/dataset.py | 3 ++- micro_manager/snapshot/snapshot.py | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index 6152d49..cceea0f 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -25,7 +25,7 @@ jobs: - name: Install Micro Manager and uninstall pyprecice working-directory: micro-manager run: | - pip3 install --user . + pip3 install --user .[snapshot] pip3 uninstall -y pyprecice - name: Run micro_manager unit test @@ -44,10 +44,6 @@ jobs: working-directory: micro-manager/tests/unit run: python3 -m unittest test_hdf5_functionality.py - - name: Install dependencies for snapshot computation - working-directory: micro-manager/tests/unit - run: pip3 install --user ".[snapshot]" - - name: Run snapshot_computation unit tests working-directory: micro-manager/tests/unit run: python3 -m unittest test_snapshot_computation.py diff --git a/micro_manager/__init__.py b/micro_manager/__init__.py index d90d2cd..54e01d9 100644 --- a/micro_manager/__init__.py +++ b/micro_manager/__init__.py @@ -3,7 +3,13 @@ from .config import Config from .micro_manager import MicroManagerCoupling -from .snapshot.snapshot import MicroManagerSnapshot + +try: + from .snapshot.snapshot import MicroManagerSnapshot + + is_snapshot_possible = True +except ImportError: + is_snapshot_possible = False def main(): @@ -24,7 +30,12 @@ def main(): if not args.snapshot: manager = MicroManagerCoupling(config_file_path) else: - manager = MicroManagerSnapshot(config_file_path) + if not is_snapshot_possible: + raise ImportError( + "The Micro Manager snapshot computation requires the h5py package." + ) + else: + manager = MicroManagerSnapshot(config_file_path) manager.initialize() diff --git a/micro_manager/snapshot/dataset.py b/micro_manager/snapshot/dataset.py index b92252c..b2e98b0 100644 --- a/micro_manager/snapshot/dataset.py +++ b/micro_manager/snapshot/dataset.py @@ -1,13 +1,14 @@ from importlib import metadata import os from datetime import datetime + import numpy as np try: import h5py except ImportError: raise ImportError( - "The Micro Manager snapshot computation requires the h5py package to store snapshots." + "The Micro Manager snapshot computation requires the h5py package." ) diff --git a/micro_manager/snapshot/snapshot.py b/micro_manager/snapshot/snapshot.py index 28e4bac..cab4d28 100644 --- a/micro_manager/snapshot/snapshot.py +++ b/micro_manager/snapshot/snapshot.py @@ -12,9 +12,10 @@ import importlib import os import sys -import numpy as np import time +import numpy as np + from micro_manager.micro_manager import MicroManager from .dataset import ReadWriteHDF from micro_manager.micro_simulation import create_simulation_class