How to use the pycodestyle.BaseReport function in pycodestyle

To help you get started, we’ve selected a few pycodestyle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / version-control-tools / pylib / pycodestyle / testsuite / support.py View on Github external
def selftest(options):
    """
    Test all check functions with test cases in docstrings.
    """
    count_failed = count_all = 0
    report = BaseReport(options)
    counters = report.counters
    checks = options.physical_checks + options.logical_checks
    for name, check, argument_names in checks:
        for line in check.__doc__.splitlines():
            line = line.lstrip()
            match = SELFTEST_REGEX.match(line)
            if match is None:
                continue
            code, source = match.groups()
            lines = [part.replace(r'\t', '\t') + '\n'
                     for part in source.split(r'\n')]
            checker = Checker(lines=lines, options=options, report=report)
            checker.check_all()
            error = None
            if code == 'Okay':
                if len(counters) > len(options.benchmark_keys):
github PyCQA / pycodestyle / testsuite / support.py View on Github external
def selftest(options):
    """
    Test all check functions with test cases in docstrings.
    """
    count_failed = count_all = 0
    report = BaseReport(options)
    counters = report.counters
    checks = options.physical_checks + options.logical_checks
    for name, check, argument_names in checks:
        for line in check.__doc__.splitlines():
            line = line.lstrip()
            match = SELFTEST_REGEX.match(line)
            if match is None:
                continue
            code, source = match.groups()
            lines = [part.replace(r'\t', '\t') + '\n'
                     for part in source.split(r'\n')]
            checker = Checker(lines=lines, options=options, report=report)
            checker.check_all()
            error = None
            if code == 'Okay':
                if len(counters) > len(options.benchmark_keys):
github mozilla / version-control-tools / pylib / pycodestyle / testsuite / test_api.py View on Github external
def test_styleguide_init_report(self):
        style = pycodestyle.StyleGuide(paths=[E11])

        standard_report = pycodestyle.StandardReport

        self.assertEqual(style.options.reporter, standard_report)
        self.assertEqual(type(style.options.report), standard_report)

        class MinorityReport(pycodestyle.BaseReport):
            pass

        report = style.init_report(MinorityReport)
        self.assertEqual(style.options.report, report)
        self.assertEqual(type(report), MinorityReport)

        style = pycodestyle.StyleGuide(paths=[E11], reporter=MinorityReport)
        self.assertEqual(type(style.options.report), MinorityReport)
        self.assertEqual(style.options.reporter, MinorityReport)
github PyCQA / pycodestyle / testsuite / support.py View on Github external
self.counters['test cases'] += 1
        if self.file_errors:
            self.counters['failed tests'] += 1
        return super(TestReport, self).get_file_results()

    def print_results(self):
        results = ("%(physical lines)d lines tested: %(files)d files, "
                   "%(test cases)d test cases%%s." % self.counters)
        if self.total_errors:
            print(results % ", %s failures" % self.total_errors)
        else:
            print(results % "")
        print("Test failed." if self.total_errors else "Test passed.")


class InMemoryReport(BaseReport):
    """
    Collect the results in memory, without printing anything.
    """

    def __init__(self, options):
        super(InMemoryReport, self).__init__(options)
        self.in_memory_errors = []

    def error(self, line_number, offset, text, check):
        """
        Report an error, according to options.
        """
        code = text[:4]
        self.in_memory_errors.append('%s:%s:%s' % (
            code, line_number, offset + 1))
        return super(InMemoryReport, self).error(
github DamnWidget / anaconda / anaconda_lib / linting / anaconda_pep8.py View on Github external
def check(self, code, filename, rcfile, ignore, max_line_length, levels):
        """Check the code with pyflakes to find errors
        """

        messages = []
        _lines = code.split('\n')

        if _lines:
            class AnacondaReport(pep8.BaseReport):
                """Helper class to report PEP8 problems
                """

                def error(self, line_number, offset, text, check):
                    """Report an error, according to options
                    """

                    col = line_number
                    code = text[:4]
                    message = text[5:]

                    if self._ignore_code(code):
                        return

                    if code in self.counters:
                        self.counters[code] += 1
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / autopep8.py View on Github external
def _execute_pep8(pep8_options, source):
    """Execute pycodestyle via python method calls."""
    class QuietReport(pycodestyle.BaseReport):

        """Version of checker that does not print."""

        def __init__(self, options):
            super(QuietReport, self).__init__(options)
            self.__full_error_results = []

        def error(self, line_number, offset, text, check):
            """Collect errors."""
            code = super(QuietReport, self).error(line_number,
                                                  offset,
                                                  text,
                                                  check)
            if code:
                self.__full_error_results.append(
                    {'id': code,
github PyCQA / pycodestyle / pycodestyle.py View on Github external
"""Print benchmark numbers."""
        print('%-7.2f %s' % (self.elapsed, 'seconds elapsed'))
        if self.elapsed:
            for key in self._benchmark_keys:
                print('%-7d %s per second (%d total)' %
                      (self.counters[key] / self.elapsed, key,
                       self.counters[key]))


class FileReport(BaseReport):
    """Collect the results of the checks and print only the filenames."""

    print_filename = True


class StandardReport(BaseReport):
    """Collect and print the results of the checks."""

    def __init__(self, options):
        super(StandardReport, self).__init__(options)
        self._fmt = REPORT_FORMAT.get(options.format.lower(),
                                      options.format)
        self._repeat = options.repeat
        self._show_source = options.show_source
        self._show_pep8 = options.show_pep8

    def init_file(self, filename, lines, expected, line_offset):
        """Signal a new file."""
        self._deferred_print = []
        return super(StandardReport, self).init_file(
            filename, lines, expected, line_offset)
github pantsbuild / pants / contrib / python / src / python / pants / contrib / python / checks / checker / pycodestyle.py View on Github external
def reporter(python_file):
  class PantsReporter(pycodestyle.BaseReport):
    errors = []

    def error(self, line_number, offset, text, check):
      code = super(PantsReporter, self).error(line_number, offset, text, check)
      if code:
        self.errors.append(PyCodeStyleError(python_file, code, line_number, text[5:]))
      return code

  return PantsReporter
github marslo / myvim / Configurations / bundle / python-mode / submodules / pylama / pylama / lint / pylama_pycodestyle.py View on Github external
for option in parser.option_list:
            if option.dest and option.dest in params:
                value = params[option.dest]
                if isinstance(value, str):
                    params[option.dest] = option.convert_value(option, value)

        for key in ["filename", "exclude", "select", "ignore"]:
            if key in params and isinstance(params[key], str):
                params[key] = _parse_multi_options(params[key])

        P8Style = StyleGuide(reporter=_PycodestyleReport, **params)
        buf = StringIO(code)
        return P8Style.input_file(path, lines=buf.readlines())


class _PycodestyleReport(BaseReport):

    def __init__(self, *args, **kwargs):
        super(_PycodestyleReport, self).__init__(*args, **kwargs)
        self.errors = []

    def init_file(self, filename, lines, expected, line_offset):
        """Prepare storage for errors."""
        super(_PycodestyleReport, self).init_file(
            filename, lines, expected, line_offset)
        self.errors = []

    def error(self, line_number, offset, text, check):
        """Save errors."""
        code = super(_PycodestyleReport, self).error(
            line_number, offset, text, check)