mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +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:
|
||||
|
||||
- files that starts with this header are skipped::
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
- lines that contains a "# NOQA" comment at the end will not issue a warning
|
||||
- merging pep8 and pyflakes options
|
||||
- a Mercurial hook
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#!/home/tarek/dev/bitbucket.org/flake8-clean/bin/python
|
||||
from flake8 import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"""
|
||||
Implementation of the command-line I{flake8} tool.
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
import _ast
|
||||
|
|
@ -73,6 +73,22 @@ def _noqa(warning):
|
|||
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):
|
||||
"""
|
||||
Check the given path, printing out any warnings detected.
|
||||
|
|
@ -96,11 +112,16 @@ def main():
|
|||
if os.path.isdir(arg):
|
||||
for dirpath, dirnames, filenames in os.walk(arg):
|
||||
for filename in filenames:
|
||||
if filename.endswith('.py'):
|
||||
fullpath = os.path.join(dirpath, filename)
|
||||
warnings += checkPath(fullpath)
|
||||
warnings += pep8.input_file(fullpath)
|
||||
if not filename.endswith('.py'):
|
||||
continue
|
||||
fullpath = os.path.join(dirpath, filename)
|
||||
if skip_file(fullpath):
|
||||
continue
|
||||
warnings += checkPath(fullpath)
|
||||
warnings += pep8.input_file(fullpath)
|
||||
else:
|
||||
if skip_file(filename):
|
||||
continue
|
||||
warnings += checkPath(arg)
|
||||
warnings += pep8.input_file(arg)
|
||||
|
||||
|
|
@ -110,6 +131,7 @@ def main():
|
|||
|
||||
raise SystemExit(warnings > 0)
|
||||
|
||||
|
||||
def hg_hook(ui, repo, **kwargs):
|
||||
pep8.process_options()
|
||||
warnings = 0
|
||||
|
|
@ -118,6 +140,8 @@ def hg_hook(ui, repo, **kwargs):
|
|||
for file_ in repo[rev].files():
|
||||
if not file_.endswith('.py'):
|
||||
continue
|
||||
if skip_file(file_):
|
||||
continue
|
||||
if file_ not in files:
|
||||
files.append(file_)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,3 @@ expected outputs:
|
|||
but got:
|
||||
%s''' % (input, repr(expectedOutputs), '\n'.join(map(str, w.messages))))
|
||||
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
|
||||
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
|
||||
created are respected in the suite of the statement and afterwards.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue