How to use the pep8.Checker 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 moinwiki / moin-1.9 / MoinMoin / _tests / test_sourcecode.py View on Github external
def pep8_error_count(path):
    # process_options initializes some data structures and MUST be called before each Checker().check_all()
    pep8.process_options(['pep8', '--ignore=E202,E221,E222,E241,E301,E302,E401,E501,E701,W391,W601,W602', '--show-source', 'dummy_path'])
    error_count = pep8.Checker(path).check_all()
    return error_count
github questrail / pycan / tests / test_cyclic_comm.py View on Github external
def testPEP8Compliance(self):
        # Ensure PEP8 is installed
        try:
            import pep8
        except ImportError:
            self.fail(msg="PEP8 not installed.")

        # Check the CAN driver
        basedriver = os.path.abspath('pycan/basedriver.py')
        pep8_checker = pep8.Checker(basedriver)
        violation_count = pep8_checker.check_all()
        error_message = "PEP8 violations found: %d" % (violation_count)
        self.assertTrue(violation_count == 0, msg = error_message)
github KDE / kate / addons / kate / pate / src / plugins / python_utils / python_checkers / pep8_checker.py View on Github external
# Check the file for errors with PEP8
    sys.argv = [path]
    pep8.process_options([path])
    python_utils_conf = kate.configuration.root.get('python_utils', {})
    ignore_pep8_errors = python_utils_conf.get(_IGNORE_PEP8_ERRORS, DEFAULT_IGNORE_PEP8_ERRORS)
    if ignore_pep8_errors:
        ignore_pep8_errors = ignore_pep8_errors.split(",")
    else:
        ignore_pep8_errors = []
    if pep8.__version__ in OLD_PEP8_VERSIONS:
        checker = StoreErrorsChecker(path)
        pep8.options.ignore = ignore_pep8_errors
        checker.check_all()
        errors = checker.get_errors()
    else:
        checker = pep8.Checker(path, reporter=KateReport, ignore=ignore_pep8_errors)
        checker.check_all()
        errors = checker.report.get_errors()
    if len(errors) == 0:
        showOk(i18n('Pep8 Ok'))
        return
    errors_to_show = []
    # Paint errors found
    for error in errors:
        errors_to_show.append({
            "line": error[0],
            "column": error[1] + 1,
            "message": error[3],
        })
    showErrors(i18n('Pep8 Errors:'),
               errors_to_show,
               mark_key,
github alademann / SublimeText3-Packages / Anaconda / anaconda_lib / linting / linter.py View on Github external
_ignore = ignore + pep8.DEFAULT_IGNORE.split(',')
                params['ignore'] = _ignore
            else:
                params['config_file'] = os.path.expanduser(rcfile)

            options = pep8.StyleGuide(**params).options
            if not rcfile:
                options.max_line_length = max_line_length

            good_lines = [l + '\n' for l in _lines]
            good_lines[-1] = good_lines[-1].rstrip('\n')

            if not good_lines[-1]:
                good_lines = good_lines[:-1]

            pep8.Checker(filename, good_lines, options=options).check_all()

        return messages
github fabioz / PyDev.Debugger / third_party / pep8 / autopep8.py View on Github external
self.__full_error_results.append(
                    {'id': code,
                     'line': line_number,
                     'column': offset + 1,
                     'info': text})

        def full_error_results(self):
            """Return error results in detail.

            Results are in the form of a list of dictionaries. Each
            dictionary contains 'id', 'line', 'column', and 'info'.

            """
            return self.__full_error_results

    checker = pep8.Checker('', lines=source,
                           reporter=QuietReport, **pep8_options)
    checker.check_all()
    return checker.report.full_error_results()
github cburroughs / pep8.py / pep8.py View on Github external
def input_file(filename):
    """
    Run all checks on a Python source file.
    """
    if excluded(filename):
        return {}
    if options.verbose:
        message('checking ' + filename)
    files_counter_before = options.counters.get('files', 0)
    if options.testsuite: # Keep showing errors for multiple tests
        options.counters = {}
    options.counters['files'] = files_counter_before + 1
    errors = Checker(filename).check_all()
    if options.testsuite: # Check if the expected error was found
        basename = os.path.basename(filename)
        code = basename[:4]
        count = options.counters.get(code, 0)
        if count == 0 and 'not' not in basename:
            message("%s: error %s not found" % (filename, code))
github Bryukh / pep8online / checktools.py View on Github external
def check_text(text, temp_dir, logger=None):
    """
    check text for pep8 requirements
    """
    #prepare code
    code_file, code_filename = tempfile.mkstemp(dir=temp_dir)
    with open(code_filename, 'w') as code_file:
        code_file.write(text.encode('utf8'))
        #initialize pep8 checker
    pep8style = pep8.StyleGuide(parse_argv=False, config_file=False)
    options = pep8style.options
    #redirect print and get result
    temp_outfile = StringIO.StringIO()
    sys.stdout = temp_outfile
    checker = pep8.Checker(code_filename, options=options)
    checker.check_all()
    sys.stdout = sys.__stdout__
    result = temp_outfile.buflist[:]
    #clear all
    temp_outfile.close()
    code_file.close()
    os.remove(code_filename)
    fullResultList = pep8parser(result)
    fullResultList.sort(key=lambda x: (int(x['line']), int(x["place"])))
    if logger:
        logger.debug(result)
    return fullResultList
github mozilla / version-control-tools / pylib / flake8 / flake8 / engine.py View on Github external
parser.remove_option(opt)
        except ValueError:
            pass
    parser.add_option('--exit-zero', action='store_true',
                      help="exit with code 0 even if there are errors")
    for parser_hook in parser_hooks:
        parser_hook(parser)
    parser.add_option('--install-hook', default=False, action='store_true',
                      help='Install the appropriate hook for this '
                      'repository.', dest='install_hook')
    return parser, options_hooks


class StyleGuide(pep8.StyleGuide):
    # Backward compatibility pep8 <= 1.4.2
    checker_class = pep8.Checker

    def input_file(self, filename, lines=None, expected=None, line_offset=0):
        """Run all checks on a Python source file."""
        if self.options.verbose:
            print('checking %s' % filename)
        fchecker = self.checker_class(
            filename, lines=lines, options=self.options)
        # Any "# flake8: noqa" line?
        if any(_flake8_noqa(line) for line in fchecker.lines):
            return 0
        return fchecker.check_all(expected=expected, line_offset=line_offset)


def get_style_guide(**kwargs):
    """Parse the options and configure the checker. This returns a sub-class 
    of ``pep8.StyleGuide``."""