Esempio n. 1
0
def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
    from flake8.main import check_file
    _initpep8()
    if ignore:
        pep8style.options.ignore = ignore

    warnings = 0

    gitcmd = "git diff-index --cached --name-only HEAD"
    if lazy:
        gitcmd = gitcmd.replace('--cached ', '')

    _, files_modified, _ = run(gitcmd)
    for filename in files_modified:
        ext = os.path.splitext(filename)[-1]
        if ext != '.py':
            continue
        if not os.path.exists(filename):
            continue
        warnings += check_file(path=filename, ignore=ignore,
                               complexity=complexity)

    if strict:
        return warnings

    return 0
Esempio n. 2
0
def hg_hook(ui, repo, **kwargs):
    from flake8.main import check_file
    complexity = ui.config('flake8', 'complexity', default=-1)
    config = ui.config('flake8', 'config', default=True)
    _initpep8(config_file=config)
    warnings = 0

    for file_ in _get_files(repo, **kwargs):
        warnings += check_file(file_, complexity)

    strict = ui.configbool('flake8', 'strict', default=True)

    if strict:
        return warnings

    return 0
Esempio n. 3
0
def check_flake8(file_paths):
    from flake8.main import check_file

    ignore = {
        "W291",  # trailing whitespace; the standard tidy process will enforce no trailing whitespace
        "E501",  # 80 character line length; the standard tidy process will enforce line length
    }

    num_errors = 0

    for file_path in file_paths:
        if os.path.splitext(file_path)[-1].lower() != ".py":
            continue

        num_errors += check_file(file_path, ignore=ignore)

    return num_errors
Esempio n. 4
0
def check_flake8(file_paths):
    from flake8.main import check_file

    ignore = {
        "W291",  # trailing whitespace; the standard tidy process will enforce no trailing whitespace
        "E501",  # 80 character line length; the standard tidy process will enforce line length
    }

    num_errors = 0

    for file_path in file_paths:
        if os.path.splitext(file_path)[-1].lower() != ".py":
            continue

        num_errors += check_file(file_path, ignore=ignore)

    return num_errors
Esempio n. 5
0
#! /usr/bin/env python

import logging
import os
import os.path
import flake8.main as main

logging.basicConfig(level=logging.ERROR)

if __name__ == "__main__":
    with open('pep8-done.txt') as f:
        for path in f:
            path = path.strip()
            path = os.path.sep.join(path.split('/'))
            if os.path.isfile(path):
                logging.info('Checking file... %s', path)
                main.check_file(path)
            else:
                logging.info('Walking %s', path)
                for dirpath, dirnames, filenames in os.walk(path):
                    # if the file extension is .py, check it!
                    for fname in filenames:
                        fpath = os.path.join(dirpath, fname)
                        root, ext = os.path.splitext(fname)
                        if ext.lower() == ".py":
                            logging.info('Checking file... %s', fpath)
                            main.check_file(fpath)
Esempio n. 6
0
def flake8(ignore=()):
    # run flake8
    passed = {}
    for fnm in git.files_altered():
        passed[fnm] = _flake8.check_file(fnm, ignore=ignore) == 0
    return all(passed.values())