forked from AllenCellModeling/aicsimageio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/import-any-reader-from-readers (AllenCellModeling#326)
* allow reader import * use forward ref * fix docs
- Loading branch information
1 parent
3ff8d7b
commit 5ea864b
Showing
1 changed file
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,38 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from .array_like_reader import ArrayLikeReader # noqa: F401 | ||
from .ome_tiff_reader import OmeTiffReader # noqa: F401 | ||
from .tiff_reader import TiffReader # noqa: F401 | ||
from typing import TYPE_CHECKING, Type | ||
|
||
# To add a new reader add it both to TYPE_CHECKING and _READERS | ||
|
||
if TYPE_CHECKING: | ||
from .array_like_reader import ArrayLikeReader # noqa: F401 | ||
from .bioformats_reader import BioformatsReader # noqa: F401 | ||
from .czi_reader import CziReader # noqa: F401 | ||
from .lif_reader import LifReader # noqa: F401 | ||
from .ome_tiff_reader import OmeTiffReader # noqa: F401 | ||
from .reader import Reader | ||
from .tiff_reader import TiffReader # noqa: F401 | ||
|
||
|
||
# add ".relativepath.ClassName" | ||
_READERS = ( | ||
".array_like_reader.ArrayLikeReader", | ||
".bioformats_reader.BioformatsReader", | ||
".czi_reader.CziReader", | ||
".lif_reader.LifReader", | ||
".ome_tiff_reader.OmeTiffReader", | ||
".tiff_reader.TiffReader", | ||
) | ||
_LOOKUP = {k.rsplit(".", 1)[-1]: k for k in _READERS} | ||
__all__ = list(_LOOKUP) | ||
|
||
|
||
def __getattr__(name: str) -> Type["Reader"]: | ||
if name in _LOOKUP: | ||
from importlib import import_module | ||
|
||
path, clsname = _LOOKUP[name].rsplit(".", 1) | ||
mod = import_module(path, __name__) | ||
return getattr(mod, clsname) | ||
raise AttributeError(f"module {__name__!r} has no attribute import name {name!r}") |