Replace pkg_resources with importlib solution (#450)

This commit is contained in:
Hasan Ramezani 2022-11-21 19:20:34 +03:30 committed by GitHub
parent 1ba3bd9d07
commit e23b091c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View file

@ -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")

View file

@ -10,7 +10,7 @@ import os
import sys
from datetime import date
from pkg_resources import get_distribution
from auditlog import __version__
# -- Path setup --------------------------------------------------------------
@ -33,7 +33,7 @@ project = "django-auditlog"
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])