Commits

Tarek Ziadé  committed 51236d0 Merge

merged

  • Participants
  • Parent commits 55e0547, 85a4462

Comments (0)

Files changed (5)

 
 - PyFlakes
 - pep8
-- Ned's MacCabe script
+- Ned's McCabe script
 
 Flake8 runs all tools by launching the single 'flake8' script, but ignores pep8
 and PyFlakes extended options and just uses defaults. It displays the warnings

File flake8/mccabe.py

 import sys
 from collections import defaultdict
 
+WARNING_CODE = "W901"
+
 
 class ASTVisitor:
 
 
 
 class PathGraph:
-    def __init__(self, name):
+    def __init__(self, name, entity, lineno):
         self.name = name
+        self.entity = entity
+        self.lineno = lineno
         self.nodes = defaultdict(list)
 
     def connect(self, n1, n2):
             self.graph.connect(pathnode, bottom)
             self.tail = bottom
         else:
-            self.graph = PathGraph(name)
+            self.graph = PathGraph(name, entity, node.lineno)
             pathnode = PathNode(name)
             self.tail = pathnode
             self.default(node)
 
         if self.graph is None:
             # global loop
-            self.graph = PathGraph(name)
+            self.graph = PathGraph(name, name, node.lineno)
             pathnode = PathNode(name)
             self.tail = pathnode
             self.default(node)
             # ?
             continue
         if graph.complexity() >= min:
-            msg = '%s:%s is too complex (%d)' % (filename,
-                    graph.name, graph.complexity())
+            msg = '%s:%d:1 %s %r is too complex (%d)' % (
+                filename,
+                graph.lineno,
+                WARNING_CODE,
+                graph.entity,
+                graph.complexity(),
+            )
             complex.append(msg)
 
     if len(complex) == 0:

File flake8/messages.py

 
 
 class UnusedImport(Message):
-    message = '%r imported but unused'
+    message = 'W402 %r imported but unused'
 
     def __init__(self, filename, lineno, name):
         Message.__init__(self, filename, lineno)
 
 
 class RedefinedWhileUnused(Message):
-    message = 'redefinition of unused %r from line %r'
+    message = 'W801 redefinition of unused %r from line %r'
 
     def __init__(self, filename, lineno, name, orig_lineno):
         Message.__init__(self, filename, lineno)
 
 
 class ImportShadowedByLoopVar(Message):
-    message = 'import %r from line %r shadowed by loop variable'
+    message = 'W403 import %r from line %r shadowed by loop variable'
 
     def __init__(self, filename, lineno, name, orig_lineno):
         Message.__init__(self, filename, lineno)
 
 
 class ImportStarUsed(Message):
-    message = "'from %s import *' used; unable to detect undefined names"
+    message = "W404 'from %s import *' used; unable to detect undefined names"
 
     def __init__(self, filename, lineno, modname):
         Message.__init__(self, filename, lineno)
 
 
 class UndefinedName(Message):
-    message = 'undefined name %r'
+    message = 'W802 undefined name %r'
 
     def __init__(self, filename, lineno, name):
         Message.__init__(self, filename, lineno)
 
 
 class UndefinedExport(Message):
-    message = 'undefined name %r in __all__'
+    message = 'W803 undefined name %r in __all__'
 
     def __init__(self, filename, lineno, name):
         Message.__init__(self, filename, lineno)
 
 
 class UndefinedLocal(Message):
-    message = "local variable %r (defined in enclosing scope on line %r) " \
-            "referenced before assignment"
+    message = "W804 local variable %r (defined in enclosing scope on line " \
+            "%r) referenced before assignment"
 
     def __init__(self, filename, lineno, name, orig_lineno):
         Message.__init__(self, filename, lineno)
 
 
 class DuplicateArgument(Message):
-    message = 'duplicate argument %r in function definition'
+    message = 'W805 duplicate argument %r in function definition'
 
     def __init__(self, filename, lineno, name):
         Message.__init__(self, filename, lineno)
 
 
 class RedefinedFunction(Message):
-    message = 'redefinition of function %r from line %r'
+    message = 'W806 redefinition of function %r from line %r'
 
     def __init__(self, filename, lineno, name, orig_lineno):
         Message.__init__(self, filename, lineno)
 
 
 class LateFutureImport(Message):
-    message = 'future import(s) %r after other statements'
+    message = 'W405 future import(s) %r after other statements'
 
     def __init__(self, filename, lineno, names):
         Message.__init__(self, filename, lineno)
     used.
     """
 
-    message = 'local variable %r is assigned to but never used'
+    message = 'W806 local variable %r is assigned to but never used'
 
     def __init__(self, filename, lineno, names):
         Message.__init__(self, filename, lineno)

File flake8/pep8.py

                       help="exclude files or directories which match these "
                         "comma separated patterns (default: %s)" %
                         DEFAULT_EXCLUDE)
+    parser.add_option('--exit-zero', action='store_true',
+                      help="use exit code 0 (success), even if there are "
+                        "warnings")
     parser.add_option('--filename', metavar='patterns', default='*.py',
                       help="when parsing directories, only check filenames "
                         "matching these comma separated patterns (default: "

File flake8/run.py

     else:
         stdin = sys.stdin.read()
         warnings += check_code(stdin, complexity)
+
+    if options.exit_zero:
+        raise SystemExit(0)
     raise SystemExit(warnings > 0)