From c92e7d523010d6b377705dcc14d1f0989a9cfa41 Mon Sep 17 00:00:00 2001 From: Raphael Hagen Date: Thu, 6 Oct 2022 15:02:00 -0600 Subject: [PATCH] Use importlib.metadata rather than pkg_resources (#97) * Use importlib.metadata rather than pkg_resources for dynamic version metadata Co-authored-by: Max Jones --- setup.cfg | 2 +- xbatcher/__init__.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 539a1ba..e74bfda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ select = B,C,E,F,W,T4,B9 [isort] known_first_party=xbatcher -known_third_party=numpy,pkg_resources,pytest,setuptools,sphinx_autosummary_accessors,tensorflow,torch,xarray +known_third_party=numpy,pytest,setuptools,sphinx_autosummary_accessors,tensorflow,torch,xarray multi_line_output=3 include_trailing_comma=True force_grid_wrap=0 diff --git a/xbatcher/__init__.py b/xbatcher/__init__.py index 788b309..6bdb880 100644 --- a/xbatcher/__init__.py +++ b/xbatcher/__init__.py @@ -1,11 +1,14 @@ -from pkg_resources import DistributionNotFound, get_distribution +from importlib.metadata import ( + PackageNotFoundError as _PackageNotFoundError, + version as _version, +) from .accessors import BatchAccessor # noqa: F401 from .generators import BatchGenerator # noqa: F401 from .util.print_versions import show_versions # noqa: F401 try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: # noqa: F401; pragma: no cover + __version__ = _version(__name__) +except _PackageNotFoundError: # package is not installed - pass + __version__ = 'unknown'