diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 449f78c..90998a2 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -7,7 +7,6 @@ from decimal import Decimal from functools import partial, reduce from html import escape as htmlescape -from importlib.metadata import PackageNotFoundError, version import io from itertools import chain, zip_longest as izip_longest import math @@ -21,12 +20,15 @@ except ImportError: wcwidth = None + try: - __version__ = version("tabulate") # installed package -except PackageNotFoundError: + from ._version import version as __version__ # generated by flit_scm / setuptools_scm +except ImportError: + from importlib.metadata import PackageNotFoundError, version + try: - from ._version import version as __version__ # editable / source checkout - except ImportError: + __version__ = version("tabulate") + except PackageNotFoundError: __version__ = "unknown" diff --git a/test/test_api.py b/test/test_api.py index cb59836..d6ba280 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -1,6 +1,6 @@ """API properties.""" -from tabulate import simple_separated_format, tabulate, tabulate_formats +from tabulate import __version__, simple_separated_format, tabulate, tabulate_formats from common import skip @@ -11,6 +11,12 @@ _empty = None +def test_tabulate_version(): + "API: __version__ is a non-empty string" + assert type(__version__) is str + assert len(__version__) > 0 + + def test_tabulate_formats(): "API: tabulate_formats is a list of strings" supported = tabulate_formats