Commits

Tarek Ziadé committed fdbd8a2 Merge

Merged in fix_excludes (pull request #27)

Comments (0)

Files changed (6)

 - Miki Tebeka
 - David Cramer
 - Peter Teichman
+- Oleg Broytman
+- Marc Labbé
 is emited. If you don't specify it or set it to **-1**, it's just ignored.
 If specified, it must be a positive value. 12 is usually a good value.
 
+*lazy* when set to ``True`` will also take into account files not added to the 
+index.
+
 Also, make sure the file is executable and adapt the shebang line so it
 point to your python interpreter.
 
 =======
 
 1.6
+---
 
-XXX
+- changed the signatures of the ``check_file`` function in flake8/run.py, 
+  ``skip_warning`` in flake8/util.py and the ``check``, ``checkPath``
+  functions in flake8/pyflakes.py.
 
 
 1.5 - 2012-10-13
         print(">>> " + tokens[0][4].rstrip())
 
     for token_type, text, start, end, line in tokens:
+        if line.strip().lower().endswith('# nopep8'):
+            continue
+
         newline = row < start[0] - first_row
         if newline:
             row = start[0] - first_row

flake8/pyflakes.py

         if node.name is not None:
             if isinstance(node.name, str):
                 name = node.name
+            elif hasattr(node.name, 'elts'):
+                names = [e.id for e in node.name.elts]
+                name = '({0})'.format(', '.join(names))
             else:
                 name = node.name.id
             self.addBinding(node.lineno, Assignment(name, node))
             self.addBinding(node.lineno, importation)
 
 
-def checkPath(filename):
+def checkPath(filename, ignore=[]):
     """
     Check the given path, printing out any warnings detected.
 
     @return: the number of warnings printed
     """
     try:
-        return check(open(filename, 'U').read() + '\n', filename)
+        return check(open(filename, 'U').read() + '\n', ignore, filename)
     except IOError:
         msg = sys.exc_info()[1]
         sys.stderr.write("%s: %s\n" % (filename, msg.args[1]))
         return 1
 
 
-def check(codeString, filename='(code)'):
+def check(codeString, ignore, filename='(code)'):
     """
     Check the Python source given by C{codeString} for flakes.
 
         valid_warnings = 0
 
         for warning in w.messages:
-            if skip_warning(warning):
+            if skip_warning(warning, ignore):
                 continue
             print(warning)
             valid_warnings += 1
 pep8style = None
 
 
-def check_file(path, complexity=-1):
-    warnings = pyflakes.checkPath(path)
+def check_file(path, ignore=[], complexity=-1):
+    if pep8style.excluded(path):
+        return 0
+    warnings = pyflakes.checkPath(path, ignore)
     warnings += pep8style.input_file(path)
     if complexity > -1:
         warnings += mccabe.get_module_complexity(path, complexity)
                     if not filename.endswith('.py'):
                         continue
                     fullpath = os.path.join(dirpath, filename)
-                    if not skip_file(fullpath, pep8style):
+                    if not skip_file(fullpath) or pep8style.excluded(fullpath):
                         yield fullpath
 
         else:
-            if not skip_file(path, pep8style):
+            if not skip_file(path) or pep8style.excluded(path):
                 yield path
 
 
 
     if pep8style.paths and options.filename is not None:
         for path in _get_python_files(pep8style.paths):
-            warnings += check_file(path, complexity)
+            warnings += check_file(path, options.ignore, complexity)
     else:
         # wait for 1 second on the stdin fd
         reads, __, __ = select.select([sys.stdin], [], [], 1.)
             [line.strip() for line in p.stderr.readlines()])
 
 
-def git_hook(complexity=-1, strict=False, ignore=None):
+def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
     _initpep8()
     if ignore:
         pep8.options.ignore = ignore
 
     warnings = 0
 
-    _, files_modified, _ = run("git diff-index --cached --name-only HEAD")
+    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':
 import os
 
 
-def skip_warning(warning):
+def skip_warning(warning, ignore=[]):
     # XXX quick dirty hack, just need to keep the line in the warning
+    if warning.message.split()[0] in ignore:
+        return True
     if not os.path.isfile(warning.filename):
         return False
 
 _NOQA = re.compile(r'flake8[:=]\s*noqa', re.I | re.M)
 
 
-def skip_file(path, pep8style):
+def skip_file(path):
     """Returns True if this header is found in path
 
     # flake8: noqa
     """
+    if not os.path.isfile(path):
+        return False
     f = open(path)
     try:
         content = f.read()
     finally:
         f.close()
-    return _NOQA.search(content) is not None or pep8style.excluded(path)
+    return _NOQA.search(content) is not None