From 4a4df014b5e5a2a07e31614ad66a96e58ca1ff58 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 16 Aug 2018 00:06:01 -0300 Subject: [PATCH 1/2] Add support for Django 2.1 --- django_coverage_plugin/plugin.py | 36 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index fa2ad99..a8c6ed2 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -14,17 +14,35 @@ import django import django.template -from django.template.base import ( - Lexer, TextNode, NodeList, Template, - TOKEN_BLOCK, TOKEN_MAPPING, TOKEN_TEXT, TOKEN_VAR, -) +from django.template.base import Lexer, TextNode, NodeList, Template from django.templatetags.i18n import BlockTranslateNode + try: from django.template.defaulttags import VerbatimNode except ImportError: # Django 1.4 didn't have VerbatimNode VerbatimNode = None +try: + from django.template.base import TokenType + + def _token_name(token_type): + token_type.name.capitalize() + +except ImportError: + # Django <2.1 uses separate constants for token types + from django.template.base import ( + TOKEN_BLOCK, TOKEN_MAPPING, TOKEN_TEXT, TOKEN_VAR + ) + + class TokenType: + TEXT = TOKEN_TEXT + VAR = TOKEN_VAR + BLOCK = TOKEN_BLOCK + + def _token_name(token_type): + return TOKEN_MAPPING[token_type] + class DjangoTemplatePluginException(Exception): """Used for any errors from the plugin itself.""" @@ -298,12 +316,12 @@ def lines(self): if SHOW_PARSING: print( "%10s %2d: %r" % ( - TOKEN_MAPPING[token.token_type], + _token_name(token.token_type), token.lineno, token.contents, ) ) - if token.token_type == TOKEN_BLOCK: + if token.token_type == TokenType.BLOCK: if token.contents == "endcomment": comment = False continue @@ -311,7 +329,7 @@ def lines(self): if comment: continue - if token.token_type == TOKEN_BLOCK: + if token.token_type == TokenType.BLOCK: if token.contents.startswith("endblock"): inblock = False elif token.contents.startswith("block"): @@ -340,10 +358,10 @@ def lines(self): source_lines.add(token.lineno) - elif token.token_type == TOKEN_VAR: + elif token.token_type == TokenType.VAR: source_lines.add(token.lineno) - elif token.token_type == TOKEN_TEXT: + elif token.token_type == TokenType.TEXT: if extends and not inblock: continue # Text nodes often start with newlines, but we don't want to From 06454e5332b75d3d05f1fb5e28f193abec9bd674 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 16 Aug 2018 00:07:05 -0300 Subject: [PATCH 2/2] Add Django 2.1 to build matrix --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index a9ce46e..91d4e40 100644 --- a/tox.ini +++ b/tox.ini @@ -17,8 +17,9 @@ envlist = py27-django{18,19,110,111,111tip}, py34-django{18,19,110,111,111tip,20}, - py35-django{18,19,110,111,111tip,20,tip}, - py36-django{18,19,110,111,111tip,20,tip}, + py35-django{18,19,110,111,111tip,20,21,tip}, + py36-django{18,19,110,111,111tip,20,21,tip}, + py37-django{20,21,tip}, check,doc [testenv] @@ -30,6 +31,7 @@ deps = django111: Django >=1.11, <2.0 django111tip: https://github.com/django/django/archive/stable/1.11.x.tar.gz django20: Django>=2.0b1,<2.1 + django21: Django>=2.1, <2.2 djangotip: https://github.com/django/django/archive/master.tar.gz commands =