summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtools/hacking.py49
-rw-r--r--tox.ini5
2 files changed, 53 insertions, 1 deletions
diff --git a/tools/hacking.py b/tools/hacking.py
index ea490f748..edb06525e 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -21,6 +21,7 @@
built on top of pep8.py
"""
+import fnmatch
import inspect
import logging
import os
@@ -49,6 +50,52 @@ DOCSTRING_TRIPLE = ['"""', "'''"]
VERBOSE_MISSING_IMPORT = False
+# Monkey patch broken excluded filter in pep8
+def filename_match(filename, patterns, default=True):
+ """
+ Check if patterns contains a pattern that matches filename.
+ If patterns is unspecified, this always returns True.
+ """
+ if not patterns:
+ return default
+ return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)
+
+
+def excluded(filename):
+ """
+ Check if options.exclude contains a pattern that matches filename.
+ """
+ basename = os.path.basename(filename)
+ return any((filename_match(filename, pep8.options.exclude,
+ default=False),
+ filename_match(basename, pep8.options.exclude,
+ default=False)))
+
+
+def input_dir(dirname, runner=None):
+ """
+ Check all Python source files in this directory and all subdirectories.
+ """
+ dirname = dirname.rstrip('/')
+ if excluded(dirname):
+ return
+ if runner is None:
+ runner = pep8.input_file
+ for root, dirs, files in os.walk(dirname):
+ if pep8.options.verbose:
+ print('directory ' + root)
+ pep8.options.counters['directories'] += 1
+ dirs.sort()
+ for subdir in dirs[:]:
+ if excluded(os.path.join(root, subdir)):
+ dirs.remove(subdir)
+ files.sort()
+ for filename in files:
+ if pep8.filename_match(filename) and not excluded(filename):
+ pep8.options.counters['files'] += 1
+ runner(os.path.join(root, filename))
+
+
def is_import_exception(mod):
return (mod in IMPORT_EXCEPTIONS or
any(mod.startswith(m + '.') for m in IMPORT_EXCEPTIONS))
@@ -417,6 +464,8 @@ if __name__ == "__main__":
add_nova()
pep8.current_file = current_file
pep8.readlines = readlines
+ pep8.excluded = excluded
+ pep8.input_dir = input_dir
try:
pep8._main()
finally:
diff --git a/tox.ini b/tox.ini
index 5cfaa87b4..b95decf9e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,10 @@ commands = nosetests {posargs}
downloadcache = ~/cache/pip
[testenv:pep8]
-commands = python tools/hacking.py --ignore=N4 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack,*egg .
+deps=pep8==1.0.1
+commands =
+ python tools/hacking.py --ignore=N4 --repeat --show-source \
+ --exclude=.venv,.tox,dist,doc,*openstack/common*,*lib/python*,*egg .
[testenv:cover]
setenv = NOSE_WITH_COVERAGE=1