<commit_before>import textwrap
import cfnlint.core
from yaml.scanner import ScannerError
from taskcat.colored_console import PrintMsg
import yaml
import re


class Lint(object):

    _code_regex = re.compile("^([WER][0-9]*:)")

    def __init__(self, config, path=""):
        """
        Lints templates using cfn_python_lint. Uses config file to define regions and templates to test. Recurses into
        child templates, excluding submodules.

        :param config: path to tascat ci config file
        """
        self._config = yaml.safe_load(open(config))
        self._rules = cfnlint.core.get_rules([], [], [])
        self._path = path
        self.lints = self._lint()

    def _get_template_path(self, test):
        if self._path:
            return '%s/templates/%s' % (self._path, self._config['tests'][test]['template_file'])
        else:
            return 'templates/%s' % (self._config['tests'][test]['template_file'])

    def _get_test_regions(self, test):
        if 'regions' in self._config['tests'][test].keys():
            return self._config['tests'][test]['regions']
        else:
            return self._config['global']['regions']

    @staticmethod
    def _parse_template(template_path, quiet=False):
        try:
            return cfnlint.decode.cfn_yaml.load(template_path)
        except ScannerError as e:
            if not quiet:
                print(PrintMsg.ERROR + 'Linter failed to load template %s "%s" line %s, column %s' % (<commit_msg>only test against regions supported by cfn-python-lint<commit_after>import textwrap
import cfnlint.core
from yaml.scanner import ScannerError
from taskcat.colored_console import PrintMsg
import yaml
import re


class Lint(object):

    _code_regex = re.compile("^([WER][0-9]*:)")

    def __init__(self, config, path=""):
        """
        Lints templates using cfn_python_lint. Uses config file to define regions and templates to test. Recurses into
        child templates, excluding submodules.

        :param config: path to tascat ci config file
        """
        self._config = yaml.safe_load(open(config))
        self._rules = cfnlint.core.get_rules([], [], [])
        self._path = path
        self.lints = self._lint()

    def _get_template_path(self, test):
        if self._path:
            return '%s/templates/%s' % (self._path, self._config['tests'][test]['template_file'])
        else:
            return 'templates/%s' % (self._config['tests'][test]['template_file'])

    def _get_test_regions(self, test):
        if 'regions' in self._config['tests'][test].keys():
            return self._filter_unsupported_regions(self._config['tests'][test]['regions'])
        else:
            return self._filter_unsupported_regions(self._config['global']['regions'])

    def _filter_unsupported_regions(self, regions):
        lint_regions = set(cfnlint.core.REGIONS)
        if set(regions).issubset(lint_regions):
            return regions
        supported = set(regions).intersection(lint_regions)
        unsupported = set(regions).difference(lint_regions)
        print(PrintMsg.ERROR + "The following regions are not supported by cfn-python-lint and will not be linted %s" % unsupported)
        return list(supported)

    @staticmethod
    def _parse_template(template_path, quiet=False):
        try:
            return cfnlint.decode.cfn_yaml.load(template_path)
        except ScannerError as e:
            if not quiet:
                print(PrintMsg.ERROR + 'Linter failed to load template %s "%s" line %s, column %s' % (
{'fraction_non_alphanumeric': 0.11816130851663846, 'fraction_numerical': 0.0011280315848843769, 'mean_word_length': 2.8978021978021977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6302028', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1011, 'n_words': 259}