python: replace pkg_resources with importlib.metadata

Use of pkg_resources is discouraged in favor of importlib.resources,
importlib.metadata, and their backports.
This commit is contained in:
Robert Schütz
2023-02-20 09:29:38 -08:00
committed by Robert Schütz
parent 999a9550f5
commit d3f4654d4b
2 changed files with 7 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
import sys
from pkg_resources import DistributionNotFound, get_distribution
if sys.version_info >= (3, 8):
from importlib.metadata import PackageNotFoundError, version
else:
from importlib_metadata import PackageNotFoundError, version
from . import capi, events, hookspec # noqa
from .account import Account, get_core_info # noqa
@@ -11,8 +14,8 @@ from .hookspec import account_hookimpl, global_hookimpl # noqa
from .message import Message # noqa
try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = version(__name__)
except PackageNotFoundError:
# package is not installed
__version__ = "0.0.0.dev0-unknown"