Fix spell checker to check all files.

This commit is contained in:
Florian Bruhin 2015-06-05 18:18:29 +02:00
parent 2459f14f6f
commit fd75f77108
2 changed files with 16 additions and 23 deletions

View File

@ -35,9 +35,13 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
from scripts import utils from scripts import utils
def _py_files(target): def _py_files():
"""Iterate over all python files and yield filenames.""" """Iterate over all python files and yield filenames."""
for (dirpath, _dirnames, filenames) in os.walk(target): for (dirpath, _dirnames, filenames) in os.walk('.'):
parts = dirpath.split(os.sep)
if len(parts) >= 2 and parts[1].startswith('.'):
# ignore hidden dirs
continue
for name in (e for e in filenames if e.endswith('.py')): for name in (e for e in filenames if e.endswith('.py')):
yield os.path.join(dirpath, name) yield os.path.join(dirpath, name)
@ -64,7 +68,7 @@ def check_git():
return status return status
def check_spelling(target): def check_spelling():
"""Check commonly misspelled words.""" """Check commonly misspelled words."""
# Words which I often misspell # Words which I often misspell
words = {'behaviour', 'quitted', 'likelyhood', 'sucessfully', words = {'behaviour', 'quitted', 'likelyhood', 'sucessfully',
@ -81,9 +85,9 @@ def check_spelling(target):
seen = collections.defaultdict(list) seen = collections.defaultdict(list)
try: try:
ok = True ok = True
for fn in _py_files(target): for fn in _py_files():
with tokenize.open(fn) as f: with tokenize.open(fn) as f:
if fn == os.path.join('scripts', 'misc_checks.py'): if fn == os.path.join('.', 'scripts', 'misc_checks.py'):
continue continue
for line in f: for line in f:
for w in words: for w in words:
@ -98,11 +102,11 @@ def check_spelling(target):
return None return None
def check_vcs_conflict(target): def check_vcs_conflict():
"""Check VCS conflict markers.""" """Check VCS conflict markers."""
try: try:
ok = True ok = True
for fn in _py_files(target): for fn in _py_files():
with tokenize.open(fn) as f: with tokenize.open(fn) as f:
for line in f: for line in f:
if any(line.startswith(c * 7) for c in '<>=|'): if any(line.startswith(c * 7) for c in '<>=|'):
@ -120,25 +124,14 @@ def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('checker', choices=('git', 'vcs', 'spelling'), parser.add_argument('checker', choices=('git', 'vcs', 'spelling'),
help="Which checker to run.") help="Which checker to run.")
parser.add_argument('target', help="What to check", nargs='*')
args = parser.parse_args() args = parser.parse_args()
if args.checker == 'git': if args.checker == 'git':
ok = check_git() ok = check_git()
return 0 if ok else 1
elif args.checker == 'vcs': elif args.checker == 'vcs':
is_ok = True ok = check_vcs_conflict()
for target in args.target:
ok = check_vcs_conflict(target)
if not ok:
is_ok = False
return 0 if is_ok else 1
elif args.checker == 'spelling': elif args.checker == 'spelling':
is_ok = True ok = check_spelling()
for target in args.target: return 0 if ok else 1
ok = check_spelling(target)
if not ok:
is_ok = False
return 0 if is_ok else 1
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -46,8 +46,8 @@ commands =
[testenv:misc] [testenv:misc]
commands = commands =
{envpython} scripts/misc_checks.py git {envpython} scripts/misc_checks.py git
{envpython} scripts/misc_checks.py vcs qutebrowser scripts tests {envpython} scripts/misc_checks.py vcs
{envpython} scripts/misc_checks.py spelling qutebrowser scripts tests {envpython} scripts/misc_checks.py spelling
[testenv:pylint] [testenv:pylint]
skip_install = true skip_install = true