Skip to content

Commit

Permalink
Drop support for Django < 1.11 and remove workarounds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jdufresne authored and avelis committed Jan 29, 2018
1 parent 4576482 commit fa1f542
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 130 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 1 addition & 6 deletions project/example_app/admin.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
30 changes: 9 additions & 21 deletions project/project/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
Expand All @@ -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'

Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_config_auth.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_config_max_body_size.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_end_points.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_lib/mock_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import random
import traceback

import django
from django.core import management
from django.utils import timezone

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_silky_middleware.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 1 addition & 6 deletions project/tests/test_view_sql_detail.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
gprof2dot>=2016.10.13,<2017.09.19
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ 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',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
install_requires=[
'Django',
'Django>=1.11',
'Pygments',
'python-dateutil',
'requests',
Expand Down
16 changes: 2 additions & 14 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')


Expand Down
7 changes: 1 addition & 6 deletions silk/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions silk/profiling/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
import traceback

import django
from django.conf import settings
from django.utils import timezone

Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions silk/templatetags/silk_nav.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
5 changes: 1 addition & 4 deletions silk/views/profiling.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fa1f542

Please sign in to comment.