Skip to content

Think about how reader is chosen #20

@TimMonko

Description

@TimMonko

🧰 Task

Currently there are two paths, and they have crossover and need to figure out the best way. I need to reduce the duplicated logic here. And probably find a way to also use determine_plugin() from bioio a bit more cleanly for shared logic, because this would be more consistent than grabbing the first in the list (bioio grabs the most recently installed)

  1. report = self.feasibility_report
    # Try preferred reader first
    if (
    preferred_reader
    and preferred_reader in report
    and report[preferred_reader].supported
    ):
    logger.info(
    "Using preferred reader: %s for %s",
    preferred_reader,
    self.path,
    )
    return self._get_reader_module(preferred_reader)
    # Try any installed reader that supports the file
    for name, support in report.items():
    if name != "ArrayLike" and support.supported:
    logger.info(
    "Using reader: %s for %s (preferred not available)",
    name,
    self.path,
    )
    return self._get_reader_module(name)
    logger.warning("No working reader found for: %s", self.path)
    return None
  2. preferred_reader = (
    preferred_reader or settings.ndevio_Reader.preferred_reader # type: ignore
    )
    # Only use ReaderPluginManager for file paths, not arrays
    if isinstance(image, str | Path):
    manager = ReaderPluginManager(image)
    reader = manager.get_working_reader(preferred_reader)
    if reader:
    return reader
    # No reader found - raise with helpful message if enabled
    if settings.ndevio_Reader.suggest_reader_plugins: # type: ignore
    raise UnsupportedFileFormatError(
    reader_name="ndevio",
    path=str(image),
    msg_extra=manager.get_installation_message(),
    )
    else:
    # Re-raise without suggestions
    raise UnsupportedFileFormatError(
    reader_name="ndevio",
    path=str(image),
    )
    else:
    # For arrays, use bioio's built-in plugin determination
    try:
    return nImage.determine_plugin(image).metadata.get_reader()
    except UnsupportedFileFormatError:
    # Re-raise for non-file inputs
    raise

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions