diff options
| author | Monty Taylor <mordred@inaugust.com> | 2012-07-26 08:22:01 -0500 |
|---|---|---|
| committer | Monty Taylor <mordred@inaugust.com> | 2012-08-03 12:15:44 -0500 |
| commit | b71e86d4d7689896daddf40476f466df7ac6cabe (patch) | |
| tree | 0d9a3a38afb6d2c27fcd272b9fbc4dfc0680164e /tools | |
| parent | 87dcb13117459da0e92b98feadab8a4ecba2c4f9 (diff) | |
| download | nova-b71e86d4d7689896daddf40476f466df7ac6cabe.tar.gz nova-b71e86d4d7689896daddf40476f466df7ac6cabe.tar.xz nova-b71e86d4d7689896daddf40476f466df7ac6cabe.zip | |
Fix broken pep8 exclude processing.
First of all, our pep8 exclude was excluding openstack, to trap
for not doing pep8 checks on openstack/common, which comes from elsewhere.
But, pep8 strips filenames down to basename when doing exclude checks on
them, which makes no sense. To fix this, grab the two functions from pep8,
fix them, and monkeypatch them from within hacking.py.
Patch has been submitted upstream as:
https://github.com/jcrocholl/pep8/pull/111
Also, changed the exclude to catch just openstack/common.
Change-Id: If0b18ae828e74203f84a8b6f8b4ba0100b3bbc59
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/hacking.py | 49 |
1 files changed, 49 insertions, 0 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: |
