From 1aad9e79962db0eb439b7dac8dbdf1617a130602 Mon Sep 17 00:00:00 2001 From: Pascal F Date: Sun, 7 Jan 2024 08:41:24 +0100 Subject: [PATCH] Update Django and Python supported versions --- .github/workflows/ci.yml | 6 +++--- CHANGELOG.rst | 8 ++++++++ docs/conf.py | 11 +++++------ sendsms/__init__.py | 1 - sendsms/api.py | 11 ++--------- sendsms/backends/__init__.py | 1 - sendsms/backends/base.py | 3 --- sendsms/backends/bulksms.py | 2 -- sendsms/backends/celery.py | 1 + sendsms/backends/console.py | 4 ++-- sendsms/backends/dummy.py | 1 - sendsms/backends/esendex.py | 1 - sendsms/backends/locmem.py | 1 - sendsms/backends/nexmo.py | 1 - sendsms/backends/ovhsms.py | 6 +----- sendsms/backends/rq.py | 1 + sendsms/backends/smsglobal.py | 1 + sendsms/backends/smspubli.py | 2 -- sendsms/backends/twiliorest.py | 3 +-- sendsms/message.py | 1 - sendsms/signals.py | 1 - sendsms/utils.py | 3 +-- setup.py | 11 +++++++++++ test.py | 25 ++++++++----------------- tox.ini | 22 +++++++++++++--------- 25 files changed, 58 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b05058..20d0088 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,15 +15,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 02be0a9..ccc70a1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ CHANGELOG ========= +Unreleased +------------------ + +* Add support for django 4.1, 4.2, and django 5.0 +* Add support for Python 3.10, 3.11, and 3.12 +* Remove support for django 2.2 and 3.0 +* Remove support for Python 3.6, 3.7 + 0.5.0 (2021-12-27) ------------------ diff --git a/docs/conf.py b/docs/conf.py index bf0d30f..14cc403 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # django-sendsms documentation build configuration file, created by # sphinx-quickstart on Sun Aug 21 17:29:36 2011. @@ -47,8 +46,8 @@ master_doc = "index" # General information about the project. -project = u"django-sendsms" -copyright = u"2011, Stefan Foulis" +project = "django-sendsms" +copyright = "2011, Stefan Foulis" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -188,8 +187,8 @@ ( "index", "django-sendsms.tex", - u"django-sendsms Documentation", - u"Stefan Foulis", + "django-sendsms Documentation", + "Stefan Foulis", "manual", ) ] @@ -223,5 +222,5 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ("index", "django-sendsms", u"django-sendsms Documentation", [u"Stefan Foulis"], 1) + ("index", "django-sendsms", "django-sendsms Documentation", ["Stefan Foulis"], 1) ] diff --git a/sendsms/__init__.py b/sendsms/__init__.py index f41e6ab..b1390b0 100644 --- a/sendsms/__init__.py +++ b/sendsms/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- __version_info__ = { "major": 0, "minor": 5, diff --git a/sendsms/api.py b/sendsms/api.py index 91ff105..9013c53 100644 --- a/sendsms/api.py +++ b/sendsms/api.py @@ -1,13 +1,6 @@ -# -*- coding: utf-8 -*- from django.conf import settings from django.core.exceptions import ImproperlyConfigured - -try: - # Django versions >= 1.9 - from django.utils.module_loading import import_module -except ImportError: - # Django versions < 1.9 - from django.utils.importlib import import_module +from django.utils.module_loading import import_module def send_sms( @@ -75,7 +68,7 @@ def get_connection(path=None, fail_silently=False, **kwargs): mod = import_module(mod_name) except AttributeError as e: raise ImproperlyConfigured( - u'Error importing sms backend module %s: "%s"' % (mod_name, e) + 'Error importing sms backend module %s: "%s"' % (mod_name, e) ) try: diff --git a/sendsms/backends/__init__.py b/sendsms/backends/__init__.py index 40a96af..e69de29 100644 --- a/sendsms/backends/__init__.py +++ b/sendsms/backends/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/sendsms/backends/base.py b/sendsms/backends/base.py index 2972210..02f605a 100644 --- a/sendsms/backends/base.py +++ b/sendsms/backends/base.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - class BaseSmsBackend(object): """ Base class for sms backend implementations. diff --git a/sendsms/backends/bulksms.py b/sendsms/backends/bulksms.py index a5431ca..6752c41 100644 --- a/sendsms/backends/bulksms.py +++ b/sendsms/backends/bulksms.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf import settings import requests diff --git a/sendsms/backends/celery.py b/sendsms/backends/celery.py index c36bc96..3f54bdf 100644 --- a/sendsms/backends/celery.py +++ b/sendsms/backends/celery.py @@ -18,6 +18,7 @@ """ + from __future__ import absolute_import from django.conf import settings diff --git a/sendsms/backends/console.py b/sendsms/backends/console.py index 3977541..25b9d5d 100644 --- a/sendsms/backends/console.py +++ b/sendsms/backends/console.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- """ SMS backend that writes messages to console instead of sending them. This is a total ripoff of django.core.mail.backends.console """ + import sys import threading @@ -43,7 +43,7 @@ def send_messages(self, messages): def render_message(message): - return u"""from: %(from)s\nto: %(to)s\nflash: %(flash)s\n%(body)s""" % { + return """from: %(from)s\nto: %(to)s\nflash: %(flash)s\n%(body)s""" % { "from": message.from_phone, "to": ", ".join(message.to), "flash": message.flash, diff --git a/sendsms/backends/dummy.py b/sendsms/backends/dummy.py index c5eeb12..e3a0030 100644 --- a/sendsms/backends/dummy.py +++ b/sendsms/backends/dummy.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Dummy sms backend that does nothing. """ diff --git a/sendsms/backends/esendex.py b/sendsms/backends/esendex.py index 791891d..d4fbee5 100644 --- a/sendsms/backends/esendex.py +++ b/sendsms/backends/esendex.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Esendex sms gateway backend. (http://www.esendex.es/) diff --git a/sendsms/backends/locmem.py b/sendsms/backends/locmem.py index fda4191..fe6e2cf 100644 --- a/sendsms/backends/locmem.py +++ b/sendsms/backends/locmem.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Backend for test environment. """ diff --git a/sendsms/backends/nexmo.py b/sendsms/backends/nexmo.py index c6766f8..0aea6e1 100644 --- a/sendsms/backends/nexmo.py +++ b/sendsms/backends/nexmo.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ nexmo sms gateway backend. (https://www.nexmo.com/) diff --git a/sendsms/backends/ovhsms.py b/sendsms/backends/ovhsms.py index d4d8770..0399ec0 100644 --- a/sendsms/backends/ovhsms.py +++ b/sendsms/backends/ovhsms.py @@ -1,9 +1,6 @@ -try: - from urllib.parse import urlencode -except ImportError: - from urllib import urlencode # Python2 import json import logging +from urllib.parse import urlencode from django.conf import settings @@ -38,7 +35,6 @@ def _send_via_ovh( tag=None, # string of max 20 characters deferred=None, ): # eg. format "125025112017" for sending on 28/11/2017 at 12h50 - # late lookup, else tests won't work... OVH_API_URL = getattr( settings, "OVH_API_URL", "https://www.ovh.com/cgi-bin/sms/http2sms.cgi" diff --git a/sendsms/backends/rq.py b/sendsms/backends/rq.py index cb2836a..9ade7c0 100644 --- a/sendsms/backends/rq.py +++ b/sendsms/backends/rq.py @@ -16,6 +16,7 @@ """ + from django.conf import settings from django.core.exceptions import ImproperlyConfigured diff --git a/sendsms/backends/smsglobal.py b/sendsms/backends/smsglobal.py index 00ba347..f3f6592 100644 --- a/sendsms/backends/smsglobal.py +++ b/sendsms/backends/smsglobal.py @@ -1,4 +1,5 @@ """SMS Global sms backend class.""" + import logging import math import re diff --git a/sendsms/backends/smspubli.py b/sendsms/backends/smspubli.py index cd67a1b..a7208b8 100644 --- a/sendsms/backends/smspubli.py +++ b/sendsms/backends/smspubli.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ SmsPubli sms gateway backend. (http://www.smspubli.com) diff --git a/sendsms/backends/twiliorest.py b/sendsms/backends/twiliorest.py index 3c618f9..a17a07d 100644 --- a/sendsms/backends/twiliorest.py +++ b/sendsms/backends/twiliorest.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- - """ this backend requires the twilio python library: http://pypi.python.org/pypi/twilio/ """ + from django.conf import settings import twilio diff --git a/sendsms/message.py b/sendsms/message.py index d4ff0a9..f8e2236 100644 --- a/sendsms/message.py +++ b/sendsms/message.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.conf import settings from sendsms.api import get_connection diff --git a/sendsms/signals.py b/sendsms/signals.py index 52f2163..91b9182 100644 --- a/sendsms/signals.py +++ b/sendsms/signals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.dispatch import Signal sms_post_send = Signal() # providing_args=["from_phone", "to", "body"] diff --git a/sendsms/utils.py b/sendsms/utils.py index 58a4dd3..7c2171c 100644 --- a/sendsms/utils.py +++ b/sendsms/utils.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- try: from importlib import import_module except ImportError: - from django.utils.importlib import import_module + from django.utils.module_loading import import_module def load_object(import_path): diff --git a/setup.py b/setup.py index 58205eb..f527bd3 100644 --- a/setup.py +++ b/setup.py @@ -32,10 +32,21 @@ classifiers=[ "Development Status :: 5 - Production/Stable", "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.0", + "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Internet :: WWW/HTTP", ], ) diff --git a/test.py b/test.py index e4cba8c..a5702ae 100644 --- a/test.py +++ b/test.py @@ -1,22 +1,16 @@ -# -*- coding: utf-8 -*- - -try: - from unittest import mock -except: - import mock - -try: - from importlib import reload -except: - pass - import unittest +from unittest import mock from django.conf import settings from django.test import SimpleTestCase import sendsms +try: + from importlib import reload +except: + pass + if not settings.configured: settings.configure( SENDSMS_BACKEND="sendsms.backends.locmem.SmsBackend", @@ -40,8 +34,8 @@ def test_send_simple_sms(self): self.assertEqual(len(sendsms.outbox), 1) def test_send_esendex_sandbox(self): - from sendsms.message import SmsMessage from sendsms.api import get_connection + from sendsms.message import SmsMessage connection = get_connection("sendsms.backends.esendex.SmsBackend") obj = SmsMessage( @@ -159,7 +153,6 @@ def test_should_call_proper_url(self, _call_url_mock): OVH_API_FROM="mysender", OVH_API_NO_STOP=False, ): - message = SmsMessage( body="Hello!", from_phone="29290", # overrides OVH_API_FROM @@ -182,7 +175,6 @@ def test_should_call_proper_url(self, _call_url_mock): OVH_API_PASSWORD="mypwd", OVH_API_FROM="mysender", ): - message = SmsMessage( body="Wêlcome à vous\nHenrï & Jack!\r\n", from_phone="thierry", # overrides OVH_API_FROM @@ -206,10 +198,9 @@ def test_should_properly_handle_errors(self): OVH_API_PASSWORD="mypwd", OVH_API_FROM="mysender", ): - from sendsms.api import send_sms - with self.assertRaisesRegex(RuntimeError, "Invalid smsAccount"): + with self.assertRaises(RuntimeError): send_sms(body="I can hàz txt", from_phone=None, to=["+33632020000"]) res = send_sms( diff --git a/tox.ini b/tox.ini index b40fa4f..81dbffc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,20 @@ [tox] envlist = - py{36,37}-dj{22} - py{37,38}-dj{30} - py{37,38,39}-dj{32} - py{38,39}-dj{40} + py{38,39}-dj32 + py{38,39,310}-dj40 + py{38,39,310,311}-dj41 + py{38,39,310,311,312}-dj42 + py{310,311,312}-dj50 flake8 black [gh-actions] python = - 3.6: py36, black, flake8 - 3.7: py37, black, flake8 3.8: py38, black, flake8 3.9: py39, black, flake8 + 3.10: py310, black, flake8 + 3.11: py311, black, flake8 + 3.12: py312, black, flake8 [testenv] commands = @@ -21,10 +23,12 @@ commands = coverage report deps = coverage - dj22: Django~=2.2.0 - dj30: Django~=3.0.0 + setuptools dj32: Django~=3.2.0 - dj40: Django~=4.0rc1 + dj40: Django~=4.0.0 + dj41: Django~=4.1.0 + dj42: Django~=4.2.0 + dj50: Django~=5.0.0 [testenv:flake8] commands = flake8 sendsms setup.py