Tarek Ziadé avatar Tarek Ziadé committed 9ab4761

fixed outputs

Comments (0)

Files changed (8)

 Flake8 is just a merge of the PyFlakes and the pep8 projects into one single
 script.
 
-It runs both tests by launching the single 'flake8' script, and also adds a 
-few features:
+It runs both tests by launching the single 'flake8' script, but ignores pep8
+options and just uses its defaults.
+
+It also adds a few features:
 
 - lines that contains a "# NOQA" comment at the end will not issue a warning
+- merging pep8 and pyflakes options
 - more things to come..
 
 Original projects:
 #!/usr/bin/python
-from flake8.scripts.flake8 import main
+from flake8 import main
 
 if __name__ == '__main__':
     main()

flake8/__init__.py

-#
+
+"""
+Implementation of the command-line I{flake8} tool.
+"""
+
+import sys
+import os
+import _ast
+import pep8
+
+checker = __import__('flake8.checker').checker
+
+def check(codeString, filename):
+    """
+    Check the Python source given by C{codeString} for flakes.
+
+    @param codeString: The Python source to check.
+    @type codeString: C{str}
+
+    @param filename: The name of the file the source came from, used to report
+        errors.
+    @type filename: C{str}
+
+    @return: The number of warnings emitted.
+    @rtype: C{int}
+    """
+    # First, compile into an AST and handle syntax errors.
+    try:
+        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+    except SyntaxError, value:
+        msg = value.args[0]
+
+        (lineno, offset, text) = value.lineno, value.offset, value.text
+
+        # If there's an encoding problem with the file, the text is None.
+        if text is None:
+            # Avoid using msg, since for the only known case, it contains a
+            # bogus message that claims the encoding the file declared was
+            # unknown.
+            print >> sys.stderr, "%s: problem decoding source" % (filename, )
+        else:
+            line = text.splitlines()[-1]
+
+            if offset is not None:
+                offset = offset - (len(text) - len(line))
+
+            print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
+            print >> sys.stderr, line
+
+            if offset is not None:
+                print >> sys.stderr, " " * offset, "^"
+
+        return 1
+    else:
+        # Okay, it's syntactically valid.  Now check it.
+        w = checker.Checker(tree, filename)
+        w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
+        for warning in w.messages:
+            print warning
+        return len(w.messages)
+
+
+def checkPath(filename):
+    """
+    Check the given path, printing out any warnings detected.
+
+    @return: the number of warnings printed
+    """
+    try:
+        return check(file(filename, 'U').read() + '\n', filename)
+    except IOError, msg:
+        print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
+        return 1
+
+
+def main():
+    pep8.process_options()
+
+    warnings = 0
+    args = sys.argv[1:]
+    if args:
+        for arg in args:
+            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)
+            else:
+                warnings += checkPath(arg)
+                warnings += pep8.input_file(arg)
+
+    else:
+        stdin = sys.stdin.read()
+        warnings += check(stdin, '<stdin>')
+
+
+    raise SystemExit(warnings > 0)

flake8/checker.py

 import os.path
 import _ast
 
-from pyflakes import messages
-
+from flake8 import messages
 
 # utility function to iterate over an AST node's children, adapted
 # from Python 2.6's standard ast module
         count = options.counters.get(code, 0)
         if count == 0 and 'not' not in basename:
             message("%s: error %s not found" % (filename, code))
-    return len(errors)
+    return errors
 
 def input_dir(dirname):
     """
Add a comment to this file

flake8/scripts/__init__.py

Empty file removed.

flake8/scripts/flake8.py

-
-"""
-Implementation of the command-line I{flake8} tool.
-"""
-
-import sys
-import os
-import _ast
-
-from flake8.pep8 import input_file
-from flake8 import pep8
-
-checker = __import__('flake8.checker').checker
-
-def check(codeString, filename):
-    """
-    Check the Python source given by C{codeString} for flakes.
-
-    @param codeString: The Python source to check.
-    @type codeString: C{str}
-
-    @param filename: The name of the file the source came from, used to report
-        errors.
-    @type filename: C{str}
-
-    @return: The number of warnings emitted.
-    @rtype: C{int}
-    """
-    # First, compile into an AST and handle syntax errors.
-    try:
-        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
-    except SyntaxError, value:
-        msg = value.args[0]
-
-        (lineno, offset, text) = value.lineno, value.offset, value.text
-
-        # If there's an encoding problem with the file, the text is None.
-        if text is None:
-            # Avoid using msg, since for the only known case, it contains a
-            # bogus message that claims the encoding the file declared was
-            # unknown.
-            print >> sys.stderr, "%s: problem decoding source" % (filename, )
-        else:
-            line = text.splitlines()[-1]
-
-            if offset is not None:
-                offset = offset - (len(text) - len(line))
-
-            print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
-            print >> sys.stderr, line
-
-            if offset is not None:
-                print >> sys.stderr, " " * offset, "^"
-
-        return 1
-    else:
-        # Okay, it's syntactically valid.  Now check it.
-        w = checker.Checker(tree, filename)
-        w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
-        for warning in w.messages:
-            print warning
-        return len(w.messages)
-
-
-def checkPath(filename):
-    """
-    Check the given path, printing out any warnings detected.
-
-    @return: the number of warnings printed
-    """
-    try:
-        return check(file(filename, 'U').read() + '\n', filename)
-    except IOError, msg:
-        print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
-        return 1
-
-
-def main():
-    warnings = 0
-    args = sys.argv[1:]
-    if args:
-        for arg in args:
-            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 += input_file(fullpath)
-            else:
-                warnings += checkPath(arg)
-                warnings += input_file(arg)
-
-    else:
-        stdin = sys.stdin.read()
-        warnings += check(stdin, '<stdin>')
-
-
-    raise SystemExit(warnings > 0)
     description="code checking",
     author="Tarek Ziade",
     url="http://bitbucket.org/tarek/flake8",
-    packages=["flake8", "flake8.scripts", "flake8.test"],
+    packages=["flake8", "flake8.test"],
     scripts=["bin/flake8"],
     long_description=README,
     classifiers=[
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.