Skip to content

Commit c92e7d5

Browse files
norlandrhagenMax Jones
andauthored
Use importlib.metadata rather than pkg_resources (#97)
* Use importlib.metadata rather than pkg_resources for dynamic version metadata Co-authored-by: Max Jones <[email protected]>
1 parent 57cb69c commit c92e7d5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ select = B,C,E,F,W,T4,B9
77

88
[isort]
99
known_first_party=xbatcher
10-
known_third_party=numpy,pkg_resources,pytest,setuptools,sphinx_autosummary_accessors,tensorflow,torch,xarray
10+
known_third_party=numpy,pytest,setuptools,sphinx_autosummary_accessors,tensorflow,torch,xarray
1111
multi_line_output=3
1212
include_trailing_comma=True
1313
force_grid_wrap=0

xbatcher/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from pkg_resources import DistributionNotFound, get_distribution
1+
from importlib.metadata import (
2+
PackageNotFoundError as _PackageNotFoundError,
3+
version as _version,
4+
)
25

36
from .accessors import BatchAccessor # noqa: F401
47
from .generators import BatchGenerator # noqa: F401
58
from .util.print_versions import show_versions # noqa: F401
69

710
try:
8-
__version__ = get_distribution(__name__).version
9-
except DistributionNotFound: # noqa: F401; pragma: no cover
11+
__version__ = _version(__name__)
12+
except _PackageNotFoundError:
1013
# package is not installed
11-
pass
14+
__version__ = 'unknown'

0 commit comments

Comments
 (0)