Skip to content

Commit

Permalink
Make FilenameProvider optional on PathProvider impl (#547)
Browse files Browse the repository at this point in the history
* Adjust FilenameProvider signature to match PathProvider
  • Loading branch information
DiamondJoseph committed Aug 30, 2024
1 parent 0a1b661 commit 3750ede
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/ophyd_async/core/_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ class PathInfo:

class FilenameProvider(Protocol):
@abstractmethod
def __call__(self) -> str:
def __call__(self, device_name: Optional[str] = None) -> str:
"""Get a filename to use for output data, w/o extension"""


class PathProvider(Protocol):
_filename_provider: FilenameProvider

@abstractmethod
def __call__(self, device_name: Optional[str] = None) -> PathInfo:
"""Get the current directory to write files into"""
Expand All @@ -42,7 +40,7 @@ class StaticFilenameProvider(FilenameProvider):
def __init__(self, filename: str):
self._static_filename = filename

def __call__(self) -> str:
def __call__(self, device_name: Optional[str] = None) -> str:
return self._static_filename


Expand All @@ -55,7 +53,7 @@ def __init__(
self._uuid_call_func = uuid_call_func
self._uuid_call_args = uuid_call_args or []

def __call__(self) -> str:
def __call__(self, device_name: Optional[str] = None) -> str:
if (
self._uuid_call_func in [uuid.uuid3, uuid.uuid5]
and len(self._uuid_call_args) < 2
Expand Down Expand Up @@ -84,7 +82,7 @@ def __init__(
self._increment = increment
self._inc_delimeter = inc_delimeter

def __call__(self):
def __call__(self, device_name: Optional[str] = None) -> str:
if len(str(self._current_value)) > self._max_digits:
raise ValueError(
f"Auto incrementing filename counter \
Expand All @@ -111,7 +109,7 @@ def __init__(
self._create_dir_depth = create_dir_depth

def __call__(self, device_name: Optional[str] = None) -> PathInfo:
filename = self._filename_provider()
filename = self._filename_provider(device_name)

return PathInfo(
directory_path=self._directory_path,
Expand Down Expand Up @@ -146,7 +144,7 @@ def __init__(
self._inc_delimeter = inc_delimeter

def __call__(self, device_name: Optional[str] = None) -> PathInfo:
filename = self._filename_provider()
filename = self._filename_provider(device_name)

padded_counter = f"{self._current_value:0{self._max_digits}}"

Expand Down Expand Up @@ -199,7 +197,7 @@ def __call__(self, device_name: Optional[str] = None) -> PathInfo:
current_date,
)

filename = self._filename_provider()
filename = self._filename_provider(device_name)
return PathInfo(
directory_path=self._base_directory_path / ymd_dir_path,
filename=filename,
Expand Down

0 comments on commit 3750ede

Please sign in to comment.