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
This commit is contained in:
Monty Taylor
2012年07月26日 08:22:01 -05:00
parent 87dcb13117
commit b71e86d4d7

View File

@@ -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:

View File

@@ -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
Reference in New Issue
openstack/nova
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.