示例#1
0
def read(
    path: Union[str, Sequence[str]], plugin: Optional[str] = None
) -> Optional[Tuple[List[LayerData], _FakeHookimpl]]:
    """Try to return data for `path`, from reader plugins using a manifest."""
    with suppress(ValueError):
        layer_data, reader = read_get_reader(path, plugin_name=plugin)
        return layer_data, _FakeHookimpl(reader.plugin_name)
    return None
示例#2
0
文件: _npe2.py 项目: napari/napari
def read(
    paths: Sequence[str], plugin: Optional[str] = None, *, stack: bool
) -> Optional[Tuple[List[LayerData], _FakeHookimpl]]:
    """Try to return data for `path`, from reader plugins using a manifest."""
    assert stack is not None
    # the goal here would be to make read_get_reader of npe2 aware of "stack",
    # and not have this conditional here.
    # this would also allow the npe2-npe1 shim to do this transform as well
    if stack:
        npe1_path = paths
    else:
        assert len(paths) == 1
        npe1_path = paths[0]
    try:
        layer_data, reader = read_get_reader(npe1_path, plugin_name=plugin)
        return layer_data, _FakeHookimpl(reader.plugin_name)
    except ValueError as e:
        if 'No readers returned data' not in str(e):
            raise e
    return None