mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-16 09:09:52 +00:00
added a header to skip files
This commit is contained in:
parent
5a1a4917e1
commit
93d19d39a5
5 changed files with 36 additions and 8 deletions
4
README
4
README
|
|
@ -10,6 +10,10 @@ options and just uses its defaults.
|
||||||
|
|
||||||
It also adds a few features:
|
It also adds a few features:
|
||||||
|
|
||||||
|
- files that starts with this header are skipped::
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
- lines that contains a "# NOQA" comment at the end will not issue a warning
|
- lines that contains a "# NOQA" comment at the end will not issue a warning
|
||||||
- merging pep8 and pyflakes options
|
- merging pep8 and pyflakes options
|
||||||
- a Mercurial hook
|
- a Mercurial hook
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/home/tarek/dev/bitbucket.org/flake8-clean/bin/python
|
||||||
from flake8 import main
|
from flake8 import main
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"""
|
"""
|
||||||
Implementation of the command-line I{flake8} tool.
|
Implementation of the command-line I{flake8} tool.
|
||||||
"""
|
"""
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import _ast
|
import _ast
|
||||||
|
|
@ -73,6 +73,22 @@ def _noqa(warning):
|
||||||
return line.strip().lower().endswith('# noqa')
|
return line.strip().lower().endswith('# noqa')
|
||||||
|
|
||||||
|
|
||||||
|
_NOQA = re.compile(r'^# flake8: noqa', re.I | re.M)
|
||||||
|
|
||||||
|
|
||||||
|
def skip_file(path):
|
||||||
|
"""Returns True if this header is found in path
|
||||||
|
|
||||||
|
# -*- flake8: noqa -*-
|
||||||
|
"""
|
||||||
|
f = open(path)
|
||||||
|
try:
|
||||||
|
content = f.read()
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
return _NOQA.match(content) is not None
|
||||||
|
|
||||||
|
|
||||||
def checkPath(filename):
|
def checkPath(filename):
|
||||||
"""
|
"""
|
||||||
Check the given path, printing out any warnings detected.
|
Check the given path, printing out any warnings detected.
|
||||||
|
|
@ -96,11 +112,16 @@ def main():
|
||||||
if os.path.isdir(arg):
|
if os.path.isdir(arg):
|
||||||
for dirpath, dirnames, filenames in os.walk(arg):
|
for dirpath, dirnames, filenames in os.walk(arg):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if filename.endswith('.py'):
|
if not filename.endswith('.py'):
|
||||||
fullpath = os.path.join(dirpath, filename)
|
continue
|
||||||
warnings += checkPath(fullpath)
|
fullpath = os.path.join(dirpath, filename)
|
||||||
warnings += pep8.input_file(fullpath)
|
if skip_file(fullpath):
|
||||||
|
continue
|
||||||
|
warnings += checkPath(fullpath)
|
||||||
|
warnings += pep8.input_file(fullpath)
|
||||||
else:
|
else:
|
||||||
|
if skip_file(filename):
|
||||||
|
continue
|
||||||
warnings += checkPath(arg)
|
warnings += checkPath(arg)
|
||||||
warnings += pep8.input_file(arg)
|
warnings += pep8.input_file(arg)
|
||||||
|
|
||||||
|
|
@ -110,6 +131,7 @@ def main():
|
||||||
|
|
||||||
raise SystemExit(warnings > 0)
|
raise SystemExit(warnings > 0)
|
||||||
|
|
||||||
|
|
||||||
def hg_hook(ui, repo, **kwargs):
|
def hg_hook(ui, repo, **kwargs):
|
||||||
pep8.process_options()
|
pep8.process_options()
|
||||||
warnings = 0
|
warnings = 0
|
||||||
|
|
@ -118,6 +140,8 @@ def hg_hook(ui, repo, **kwargs):
|
||||||
for file_ in repo[rev].files():
|
for file_ in repo[rev].files():
|
||||||
if not file_.endswith('.py'):
|
if not file_.endswith('.py'):
|
||||||
continue
|
continue
|
||||||
|
if skip_file(file_):
|
||||||
|
continue
|
||||||
if file_ not in files:
|
if file_ not in files:
|
||||||
files.append(file_)
|
files.append(file_)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,4 +25,3 @@ expected outputs:
|
||||||
but got:
|
but got:
|
||||||
%s''' % (input, repr(expectedOutputs), '\n'.join(map(str, w.messages))))
|
%s''' % (input, repr(expectedOutputs), '\n'.join(map(str, w.messages))))
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,8 @@ class Python25Test(harness.Test):
|
||||||
"""
|
"""
|
||||||
If the target of a C{with} statement uses any or all of the valid forms
|
If the target of a C{with} statement uses any or all of the valid forms
|
||||||
for that part of the grammar (See
|
for that part of the grammar (See
|
||||||
U{http://docs.python.org/reference/compound_stmts.html#the-with-statement}),
|
U{http://docs.python.org/reference/
|
||||||
|
compound_stmts.html#the-with-statement}),
|
||||||
the names involved are checked both for definedness and any bindings
|
the names involved are checked both for definedness and any bindings
|
||||||
created are respected in the suite of the statement and afterwards.
|
created are respected in the suite of the statement and afterwards.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue