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

Split out FilenameProvider, rename DirectoryProvider to PathProvider #245

Merged
merged 36 commits into from
Jul 17, 2024

Conversation

jwlodek
Copy link
Member

@jwlodek jwlodek commented Apr 18, 2024

Creating this as a draft PR first to get some feedback before I apply fixes to the filewriters to account for this change.

Addresses #214

@jwlodek jwlodek requested a review from coretl April 18, 2024 15:52
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
@jwlodek
Copy link
Member Author

jwlodek commented Apr 29, 2024

Before I continue, I'd like to hear if you have any suggestions. @coretl @mrakitin @DiamondJoseph

@jwlodek jwlodek requested a review from mrakitin April 29, 2024 21:16
@jwlodek jwlodek changed the title First pass at splitting out FilenameProvider from DirectoryProvider Split out FilenameProvider, rename DirectoryProvider to PathProvider May 3, 2024
@jwlodek jwlodek marked this pull request as ready for review May 3, 2024 16:16
Copy link
Collaborator

@coretl coretl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of 2 usecases for us:

  • For testing we would like all the files for a given detector to be placed in a predictable tmp_path. I guess we could either use a different StaticPathProvider and AutoIncrementingFilenameProvider for each detector, or we could pass down device_name to all FilenameProviders and allow AutoIncrementingFilenameProvider to use that in its format string.
  • In production we will probably make a PathProvider that doesn't use a FilenameProvider at all, just generates the names according to DLS conventions

So feel free to delete all the prefix and suffix code that you wouldn't use yourself.

src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/panda/writers/_hdf_writer.py Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
@mrakitin
Copy link
Member

I'll review once rebased :)

@jwlodek
Copy link
Member Author

jwlodek commented May 17, 2024

@mrakitin @danielballan @coretl I think this is ready for review and potentially merge

Copy link
Member

@mrakitin mrakitin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Proposed some non-blocking suggestions, most of them are optional.

src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
tests/core/test_providers.py Show resolved Hide resolved
@mrakitin
Copy link
Member

I have some fixes from yesterday's and today's work at HEX in jwlodek#1. Please merge, then we can rebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's a leftover from my rebasing...
Is it all now implemented in https://github.com/bluesky/ophyd-async/blob/main/src/ophyd_async/epics/areadetector/writers/general_hdffile.py?

Copy link
Member

@mrakitin mrakitin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is passing now! Codecov is failing, but I don't think it should be a blocker.
A couple of questions to @coretl, @evalott100, and @abbiemery are below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrakitin
Copy link
Member

A comment #245 (review) was intended to be a part of my review. Sorry for posting it separately.

src/ophyd_async/core/_providers.py Outdated Show resolved Hide resolved
Comment on lines 57 to 62
class UUIDFilenameProvider(FilenameProvider):
def __init__(
self, uuid_call_func: Callable = uuid.uuid4, uuid_call_args: Optional[List] = []
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this explicitly a Callable with no input args: if you want to use a uuid generator that takes arguments, you should construct a partial and pass that.

This then is just a CallableFileNameProvider, as it could take any partial not just a UUID one.

The case of needing the current state to calculate the FileName isn't covered here: it's always taking the same uuid_call_args with every call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or make call_func: Callable[[P], str], call_args: P where P = ParamSpec("P")

src/ophyd_async/epics/areadetector/writers/_hdffile.py Outdated Show resolved Hide resolved
src/ophyd_async/panda/writers/_panda_hdf_file.py Outdated Show resolved Hide resolved
Comment on lines +135 to +148
@pytest.fixture
def static_path_provider_factory(tmp_path: Path):
def create_static_dir_provider_given_fp(fp: FilenameProvider):
return StaticPathProvider(fp, tmp_path)

return create_static_dir_provider_given_fp


@pytest.fixture
def static_path_provider(
static_path_provider_factory: callable,
static_filename_provider: FilenameProvider,
):
return static_path_provider_factory(static_filename_provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@pytest.fixture
def static_path_provider_factory(tmp_path: Path):
def create_static_dir_provider_given_fp(fp: FilenameProvider):
return StaticPathProvider(fp, tmp_path)
return create_static_dir_provider_given_fp
@pytest.fixture
def static_path_provider(
static_path_provider_factory: callable,
static_filename_provider: FilenameProvider,
):
return static_path_provider_factory(static_filename_provider)
@pytest.fixture
def static_path_provider(tmp_path: Path, static_filename_provider: StaticFilenameProvider):
return StaticPathProvider(static_filename_provider, tmp_path)

Do you need this factory function elsewhere? It doesn't seem to be required.

jwlodek and others added 26 commits July 17, 2024 09:24
@abbiemery abbiemery force-pushed the directory-provider-refactor branch from 18e12a5 to 0b344e4 Compare July 17, 2024 08:24
@abbiemery abbiemery merged commit 924edbe into bluesky:main Jul 17, 2024
10 of 11 checks passed
@jwlodek jwlodek deleted the directory-provider-refactor branch August 9, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants