Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FilenameProvider optional on PathProvider impl #547

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading