<commit_before># Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt

"""The Django template coverage plugin."""

from __future__ import print_function

import os.path
import re

import coverage.plugin
import django
import django.template
from django.template.base import Lexer, NodeList, Template, TextNode
from django.template.defaulttags import VerbatimNode
from django.templatetags.i18n import BlockTranslateNode
from six.moves import range

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."""
    pass


# For debugging the plugin itself.
SHOW_PARSING = False
SHOW_TRACING = False


def check_debug():
    """Check that Django's template debugging is enabled.

    Django's built-in "template debugging" records information the plugin needs
    to do its work.  Check that the setting is correct, and raise an exception
    if it is not.

    Returns True if the debug check was performed, False otherwise
    """
    from django.conf import settings

    if not settings.configured:
        return False

    # I _think_ this check is all that's needed and the 3 "hasattr" checks
    # below can be removed, but it's not clear how to verify that
    from django.apps import apps
    if not apps.ready:
        return False

    # django.template.backends.django gets loaded lazily, so return false
    # until they've been loaded
    if not hasattr(django.template, "backends"):
        return False
    if not hasattr(django.template.backends, "django"):
        return False
    if not hasattr(django.template.backends.django, "DjangoTemplates"):
        raise DjangoTemplatePluginException("Can't use non-Django templates.")

    for engine in django.template.engines.all():
        if not isinstance(engine, django.template.backends.django.DjangoTemplates):
            raise DjangoTemplatePluginException(
                "Can't use non-Django templates."
            )
        if not engine.engine.debug:
            raise DjangoTemplatePluginException(
                "Template debugging must be enabled in settings."
            )

    return True<commit_msg>Fix tags missing when imported during collection<commit_after># Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt

"""The Django template coverage plugin."""

from __future__ import print_function

import os.path
import re

import coverage.plugin
import django
import django.template
from django.template.base import Lexer, NodeList, Template, TextNode
from django.template.defaulttags import VerbatimNode
from django.templatetags.i18n import BlockTranslateNode
from six.moves import range

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."""
    pass


# For debugging the plugin itself.
SHOW_PARSING = False
SHOW_TRACING = False


def check_debug():
    """Check that Django's template debugging is enabled.

    Django's built-in "template debugging" records information the plugin needs
    to do its work.  Check that the setting is correct, and raise an exception
    if it is not.

    Returns True if the debug check was performed, False otherwise
    """
    from django.conf import settings

    if not settings.configured:
        return False

    # I _think_ this check is all that's needed and the 3 "hasattr" checks
    # below can be removed, but it's not clear how to verify that
    from django.apps import apps
    if not apps.ready:
        return False

    # django.template.backends.django gets loaded lazily, so return false
    # until they've been loaded
    if not hasattr(django.template, "backends"):
        return False
    if not hasattr(django.template.backends, "django"):
        return False
    if not hasattr(django.template.backends.django, "DjangoTemplates"):
        raise DjangoTemplatePluginException("Can't use non-Django templates.")
    if not django.template.engines._engines:
        return False

    for engine in django.template.engines.all():
        if not isinstance(engine, django.template.backends.django.DjangoTemplates):
            raise DjangoTemplatePluginException(
                "Can't use non-Django templates."
            )
        if not engine.engine.debug:
            raise DjangoTemplatePluginException(
                "Template debugging must be enabled in settings."
            )

    return True
{'fraction_non_alphanumeric': 0.06870638754696726, 'fraction_numerical': 0.0025049203793165147, 'mean_word_length': 3.0244780417566597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4989189', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1476, 'n_words': 518}