Exemple #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
Exemple #2
0
        def run(self):
            _initpep8()

            # _get_python_files can produce the same file several
            # times, if one of its paths is a parent of another. Keep
            # a set of checked files to de-duplicate.
            checked = set()

            warnings = 0
            for path in _get_python_files(self.distribution_files()):
                if path not in checked:
                    warnings += check_file(path)
                checked.add(path)

            raise SystemExit(warnings > 0)
Exemple #3
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