mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Small refactoring in the hooks module
This commit is contained in:
parent
a6977c1916
commit
e4afd25312
1 changed files with 11 additions and 16 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -20,8 +21,7 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
_, files_modified, _ = run(gitcmd)
|
_, files_modified, _ = run(gitcmd)
|
||||||
|
|
||||||
flake8_style = get_style_guide(
|
flake8_style = get_style_guide(
|
||||||
config_file=DEFAULT_CONFIG,
|
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
|
||||||
ignore=ignore, max_complexity=complexity)
|
|
||||||
report = flake8_style.check_files(files_modified)
|
report = flake8_style.check_files(files_modified)
|
||||||
|
|
||||||
if strict:
|
if strict:
|
||||||
|
|
@ -32,18 +32,16 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
|
|
||||||
def hg_hook(ui, repo, **kwargs):
|
def hg_hook(ui, repo, **kwargs):
|
||||||
complexity = ui.config('flake8', 'complexity', default=-1)
|
complexity = ui.config('flake8', 'complexity', default=-1)
|
||||||
|
strict = ui.configbool('flake8', 'strict', default=True)
|
||||||
config = ui.config('flake8', 'config', default=True)
|
config = ui.config('flake8', 'config', default=True)
|
||||||
if config is True:
|
if config is True:
|
||||||
config = DEFAULT_CONFIG
|
config = DEFAULT_CONFIG
|
||||||
|
|
||||||
flake8_style = get_style_guide(
|
|
||||||
config_file=config,
|
|
||||||
max_complexity=complexity)
|
|
||||||
|
|
||||||
paths = _get_files(repo, **kwargs)
|
paths = _get_files(repo, **kwargs)
|
||||||
report = flake8_style.check_files(paths)
|
|
||||||
|
|
||||||
strict = ui.configbool('flake8', 'strict', default=True)
|
flake8_style = get_style_guide(
|
||||||
|
config_file=config, max_complexity=complexity)
|
||||||
|
report = flake8_style.check_files(paths)
|
||||||
|
|
||||||
if strict:
|
if strict:
|
||||||
return report.total_errors
|
return report.total_errors
|
||||||
|
|
@ -53,9 +51,9 @@ def hg_hook(ui, repo, **kwargs):
|
||||||
|
|
||||||
def run(command):
|
def run(command):
|
||||||
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
||||||
p.wait()
|
(stdout, stderr) = p.communicate()
|
||||||
return (p.returncode, [line.strip() for line in p.stdout.readlines()],
|
return (p.returncode, [line.strip() for line in stdout.splitlines()],
|
||||||
[line.strip() for line in p.stderr.readlines()])
|
[line.strip() for line in stderr.splitlines()])
|
||||||
|
|
||||||
|
|
||||||
def _get_files(repo, **kwargs):
|
def _get_files(repo, **kwargs):
|
||||||
|
|
@ -66,11 +64,8 @@ def _get_files(repo, **kwargs):
|
||||||
if file_ in seen or not os.path.exists(file_):
|
if file_ in seen or not os.path.exists(file_):
|
||||||
continue
|
continue
|
||||||
seen.add(file_)
|
seen.add(file_)
|
||||||
if not file_.endswith('.py'):
|
if file_.endswith('.py') and not skip_file(file_):
|
||||||
continue
|
yield file_
|
||||||
if skip_file(file_):
|
|
||||||
continue
|
|
||||||
yield file_
|
|
||||||
|
|
||||||
|
|
||||||
def find_vcs():
|
def find_vcs():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue