diff --git a/pyproject.toml b/pyproject.toml index dc8556e..d87f5f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ Repository = "https://github.com/PolusAI/bfio" [tool.setuptools.dynamic] -version = {attr = "bfio.__version__"} +version = {file = ["src/bfio/VERSION"]} [tool.setuptools] diff --git a/src/bfio/__init__.py b/src/bfio/__init__.py index 5591eec..87fa03a 100644 --- a/src/bfio/__init__.py +++ b/src/bfio/__init__.py @@ -3,6 +3,7 @@ import logging import pathlib +from typing import Any JAR_VERSION = None @@ -16,15 +17,29 @@ try: with open(pathlib.Path(__file__).parent.joinpath("VERSION"), "r") as fh: - __version__ = fh.read() + __version__ = fh.read().strip() except FileNotFoundError: logger.info( "Could not find VERSION. " - + "This is likely due to using a local/cloned version of bfio." + "This is likely due to using a local/cloned version of bfio." ) __version__ = "0.0.0" -logger.info("VERSION = {}".format(__version__)) +logger.info("VERSION = %s", __version__) -from .bfio import BioReader, BioWriter # NOQA: F401, E402 -from .utils import start # NOQA: F401, E402 +# same public API but with lazy imports +__all__ = ["BioReader", "BioWriter", "start", "__version__", "JAR_VERSION", "log_level"] + + +def __getattr__(name: str) -> Any: + if name in ("BioReader", "BioWriter"): + from .bfio import BioReader, BioWriter # local import (lazy) + + return BioReader if name == "BioReader" else BioWriter + + if name == "start": + from .utils import start # local import (lazy) + + return start + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}")