Skip to content

Commit d841037

Browse files
committed
Adds conditional import handling for OMERO file source
1 parent cd1df36 commit d841037

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/galaxy/files/sources/omero.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
Union,
77
)
88

9-
import omero.sys
10-
from omero.gateway import BlitzGateway
11-
129
from galaxy.exceptions import (
1310
AuthenticationFailed,
1411
ObjectNotFound,
@@ -27,6 +24,13 @@
2724
)
2825
from galaxy.util.config_templates import TemplateExpansion
2926

27+
try:
28+
import omero.sys
29+
from omero.gateway import BlitzGateway
30+
except ImportError:
31+
omero = None
32+
BlitzGateway = None
33+
3034

3135
class OmeroFileSourceTemplateConfiguration(BaseFileSourceTemplateConfiguration):
3236
username: Union[str, TemplateExpansion]
@@ -47,20 +51,34 @@ class OmeroFileSource(BaseFilesSource[OmeroFileSourceTemplateConfiguration, Omer
4751
plugin_kind = PluginKind.rfs
4852
supports_pagination = True
4953
supports_search = True
54+
required_module = BlitzGateway
55+
required_package = "omero-py (requires manual Zeroc IcePy installation)"
5056

5157
template_config_class = OmeroFileSourceTemplateConfiguration
5258
resolved_config_class = OmeroFileSourceConfiguration
5359

5460
def __init__(self, template_config: OmeroFileSourceTemplateConfiguration):
61+
if self.required_module is None:
62+
raise self.required_package_exception
5563
super().__init__(template_config)
5664

65+
@property
66+
def required_package_exception(self) -> Exception:
67+
return Exception(
68+
f"The Python package '{self.required_package}' is required to use this file source plugin. "
69+
"Please see https://omero.readthedocs.io/en/stable/developers/Python.html for installation instructions."
70+
)
71+
5772
@contextmanager
5873
def _connection(self, context: FilesSourceRuntimeContext[OmeroFileSourceConfiguration]) -> Iterator[BlitzGateway]:
5974
"""Context manager for OMERO connections with automatic cleanup.
6075
6176
Establishes a connection to the OMERO server, enables keepalive for long-running
6277
operations, and ensures proper cleanup on exit.
6378
"""
79+
if BlitzGateway is None:
80+
raise self.required_package_exception
81+
6482
conn = BlitzGateway(
6583
username=context.config.username,
6684
passwd=context.config.password,

0 commit comments

Comments
 (0)