Replace setuptools' pkg_resources with stdlib importlib.metadata

This commit is contained in:
Hugo van Kemenade 2023-06-15 17:49:51 +03:00
parent 6c7afb3b3f
commit b76c6c497b
2 changed files with 6 additions and 5 deletions

View file

@ -11,7 +11,7 @@
# serve to show the default.
import os
from pkg_resources import get_distribution
import importlib.metadata
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
@ -49,7 +49,8 @@ parent_dir = os.path.dirname(os.path.dirname(__file__))
# |version| and |release|, also used in various other places throughout the
# built documents.
#
release = get_distribution('django-model-utils').version
release = importlib.metadata.version('django-model-utils')
# for example take major/minor
version = '.'.join(release.split('.')[:2])

View file

@ -1,10 +1,10 @@
from pkg_resources import DistributionNotFound, get_distribution
import importlib.metadata
from .choices import Choices # noqa:F401
from .tracker import FieldTracker, ModelTracker # noqa:F401
try:
__version__ = get_distribution("django-model-utils").version
except DistributionNotFound: # pragma: no cover
__version__ = importlib.metadata.version('django-model-utils')
except importlib.metadata.PackageNotFoundError: # pragma: no cover
# package is not installed
__version__ = None