Skip to content

Commit

Permalink
Remove and replace pkg_resources and distutils with modern equivalents
Browse files Browse the repository at this point in the history
  • Loading branch information
aclark4life committed May 8, 2024
1 parent c9d7bf2 commit 04cfe20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions newsletter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pkg_resources import get_distribution, DistributionNotFound
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = get_distribution("django-newsletter").version
except DistributionNotFound:
__version__ = version("django-newsletter")
except PackageNotFoundError:
# package is not installed
__version__ = None
10 changes: 7 additions & 3 deletions newsletter/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys
import os
import time
from datetime import datetime
Expand All @@ -17,7 +18,7 @@
from django.utils.timezone import now
from django.urls import reverse

from distutils.version import LooseVersion
# from distutils.version import LooseVersion

from .fields import DynamicImageField
from .utils import (
Expand Down Expand Up @@ -740,8 +741,11 @@ def get_absolute_url(self):
def get_address(name, email):
# Converting name to ascii for compatibility with django < 1.9.
# Remove this when django 1.8 is no longer supported.
if LooseVersion(django.get_version()) < LooseVersion('1.9'):
name = name.encode('ascii', 'ignore').decode('ascii').strip()
# if LooseVersion(django.get_version()) < LooseVersion('1.9'):
# name = name.encode('ascii', 'ignore').decode('ascii').strip()
# Assuming django.get_version() returns a string like '1.8.18'
django_version = tuple(map(int, django.get_version().split('.')))
name = name.encode('ascii', 'ignore').decode('ascii').strip() if django_version < (1, 9) else name
if name:
return f'{name} <{email}>'
else:
Expand Down

0 comments on commit 04cfe20

Please sign in to comment.