Skip to content

Commit

Permalink
Replace pkg_resources with importlib solution (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani authored Nov 21, 2022
1 parent 1ba3bd9 commit e23b091
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions auditlog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from pkg_resources import DistributionNotFound, get_distribution

try:
__version__ = get_distribution("django-auditlog").version
except DistributionNotFound:
# package is not installed
pass
from importlib.metadata import version # New in Python 3.8
except ImportError:
from pkg_resources import ( # from setuptools, deprecated
DistributionNotFound,
get_distribution,
)

try:
__version__ = get_distribution("django-auditlog").version
except DistributionNotFound:
# package is not installed
pass
else:
__version__ = version("django-auditlog")
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
from datetime import date

from pkg_resources import get_distribution
from auditlog import __version__

# -- Path setup --------------------------------------------------------------

Expand All @@ -33,7 +33,7 @@
author = "Jan-Jelle Kester and contributors"
copyright = f"2013-{date.today().year}, {author}"

release = get_distribution("django-auditlog").version
release = __version__
# for example take major/minor
version = ".".join(release.split(".")[:2])

Expand Down

0 comments on commit e23b091

Please sign in to comment.