summaryrefslogtreecommitdiff
path: root/pyflakes/scripts/pyflakes.py
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-06-27 13:08:52 +0100
committerJonathan Lange <jml@canonical.com>2012-06-27 13:08:52 +0100
commit7555e3437c4786e036c8948a8fd0b1aac6897ce4 (patch)
tree68b1e8ac7e773f2054aebe2a22b10158a5d36c35 /pyflakes/scripts/pyflakes.py
parent802e0a46e59f5039ba0b2d0e21dd1219baed1efa (diff)
downloadpyflakes-7555e3437c4786e036c8948a8fd0b1aac6897ce4.tar.gz
I can't really help this refactoring.
Diffstat (limited to 'pyflakes/scripts/pyflakes.py')
-rw-r--r--pyflakes/scripts/pyflakes.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/pyflakes/scripts/pyflakes.py b/pyflakes/scripts/pyflakes.py
index 328b666..aa61675 100644
--- a/pyflakes/scripts/pyflakes.py
+++ b/pyflakes/scripts/pyflakes.py
@@ -46,6 +46,7 @@ class Reporter(object):
self._stdout.write('\n')
+
def check(codeString, filename, reporter=None):
"""
Check the Python source given by C{codeString} for flakes.
@@ -91,6 +92,7 @@ def check(codeString, filename, reporter=None):
return len(w.messages)
+
def checkPath(filename, reporter=None):
"""
Check the given path, printing out any warnings detected.
@@ -104,6 +106,22 @@ def checkPath(filename, reporter=None):
return 1
+
+def iterSourceFiles(paths):
+ """
+ Iterate over source files listed in C{paths}.
+ """
+ for path in paths:
+ if os.path.isdir(path):
+ for dirpath, dirnames, filenames in os.walk(path):
+ for filename in filenames:
+ if filename.endswith('.py'):
+ yield os.path.join(dirpath, filename)
+ else:
+ yield path
+
+
+
def checkRecursive(paths, reporter=None):
"""
Check the given files and look recursively under any directories, looking
@@ -113,18 +131,12 @@ def checkRecursive(paths, reporter=None):
@return: the number of warnings printed
"""
warnings = 0
- for path in paths:
- if os.path.isdir(path):
- for dirpath, dirnames, filenames in os.walk(path):
- for filename in filenames:
- if filename.endswith('.py'):
- warnings += checkPath(os.path.join(dirpath, filename),
- reporter)
- else:
- warnings += checkPath(path, reporter)
+ for sourcePath in iterSourceFiles(paths):
+ warnings += checkPath(sourcePath, reporter)
return warnings
+
def main():
warnings = 0
args = sys.argv[1:]