How to use the pep8.BaseReport function in pep8

To help you get started, we’ve selected a few pep8 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 alademann / SublimeText3-Packages / Anaconda / anaconda_lib / linting / linter.py View on Github external
def pep8_check(self, code, filename, rcfile, ignore, max_line_length):
        """Check the code with pep8 to find PEP 8 errors
        """

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

        if _lines:
            class FakeCol:
                """Fake class to represent a col object for PyFlakes
                """

                def __init__(self, line_number):
                    self.lineno = line_number

            class SublimeLinterReport(pep8.BaseReport):
                """Helper class to report PEP 8 problems
                """

                def error(self, line_number, offset, text, check):
                    """Report an error, according to options
                    """
                    col = FakeCol(line_number)
                    code = text[:4]
                    message = text[5:]

                    if self._ignore_code(code):
                        return

                    if code in self.counters:
                        self.counters[code] += 1
                    else:
github JulianEberius / SublimePythonIDE / pep8.py View on Github external
def print_statistics(self, prefix=''):
        """Print overall statistics (number of errors and warnings)."""
        for line in self.get_statistics(prefix):
            print(line)

    def print_benchmark(self):
        """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):
github jazzband / django-discover-jenkins / discover_jenkins / tasks / run_pep8.py View on Github external
def teardown_test_environment(self, **kwargs):
        locations = get_app_locations()

        class JenkinsReport(pep8.BaseReport):
            def error(instance, line_number, offset, text, check):
                code = super(JenkinsReport, instance).error(
                    line_number, offset, text, check,
                )

                if not code:
                    return
                sourceline = instance.line_offset + line_number
                self.output.write(
                    '%s:%s:%s: %s\n' %
                    (instance.filename, sourceline, offset + 1, text),
                )

        pep8style = pep8.StyleGuide(
            parse_argv=False, config_file=self.pep8_rcfile,
            reporter=JenkinsReport, **self.pep8_options
github kmmbvnr / django-jenkins / django_jenkins / tasks / run_pep8.py View on Github external
def run(self, apps_locations, **options):
        output = open(os.path.join(options['output_dir'], 'pep8.report'), 'w')

        class JenkinsReport(pep8.BaseReport):
            def error(instance, line_number, offset, text, check):
                code = super(JenkinsReport, instance).error(line_number, offset, text, check)
                if code:
                    sourceline = instance.line_offset + line_number
                    output.write('%s:%s:%s: %s\n' % (instance.filename, sourceline, offset + 1, text))

        pep8_options = {}
        config_file = self.get_config_path(options)
        if config_file is not None:
            pep8_options['config_file'] = config_file

        set_option(pep8_options, 'exclude', options['pep8-exclude'], config_file,
                   default=pep8.DEFAULT_EXCLUDE + ",south_migrations", split=',')

        set_option(pep8_options, 'select', options['pep8-select'], config_file, split=',')
github quantifiedcode / checkmate / checkmate / contrib / plugins / python / pep8 / analyzer.py View on Github external
def init_file(self,filename,lines,expected,line_offset):
        pep8.BaseReport.init_file(self,filename,lines,expected,line_offset)
github quantifiedcode / checkmate / checkmate / contrib / plugins / python / pep8 / analyzer.py View on Github external
pep8style = pep8.StyleGuide(quiet = True)
        try:
            handle,temp_filename = tempfile.mkstemp()
            fh = os.fdopen(handle,"wb")
            fh.write(file_revision.get_file_content())
            fh.close()
            pep8style.init_report(Reporter)
            result = pep8style.check_files([temp_filename])
        finally:
            os.unlink(temp_filename)
        #we add the fingerprints...
        for issue in result.issues:
            issue['fingerprint'] = self.get_fingerprint_from_code(file_revision, issue['location'], extra_data=issue['data'])
        return {'issues' : result.issues}

class Reporter(pep8.BaseReport):

    def init_file(self,filename,lines,expected,line_offset):
        pep8.BaseReport.init_file(self,filename,lines,expected,line_offset)

    def error(self,line_number,offset,text,check):

        code = int(text.strip()[1:4])

        if text.strip()[0] == 'E':
            issue_level = 'error'
        else:
            issue_level = 'warning'

        error_code = text.strip()[:2]

        issue = {
github PyCQA / flake8 / flake8 / reporter.py View on Github external
import collections
import errno
import re
import sys
try:
    import multiprocessing
except ImportError:     # Python 2.5
    multiprocessing = None

import pep8

__all__ = ['multiprocessing', 'BaseQReport', 'QueueReport']


class BaseQReport(pep8.BaseReport):
    """Base Queue Report."""
    _loaded = False   # Windows support

    # Reasoning for ignored error numbers is in-line below
    ignored_errors = set([
        # EPIPE: Added by sigmavirus24
        # > If output during processing is piped to something that may close
        # > its own stdin before we've finished printing results, we need to
        # > catch a Broken pipe error and continue on.
        # > (See also: https://gitlab.com/pycqa/flake8/issues/69)
        errno.EPIPE,
        # NOTE(sigmavirus24): When adding to this list, include the reasoning
        # on the lines before the error code and always append your error
        # code. Further, please always add a trailing `,` to reduce the visual
        # noise in diffs.
    ])
github zrzka / blackmamba / blackmamba / analyzer.py View on Github external
def __lt__(self, other):
        if self.source is _Source.pep8 and other.source is _Source.pyflakes:
            return True

        if self.style is Style.warning and other.style is Style.error:
            return True

        return False


#
# pep8
#

class _Pep8AnnotationReport(pep8.BaseReport):
    def __init__(self, options):
        super().__init__(options)
        self.annotations = []

    def error(self, line_number, offset, text, check):
        # If super doesn't return code, this one is ignored
        if not super().error(line_number, offset, text, check):
            return

        annotation = _AnalyzerAnnotation(self.line_offset + line_number, text, _Source.pep8, Style.warning)
        self.annotations.append(annotation)


def _pep8_annotations(text, ignore=None, max_line_length=None):
    # pep8 requires you to include \n at the end of lines
    lines = text.splitlines(True)
github dreadatour / Pep8Lint / Pep8Lint.py View on Github external
return

    # get current line (line under cursor)
    current_line = view.rowcol(view_selection[0].end())[0]

    if current_line in view_errors:
        # there is an error on current line
        errors = view_errors[current_line]
        view.set_status('pep8-tip',
                        'Pep8 errors: %s' % ' / '.join(errors))
    else:
        # no errors - clear statusbar
        view.erase_status('pep8-tip')


class Pep8Report(pep8.BaseReport):
    """
    Collect all results of the checks.
    """
    def __init__(self, options):
        """
        Initialize reporter.
        """
        super(Pep8Report, self).__init__(options)
        # errors "collection" =)
        self.errors = []

    def error(self, line_number, offset, text, check):
        """
        Get error and save it into errors collection.
        """
        code = super(Pep8Report, self).error(line_number, offset, text, check)
github fabioz / PyDev.Debugger / third_party / pep8 / autopep8.py View on Github external
def _execute_pep8(pep8_options, source):
    """Execute pep8 via python method calls."""
    class QuietReport(pep8.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, _):
            """Collect errors."""
            code = super(QuietReport, self).error(line_number, offset, text, _)
            if code:
                self.__full_error_results.append(
                    {'id': code,
                     'line': line_number,
                     'column': offset + 1,
                     'info': text})