Skip to content

Commit dca4b51

Browse files
author
Pamela McA'Nulty
committed
Merge branch 'pm/support_dj11_and_dj20' into pm/insane_integration_test
# Conflicts: # .travis.yml
2 parents c172020 + c992231 commit dca4b51

File tree

12 files changed

+88
-50
lines changed

12 files changed

+88
-50
lines changed

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,5 @@ python:
55
- "3.4"
66
- "3.5"
77
- "3.6"
8-
env:
9-
- DJANGO="1.4"
10-
- DJANGO="1.5"
11-
- DJANGO="1.6"
12-
- DJANGO="1.7"
13-
- DJANGO="1.8"
14-
- DJANGO="1.9"
15-
- DJANGO="1.10"
16-
178
install: pip install tox-travis
189
script: tox

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ contributions by:
33

44
Jessamyn Smith
55
Simon Charette
6+
Pamela McA'Nulty

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,4 @@ kit:
2929
$(SDIST_CMD)
3030

3131
kit_upload:
32-
$(SDIST_CMD) upload
33-
34-
pypi:
35-
python setup.py register
32+
twine upload dist/*

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2015-2016 Ned Batchelder. All rights reserved.
1+
Copyright 2015-2017 Ned Batchelder. All rights reserved.
22

33
Except where noted otherwise, this software is licensed under the Apache
44
License, Version 2.0 (the "License"); you may not use this work except in

README.rst

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ Django Template Coverage.py Plugin
88
A `coverage.py`_ plugin to measure the coverage of Django templates.
99

1010
| |license| |versions| |djversions| |status|
11-
| |kit| |downloads|
11+
| |kit|
12+
13+
.. downloads badge seems to be broken... |downloads|
14+
15+
Supported Python versions are 2.7, 3.4, 3.5 and 3.6.
16+
17+
Supported Django versions are 1.4 through 1.10.
18+
19+
Supported coverage.py versions are 4.0 and higher.
1220

13-
Supported Python versions are 2.7, 3.4, and 3.5. Supported Django versions are
14-
1.4 through 1.9.
1521

1622
The plugin is pip installable::
1723

@@ -23,7 +29,7 @@ To run it, add this setting to your .coveragerc file::
2329
plugins =
2430
django_coverage_plugin
2531

26-
Then run your tests under coverage.py. It requires coverage.py 4.0 or later.
32+
Then run your tests under coverage.py.
2733

2834
You will see your templates listed in your coverage report along with your
2935
Python modules.
@@ -43,6 +49,8 @@ template files are included in the report.
4349
Caveats
4450
~~~~~~~
4551

52+
Support for Django versions 1.4 through 1.7 should be considered deprecated.
53+
4654
Files included by the ``{% ssi %}`` tag are not included in the coverage
4755
measurements.
4856

@@ -54,6 +62,30 @@ Changes
5462
~~~~~~~
5563

5664

65+
v1.4.1 --- 2017-01-25
66+
---------------------
67+
68+
Fixes `issue 32`_, which was the result of an initialization order problem.
69+
70+
.. _issue 32: https://github.com/nedbat/django_coverage_plugin/issues/32
71+
72+
73+
v1.4 --- 2017-01-16
74+
-------------------
75+
76+
Django 1.10.5 is now supported.
77+
78+
Checking settings configuration is deferred so that settings.py is included
79+
in coverage reporting. Fixes `issue 28`_.
80+
81+
Only the ``django.template.backends.django.DjangoTemplates`` template engine is
82+
supported, and it must be configured with ``['OPTIONS']['debug'] = True``.
83+
Fixes `issue 27`_.
84+
85+
.. _issue 28: https://github.com/nedbat/django_coverage_plugin/issues/28
86+
.. _issue 27: https://github.com/nedbat/django_coverage_plugin/issues/27
87+
88+
5789
v1.3.1 --- 2016-06-02
5890
---------------------
5991

@@ -140,7 +172,7 @@ To run the tests::
140172
.. |versions| image:: https://img.shields.io/pypi/pyversions/django_coverage_plugin.svg
141173
:target: https://pypi.python.org/pypi/django_coverage_plugin
142174
:alt: Python versions supported
143-
.. |djversions| image:: https://img.shields.io/badge/Django-1.4, 1.5, 1.6, 1.7, 1.8, 1.9-44b78b.svg
175+
.. |djversions| image:: https://img.shields.io/badge/Django-1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10-44b78b.svg
144176
:target: https://pypi.python.org/pypi/django_coverage_plugin
145177
:alt: Django versions supported
146178
.. |status| image:: https://img.shields.io/pypi/status/django_coverage_plugin.svg

django_coverage_plugin/plugin.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import django
1515
import django.template
16-
from django.core.exceptions import ImproperlyConfigured
1716
from django.template.base import (
1817
Lexer, TextNode, NodeList, Template,
1918
TOKEN_BLOCK, TOKEN_MAPPING, TOKEN_TEXT, TOKEN_VAR,
@@ -43,28 +42,34 @@ def check_debug():
4342
to do its work. Check that the setting is correct, and raise an exception
4443
if it is not.
4544
45+
Returns True if the debug check was performed, False otherwise
4646
"""
47-
# The settings for templates changed in Django 1.8 from TEMPLATE_DEBUG to
48-
# TEMPLATES[..]['debug']. Django 1.9 tolerated both forms, 1.10 insists on
49-
# the new form. Don't try to be version-specific here. If the new
50-
# settings exist, use them, otherwise use the old.
51-
5247
from django.conf import settings
5348

54-
try:
55-
templates = getattr(settings, 'TEMPLATES', [])
56-
except ImproperlyConfigured:
57-
# Maybe there are no settings at all. We are fine with this. Our
58-
# code will need settings, but if this program we're in runs without
59-
# settings, then it must be that it never uses templates, and our code
60-
# will never try to use the settings anyway.
61-
return
62-
63-
if templates:
64-
for template_settings in templates:
65-
if template_settings['BACKEND'] != 'django.template.backends.django.DjangoTemplates':
66-
raise DjangoTemplatePluginException("Can't use non-Django templates.")
67-
if not template_settings.get('OPTIONS', {}).get('debug', False):
49+
if not settings.configured:
50+
return False
51+
52+
if django.VERSION >= (1, 8):
53+
# Django 1.8+ handles both old and new-style settings and converts them
54+
# into template engines, so we don't need to depend on settings values
55+
# directly and can look at the resulting configured objects
56+
57+
# django.template.backends.django gets loaded lazily, so return false
58+
# until they've been loaded
59+
if not hasattr(django.template, "backends"):
60+
return False
61+
if not hasattr(django.template.backends, "django"):
62+
return False
63+
64+
if not hasattr(django.template.backends.django, "DjangoTemplates"):
65+
raise DjangoTemplatePluginException("Can't use non-Django templates.")
66+
67+
for engine in django.template.engines.all():
68+
if not isinstance(engine, django.template.backends.django.DjangoTemplates):
69+
raise DjangoTemplatePluginException(
70+
"Can't use non-Django templates."
71+
)
72+
if not engine.engine.debug:
6873
raise DjangoTemplatePluginException(
6974
"Template debugging must be enabled in settings."
7075
)
@@ -75,6 +80,8 @@ def check_debug():
7580
"Template debugging must be enabled in settings."
7681
)
7782

83+
return True
84+
7885

7986
if django.VERSION >= (1, 9):
8087
# Since we are grabbing at internal details, we have to adapt as they
@@ -151,8 +158,9 @@ def sys_info(self):
151158
def file_tracer(self, filename):
152159
if filename.startswith(self.django_template_dir):
153160
if not self.debug_checked:
154-
check_debug()
155-
self.debug_checked = True
161+
# Keep calling check_debug until it returns True, which it
162+
# will only do after settings have been configured
163+
self.debug_checked = check_debug()
156164

157165
return self
158166
return None

howto.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
- Update README.rst with latest changes
77
- Kits:
88
$ make kit
9-
$ make pypi
109
$ make kit_upload

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# To run tests, we just need tox.
22
tox >= 1.8
3+
twine

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Programming Language :: Python :: 2.7
1313
Programming Language :: Python :: 3.4
1414
Programming Language :: Python :: 3.5
15+
Programming Language :: Python :: 3.6
1516
Programming Language :: Python :: Implementation :: CPython
1617
Programming Language :: Python :: Implementation :: PyPy
1718
Topic :: Software Development :: Quality Assurance
@@ -21,7 +22,7 @@
2122

2223
setup(
2324
name='django_coverage_plugin',
24-
version='1.3.1',
25+
version='1.4.1',
2526
description='Django template coverage.py plugin',
2627
author='Ned Batchelder',
2728
author_email='[email protected]',

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def index(request):
1212
"""A bogus view to use in the urls below."""
1313
pass
1414

15+
1516
urlpatterns = [
1617
url(r'^home$', index, name='index'),
1718
]

0 commit comments

Comments
 (0)