From 23a3edd500f301104d30f032fb52591fcc2ce7b3 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Fri, 8 Mar 2024 09:44:47 -0500 Subject: [PATCH] Include `__version__` at runtime (#176) This PR adds a `__version__` attribute to the top level module --- python/acquire/__init__.py | 7 ++++++- python/acquire/__init__.pyi | 2 ++ tests/test_basic.py | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/acquire/__init__.py b/python/acquire/__init__.py index 9d95d2a..9ed1cd9 100644 --- a/python/acquire/__init__.py +++ b/python/acquire/__init__.py @@ -9,12 +9,17 @@ Tuple, Union, ) - +from importlib.metadata import version, PackageNotFoundError import numpy.typing as npt from . import acquire from .acquire import * +try: + __version__ = version("acquire-imaging") +except PackageNotFoundError: + __version__ = "uninstalled" + __doc__ = acquire.__doc__ import logging diff --git a/python/acquire/__init__.pyi b/python/acquire/__init__.pyi index 3c40e76..79468af 100644 --- a/python/acquire/__init__.pyi +++ b/python/acquire/__init__.pyi @@ -4,6 +4,8 @@ import napari # type: ignore from .acquire import Runtime, Properties +__version__: str + def setup( runtime: Runtime, camera: Union[str, List[str]] = ..., diff --git a/tests/test_basic.py b/tests/test_basic.py index b72e78a..cbca4ea 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -18,6 +18,13 @@ def runtime(): yield acquire.Runtime() +def test_version(): + assert isinstance(acquire.__version__, str) + # this will fail if pip install -e . has not been run + # so feel free to remove this line if it's not what you want to test + assert acquire.__version__ != "uninstalled" + + def test_set(): t = Trigger() assert not t.enable