Skip to content

Commit 362f33a

Browse files
authored
Merge pull request #120 from AllenNeuralDynamics/fix-type-hint
Improve type hinting for Watchdog service
2 parents f1c0bbc + aea9a98 commit 362f33a

File tree

3 files changed

+99
-97
lines changed

3 files changed

+99
-97
lines changed

src/clabe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.6.7"
1+
__version__ = "0.6.8"
22

33
import logging
44

src/clabe/data_transfer/aind_watchdog.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import subprocess
1515
from os import PathLike
1616
from pathlib import Path, PurePosixPath
17-
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, List, Optional, Union
17+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Generic, List, Optional, TypeVar, Union
1818

1919
import aind_data_transfer_service.models.core
2020
import pydantic
@@ -25,7 +25,6 @@
2525
from requests.exceptions import HTTPError
2626

2727
from .. import ui
28-
from ..data_mapper.aind_data_schema import AindDataSchemaSessionDataMapper
2928
from ..launcher._callable_manager import Promise
3029
from ..services import ServiceSettings
3130
from ._aind_watchdog_models import (
@@ -40,16 +39,19 @@
4039
if TYPE_CHECKING:
4140
from aind_data_schema.core.session import Session as AdsSession
4241

42+
from ..data_mapper.aind_data_schema import AindDataSchemaSessionDataMapper
4343
from ..launcher import Launcher
4444
else:
4545
Launcher = Any
4646
AdsSession = Any
47+
AindDataSchemaSessionDataMapper = Any
4748

4849
logger = logging.getLogger(__name__)
4950

5051
TransferServiceTask = Dict[
5152
str, Union[aind_data_transfer_service.models.core.Task, Dict[str, aind_data_transfer_service.models.core.Task]]
5253
]
54+
TSessionMapper = TypeVar("TSessionMapper", bound=AindDataSchemaSessionDataMapper)
5355

5456

5557
class WatchdogSettings(ServiceSettings):
@@ -91,7 +93,7 @@ class WatchdogSettings(ServiceSettings):
9193
job_type: str = "default"
9294

9395

94-
class WatchdogDataTransferService(DataTransfer[WatchdogSettings]):
96+
class WatchdogDataTransferService(DataTransfer[WatchdogSettings], Generic[TSessionMapper]):
9597
"""
9698
A data transfer service that uses the aind-watchdog-service to monitor and transfer
9799
data based on manifest configurations.
@@ -103,7 +105,7 @@ class WatchdogDataTransferService(DataTransfer[WatchdogSettings]):
103105
Attributes:
104106
_source (PathLike): Source directory to monitor
105107
_settings (WatchdogSettings): Service settings containing destination and configuration
106-
_aind_session_data_mapper (Optional[AindDataSchemaSessionDataMapper]): Mapper for session data
108+
_aind_session_data_mapper (Optional[_TSessionMapper]): Mapper for session data
107109
_ui_helper (ui.UiHelper): UI helper for user prompts
108110
Various configuration attributes accessible via settings
109111
@@ -188,7 +190,7 @@ def __init__(
188190
self._settings = settings
189191
self._source = source
190192

191-
self._aind_session_data_mapper: Optional[AindDataSchemaSessionDataMapper] = None
193+
self._aind_session_data_mapper: Optional[TSessionMapper] = None
192194

193195
_default_exe = os.environ.get("WATCHDOG_EXE", None)
194196
_default_config = os.environ.get("WATCHDOG_CONFIG", None)
@@ -207,7 +209,7 @@ def __init__(
207209
self._session_name = session_name
208210

209211
@property
210-
def aind_session_data_mapper(self) -> AindDataSchemaSessionDataMapper:
212+
def aind_session_data_mapper(self) -> TSessionMapper:
211213
"""
212214
Gets the aind-data-schema session data mapper.
213215
@@ -221,7 +223,7 @@ def aind_session_data_mapper(self) -> AindDataSchemaSessionDataMapper:
221223
raise ValueError("Data mapper is not set.")
222224
return self._aind_session_data_mapper
223225

224-
def with_aind_session_data_mapper(self, value: AindDataSchemaSessionDataMapper) -> "WatchdogDataTransferService":
226+
def with_aind_session_data_mapper(self, value: TSessionMapper) -> "WatchdogDataTransferService[TSessionMapper]":
225227
"""
226228
Sets the aind-data-schema session data mapper.
227229
@@ -705,9 +707,8 @@ def prompt_input(self) -> bool:
705707
def build_runner(
706708
cls,
707709
settings: WatchdogSettings,
708-
aind_session_data_mapper: Promise[[Launcher], AindDataSchemaSessionDataMapper]
709-
| AindDataSchemaSessionDataMapper,
710-
) -> Callable[[Launcher], "WatchdogDataTransferService"]:
710+
aind_session_data_mapper: Promise[[Launcher], TSessionMapper] | TSessionMapper,
711+
) -> Callable[[Launcher], "WatchdogDataTransferService[TSessionMapper]"]:
711712
"""
712713
A factory method for creating the watchdog service.
713714

0 commit comments

Comments
 (0)