Skip to content

Commit b273a05

Browse files
committed
refactor: update code according to deprecations and removals in Python 3.12
This commit makes the following changes to address deprecations and removals in Python 3.12: - Replace usage of `pkg_resources` with `importlib` as `pkg_resources` is deprecated and will be removed in December 2025. see: https://setuptools.pypa.io/en/stable/history.html#v80-9-0 - Upgrade `celery` to version `5.3.0` which includes fixes for the `entry_points` interface change in 3.12. This change was necessary to address unit test failures in 3.12. see: celery/celery#7785 - Replace `assertEquals` with `assertEqual` in unit tests as `assertEquals` has been removed in 3.12. see: https://docs.python.org/3.12/whatsnew/3.12.html#unittest-testcase-removed-aliases This commit also includes the following changes as a consequence of the above updates: - Update `startup_procedures.py` to enable use of 3.12. - In the `tests.yml` workflow, add 3.12 to the versions matrix. In addition, this commit also makes the following change: - Update `pre-commit/action` to the latest version `v3.0.1` to address the following runtime error with `v.2.0.0`: github.com/actions/cache/issues/820
1 parent bde5d93 commit b273a05

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
max-parallel: 4
1010
matrix:
11-
python-version: [3.11.7]
11+
python-version: [3.11.7, 3.12.3]
1212

1313
# services:
1414
# postgres:
@@ -32,7 +32,7 @@ jobs:
3232
python-version: ${{ matrix.python-version }}
3333
# see https://github.com/pre-commit/action/#using-this-action
3434
- name: pre-commit checks
35-
uses: pre-commit/action@v2.0.0
35+
uses: pre-commit/action@v3.0.1
3636
env:
3737
# it's okay for github to commit to main/master
3838
SKIP: no-commit-to-branch

askbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'bleach': 'bleach==5.0.1',
2424
'bs4': 'beautifulsoup4<=4.7.1',
2525
'compressor': 'django-compressor>=3.0,<=4.4',
26-
'celery': 'celery==5.2.7',
26+
'celery': 'celery==5.3.0',
2727
'django': 'django>=3.0,<5.0',
2828
'django_countries': 'django-countries>=3.3',
2929
'django_jinja': 'django-jinja>=2.0',

askbot/deployment/path_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os.path
44
import re
55
import glob
6-
import imp
6+
import importlib
77

88

99
IMPORT_RE1 = re.compile(r'from django.*import')
@@ -28,7 +28,7 @@ def is_dir_python_module(directory):
2828
"""True if directory is not taken by another python module"""
2929
dir_name = os.path.basename(directory)
3030
try:
31-
imp.find_module(dir_name)
31+
importlib.find_module(dir_name)
3232
return True
3333
except ImportError:
3434
return False

askbot/startup_procedures.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import askbot
1313
import django
1414
import os
15-
import pkg_resources
15+
import importlib
1616
import re
1717
import sys
1818
import urllib.request, urllib.parse, urllib.error
@@ -262,7 +262,7 @@ def map_int(data_list):
262262

263263
if not req.specs:
264264
return
265-
mod_ver = pkg_resources.get_distribution(req.name).version
265+
mod_ver = importlib.metadata.version(req.name)
266266
mod_ver = map_int(mod_ver.split('.'))
267267
try:
268268
for spec in req.specs:
@@ -904,11 +904,13 @@ def test_versions():
904904
if dj_ver < (3, 0) or dj_ver >= (5, 0):
905905
errors.append('This version of Askbot supports django 3.x - 4.x ' + upgrade_msg)
906906
elif py_ver[:3] < (3, 6, 0):
907-
errors.append('Askbot requires Python 3.6 - 3.10')
908-
elif py_ver[:3] >= (3, 12, 0):
909-
errors.append("""Askbot was not tested with Python > 3.11.x
910-
Try adding ASKBOT_SELF_TEST = False to the settings.py
911-
to test if your version of Python works and please let us know.""")
907+
errors.append('Askbot requires Python 3.6 - 3.12')
908+
elif py_ver[:3] >= (3, 13, 0):
909+
errors.append(
910+
'Askbot was not tested with Python > 3.12.x\n'
911+
'Try adding ASKBOT_SELF_TEST = False to the settings.py\n'
912+
'to test if your version of Python works and please let us know.'
913+
)
912914

913915
print_errors(errors)
914916

askbot/tests/test_management_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_askbot_add_user(self):
223223
subs = models.EmailFeedSetting.objects.filter(
224224
subscriber = user,
225225
)
226-
self.assertEquals(subs.count(), 6)
226+
self.assertEqual(subs.count(), 6)
227227
#try to log in
228228
user = auth.authenticate(username=username, password=password)
229229
self.assertTrue(user is not None)

askbot/utils/url_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""utilities to work with the urls"""
2-
import imp
2+
import importlib
33
import sys
44
import urllib.parse
55
from django.urls import reverse, re_path
@@ -12,7 +12,7 @@ def reload_urlconf():
1212
clear_url_caches()
1313
urlconf = django_settings.ROOT_URLCONF
1414
if urlconf in sys.modules:
15-
imp.reload(sys.modules[urlconf])
15+
importlib.reload(sys.modules[urlconf])
1616

1717
def reverse_i18n(lang, *args, **kwargs):
1818
"""reverses url in requested language"""

askbot_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Jinja2>=2.10,<3.1
44
akismet==1.0.1
55
beautifulsoup4<=4.7.1
66
bleach==5.0.1
7-
celery==5.2.7
7+
celery==5.3.0
88
django-appconf==1.0.5
99
django-avatar>=7.0
1010
django-compressor>=3.0,<=4.4

0 commit comments

Comments
 (0)