From d8d4de43cbf0dbf11e2d9aad8adbd75921b48109 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 28 Jan 2018 10:33:25 -0800 Subject: [PATCH] Drop support for Django < 1.11 and remove workarounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per Django's recommendation, as django-silk supports 2.0, it should drop support for Django < 1.11 to ease maintenance and compatibility across Django versions. So long as no deprecation warnings are produced, django-silk should remain forward compatible with the next Django version. For more details, see the Django docs: https://docs.djangoproject.com/en/2.0/releases/2.0/#third-party-library-support-for-older-version-of-django > Third-party library support for older version of Django > > Following the release of Django 2.0, we suggest that third-party app authors > drop support for all versions of Django prior to 1.11. At that time, you > should be able to run your package’s tests using python -Wd so that > deprecation warnings do appear. After making the deprecation warning fixes, > your app should be compatible with Django 2.0. Those wishing to continue using an older Django can pin the version django-silk. Should significantly reduce testing resources as the test matrix is much smaller. --- .travis.yml | 9 ------- README.md | 13 ++-------- docs/index.rst | 4 +-- docs/quickstart.rst | 9 ------- project/example_app/admin.py | 7 +---- project/project/settings.py | 30 +++++++--------------- project/tests/test_config_auth.py | 7 +---- project/tests/test_config_max_body_size.py | 7 +---- project/tests/test_end_points.py | 7 +---- project/tests/test_lib/mock_suite.py | 7 +---- project/tests/test_silky_middleware.py | 7 +---- project/tests/test_view_sql_detail.py | 7 +---- requirements.txt | 4 +-- setup.py | 6 ++++- silk/middleware.py | 16 ++---------- silk/model_factory.py | 7 +---- silk/profiling/profiler.py | 3 --- silk/templatetags/silk_nav.py | 7 +---- silk/views/profiling.py | 5 +--- 19 files changed, 32 insertions(+), 130 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7ee7ecf..b6d25437 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,19 +5,10 @@ python: - '3.5' - '3.6' env: -- DJANGO="Django>=1.8.0,<1.9.0" DB=postgresql DB_NAME=travis_ci_test -- DJANGO="Django>=1.9.0,<1.10.0" DB=postgresql DB_NAME=travis_ci_test -- DJANGO="Django>=1.10.0,<1.11.0" DB=postgresql DB_NAME=travis_ci_test - DJANGO="Django>=1.11.0,<2.0" DB=postgresql DB_NAME=travis_ci_test - DJANGO="Django>=2.0,<2.1.0" DB=postgresql DB_NAME=travis_ci_test -- DJANGO="Django>=1.8.0,<1.9.0" DB=sqlite3 DB_NAME=db.sqlite3 -- DJANGO="Django>=1.9.0,<1.10.0" DB=sqlite3 DB_NAME=db.sqlite3 -- DJANGO="Django>=1.10.0,<1.11.0" DB=sqlite3 DB_NAME=db.sqlite3 - DJANGO="Django>=1.11.0,<2.0" DB=sqlite3 DB_NAME=db.sqlite3 - DJANGO="Django>=2.0,<2.1.0" DB=sqlite3 DB_NAME=db.sqlite3 -- DJANGO="Django>=1.8.0,<1.9.0" DB=mysql DB_NAME=mysql_db -- DJANGO="Django>=1.9.0,<1.10.0" DB=mysql DB_NAME=mysql_db -- DJANGO="Django>=1.10.0,<1.11.0" DB=mysql DB_NAME=mysql_db - DJANGO="Django>=1.11.0,<2.0" DB=mysql DB_NAME=mysql_db - DJANGO="Django>=2.0,<2.1.0" DB=mysql DB_NAME=mysql_db matrix: diff --git a/README.md b/README.md index f3b92bb7..65eedd84 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Silk is a live profiling and inspection tool for the Django framework. Silk inte Silk has been tested with: -* Django: 1.8, 1.9, 1.10, 1.11, 2.0 -* Python: 2.7, 3.3, 3.4, 3.5, 3.6 +* Django: 1.11, 2.0 +* Python: 2.7, 3.4, 3.5, 3.6 ## Installation @@ -47,21 +47,12 @@ pip install django-silk In `settings.py` add the following: ```python -# Django >= 1.10 MIDDLEWARE = [ ... 'silk.middleware.SilkyMiddleware', ... ] -# Django <= 1.9 -MIDDLEWARE_CLASSES = ( - ... - 'silk.middleware.SilkyMiddleware', - ... -) - -# All versions of django INSTALLED_APPS = ( ... 'silk' diff --git a/docs/index.rst b/docs/index.rst index be5b62c9..fac88b2a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -57,5 +57,5 @@ Features Requirements ------------ -* Django: 1.8, 1.9, 1.10, 1.11, 2.0 -* Python: 2.7, 3.3, 3.4, 3.5, 3.6 +* Django: 1.11, 2.0 +* Python: 2.7, 3.4, 3.5, 3.6 diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 6d1eb7c0..1f1fa13b 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -13,21 +13,12 @@ Add the following to your ``settings.py``: .. code-block:: python - # Django >= 1.10 MIDDLEWARE = [ ... 'silk.middleware.SilkyMiddleware', ... ] - # Django <= 1.9 - MIDDLEWARE_CLASSES = ( - ... - 'silk.middleware.SilkyMiddleware', - ... - ) - - # All versions of Django INSTALLED_APPS = ( ... 'silk' diff --git a/project/example_app/admin.py b/project/example_app/admin.py index f7c96c04..bc9f1322 100644 --- a/project/example_app/admin.py +++ b/project/example_app/admin.py @@ -1,10 +1,5 @@ from django.contrib import admin -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse from .models import Blind diff --git a/project/project/settings.py b/project/project/settings.py index 7034512a..f67716fb 100644 --- a/project/project/settings.py +++ b/project/project/settings.py @@ -1,4 +1,3 @@ -import django import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -23,26 +22,15 @@ ROOT_URLCONF = 'project.urls' -if django.VERSION >= (1, 10): - MIDDLEWARE = [ - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'silk.middleware.SilkyMiddleware' - ] -else: - MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'silk.middleware.SilkyMiddleware' - ) +MIDDLEWARE = [ + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'silk.middleware.SilkyMiddleware' +] WSGI_APPLICATION = 'wsgi.application' diff --git a/project/tests/test_config_auth.py b/project/tests/test_config_auth.py index 47d8215c..2f6801e4 100644 --- a/project/tests/test_config_auth.py +++ b/project/tests/test_config_auth.py @@ -1,10 +1,5 @@ from django.contrib.auth.models import User -try: - # Django >= 1.10 - from django.urls import reverse, NoReverseMatch -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse, NoReverseMatch +from django.urls import reverse, NoReverseMatch from django.test import TestCase from silk.config import SilkyConfig, default_permissions diff --git a/project/tests/test_config_max_body_size.py b/project/tests/test_config_max_body_size.py index e4264737..2ba1a2df 100644 --- a/project/tests/test_config_max_body_size.py +++ b/project/tests/test_config_max_body_size.py @@ -1,9 +1,4 @@ -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse from django.test import TestCase from mock import Mock from silk.model_factory import RequestModelFactory, ResponseModelFactory diff --git a/project/tests/test_end_points.py b/project/tests/test_end_points.py index 3e7f06b3..a386bbdd 100644 --- a/project/tests/test_end_points.py +++ b/project/tests/test_end_points.py @@ -1,10 +1,5 @@ import random -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse from django.db.models import Count from django.test import TestCase diff --git a/project/tests/test_lib/mock_suite.py b/project/tests/test_lib/mock_suite.py index 18924fae..7db952c5 100644 --- a/project/tests/test_lib/mock_suite.py +++ b/project/tests/test_lib/mock_suite.py @@ -5,7 +5,6 @@ import random import traceback -import django from django.core import management from django.utils import timezone @@ -101,11 +100,7 @@ def mock_sql_queries(self, request=None, profile=None, n=1, as_dict=False): for q in queries: profile['queries'].append(q) else: - if django.VERSION >= (1, 9): - profile.queries.set(queries) - else: - profile.queries = queries - profile.save() + profile.queries.set(queries) return queries def mock_profile(self, request=None): diff --git a/project/tests/test_silky_middleware.py b/project/tests/test_silky_middleware.py index 8dc150c1..ded33fb3 100644 --- a/project/tests/test_silky_middleware.py +++ b/project/tests/test_silky_middleware.py @@ -1,9 +1,4 @@ -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse from django.test import TestCase from mock import patch, Mock diff --git a/project/tests/test_view_sql_detail.py b/project/tests/test_view_sql_detail.py index 795efc47..85f696f6 100644 --- a/project/tests/test_view_sql_detail.py +++ b/project/tests/test_view_sql_detail.py @@ -1,12 +1,7 @@ import os import random -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse from django.test import TestCase from silk.config import SilkyConfig from silk.middleware import silky_reverse diff --git a/requirements.txt b/requirements.txt index f55bb74d..293854e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ autopep8>=1.2.1 pytz>2014.2 mock>=1.0.1 Pillow>=3.2 -django>=1.8 +Django>=1.11 freezegun>=0.3 factory-boy>=2.8.1 -gprof2dot>=2016.10.13,<2017.09.19 \ No newline at end of file +gprof2dot>=2016.10.13,<2017.09.19 diff --git a/setup.py b/setup.py index 33e4cb5b..45b27e00 100644 --- a/setup.py +++ b/setup.py @@ -33,10 +33,14 @@ def read_md(f): 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', + 'Framework :: Django :: 1.11', + 'Framework :: Django :: 2.0', 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', @@ -44,7 +48,7 @@ def read_md(f): 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ], install_requires=[ - 'Django', + 'Django>=1.11', 'Pygments', 'python-dateutil', 'requests', diff --git a/silk/middleware.py b/silk/middleware.py index 82d367ae..505d91bc 100644 --- a/silk/middleware.py +++ b/silk/middleware.py @@ -2,15 +2,10 @@ import random from django.db import transaction, DatabaseError -try: - # Django >= 1.10 - from django.urls import reverse, NoReverseMatch -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse, NoReverseMatch - +from django.urls import reverse, NoReverseMatch from django.db.models.sql.compiler import SQLCompiler from django.utils import timezone +from django.utils.deprecation import MiddlewareMixin from silk.collector import DataCollector @@ -20,13 +15,6 @@ from silk.profiling.profiler import silk_meta_profiler from silk.sql import execute_sql -try: - from django.utils.deprecation import MiddlewareMixin -except ImportError: # Django < 1.10 - # Works perfectly for everyone using MIDDLEWARE_CLASSES - MiddlewareMixin = object - - Logger = logging.getLogger('silk.middleware') diff --git a/silk/model_factory.py b/silk/model_factory.py index c0afe693..184a538e 100644 --- a/silk/model_factory.py +++ b/silk/model_factory.py @@ -6,12 +6,7 @@ from uuid import UUID from django.utils.encoding import force_text -try: - # Django >= 1.10 - from django.urls import resolve, Resolver404 -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import resolve, Resolver404 +from django.urls import resolve, Resolver404 from silk import models from silk.collector import DataCollector diff --git a/silk/profiling/profiler.py b/silk/profiling/profiler.py index fbd4f3b2..6840ce4d 100644 --- a/silk/profiling/profiler.py +++ b/silk/profiling/profiler.py @@ -3,7 +3,6 @@ import time import traceback -import django from django.conf import settings from django.utils import timezone @@ -126,8 +125,6 @@ def __exit__(self, exc_type, exc_val, exc_tb): def _silk_installed(self): app_installed = 'silk' in settings.INSTALLED_APPS middlewares = getattr(settings, 'MIDDLEWARE', []) - if django.VERSION[0] < 2 and not middlewares: - middlewares = getattr(settings, 'MIDDLEWARE_CLASSES', []) if not middlewares: middlewares = [] middleware_installed = 'silk.middleware.SilkyMiddleware' in middlewares diff --git a/silk/templatetags/silk_nav.py b/silk/templatetags/silk_nav.py index c4aa6738..59cd088e 100644 --- a/silk/templatetags/silk_nav.py +++ b/silk/templatetags/silk_nav.py @@ -1,10 +1,5 @@ from django import template -try: - # Django >= 1.10 - from django.urls import reverse -except ImportError: - # Django < 2.0 - from django.core.urlresolvers import reverse +from django.urls import reverse register = template.Library() diff --git a/silk/views/profiling.py b/silk/views/profiling.py index beb95e1b..e23f1658 100644 --- a/silk/views/profiling.py +++ b/silk/views/profiling.py @@ -1,7 +1,4 @@ -try: - from django.template.context_processors import csrf -except ImportError: - from django.core.context_processors import csrf +from django.template.context_processors import csrf from django.db.models import Count, Sum from django.shortcuts import render from django.utils.decorators import method_decorator