Skip to content

Commit

Permalink
Replace setuptools' pkg_resources with stdlib importlib.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jun 15, 2023
1 parent 6c7afb3 commit b76c6c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,7 +49,8 @@
# |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])

Expand Down
6 changes: 3 additions & 3 deletions model_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b76c6c4

Please sign in to comment.