Backed out changeset 2141360b4137 (bug 1288425) for build bustage

This commit is contained in:
Iris Hsiao 2016-07-27 10:59:10 +08:00
Родитель 4f153efd27
Коммит bb2d612158
8 изменённых файлов: 29 добавлений и 52 удалений

Просмотреть файл

@ -25,10 +25,6 @@ class FilterPath(object):
self.path, find_executables=False, ignore=self.exclude)
return self._finder
@property
def ext(self):
return os.path.splitext(self.path)[1]
@property
def exists(self):
return os.path.exists(self.path)
@ -62,22 +58,20 @@ class FilterPath(object):
return repr(self.path)
def filterpaths(paths, linter, **lintargs):
def filterpaths(paths, include=None, exclude=None):
"""Filters a list of paths.
Given a list of paths, and a linter definition plus extra
arguments, return the set of paths that should be linted.
Given a list of paths, and a list of include and exclude
directives, return the set of paths that should be linted.
:param paths: A starting list of paths to possibly lint.
:param linter: A linter definition.
:param lintargs: Extra arguments passed to the linter.
:returns: A list of file paths to lint.
:param include: A list of include directives. May contain glob patterns.
:param exclude: A list of exclude directives. May contain glob patterns.
:returns: A tuple containing a list of file paths to lint, and a list
of file paths that should be excluded (but that the algorithm
was unable to apply).
"""
include = linter.get('include')
exclude = lintargs.get('exclude', [])
exclude.extend(linter.get('exclude', []))
if not lintargs.get('use_filters', True) or (not include and not exclude):
if not include and not exclude:
return paths
include = map(FilterPath, include or [])
@ -91,17 +85,9 @@ def filterpaths(paths, linter, **lintargs):
includeglobs = [p for p in include if not p.exists]
excludeglobs = [p for p in exclude if not p.exists]
extensions = linter.get('extensions')
keep = set()
discard = set()
for path in map(FilterPath, paths):
# Exclude bad file extensions
if extensions and path.isfile and path.ext not in extensions:
continue
if path.match(excludeglobs):
continue
# First handle include/exclude directives
# that exist (i.e don't have globs)
for inc in includepaths:
@ -135,16 +121,15 @@ def filterpaths(paths, linter, **lintargs):
# by an exclude directive.
if not path.match(includeglobs):
continue
elif path.match(excludeglobs):
continue
keep.add(path)
elif path.isdir:
# If the specified path is a directory, use a
# FileFinder to resolve all relevant globs.
path.exclude = [e.path for e in excludeglobs]
path.exclude = excludeglobs
for pattern in includeglobs:
for p, f in path.finder.find(pattern.path):
keep.add(path.join(p))
# Only pass paths we couldn't exclude here to the underlying linter
lintargs['exclude'] = [f.path for f in discard]
return [f.path for f in keep]
return ([f.path for f in keep], [f.path for f in discard])

Просмотреть файл

@ -25,11 +25,17 @@ class BaseType(object):
the definition, but passed in by a consumer.
:returns: A list of :class:`~result.ResultContainer` objects.
"""
paths = filterpaths(paths, linter, **lintargs)
exclude = lintargs.get('exclude', [])
exclude.extend(linter.get('exclude', []))
if lintargs.get('use_filters', True):
paths, exclude = filterpaths(paths, linter.get('include'), exclude)
if not paths:
print("{}: no files to lint in specified paths".format(linter['name']))
return
lintargs['exclude'] = exclude
if self.batch:
return self._lint(paths, linter, **lintargs)

Просмотреть файл

@ -1,2 +0,0 @@
# Oh no.. we called this variable foobar, bad!
foobar = "a string"

Просмотреть файл

@ -22,9 +22,9 @@ LINTER = {
'name': "ExternalLinter",
'description': "It's bad to have the string foobar in js files.",
'include': [
'python/mozlint/test/files',
'**/*.js',
'**/*.jsm',
],
'type': 'external',
'extensions': ['.js', '.jsm'],
'payload': lint,
}

Просмотреть файл

@ -20,8 +20,8 @@ class TestLintRoller(TestCase):
def __init__(self, *args, **kwargs):
TestCase.__init__(self, *args, **kwargs)
self.filedir = os.path.join(here, 'files')
self.files = [os.path.join(self.filedir, f) for f in os.listdir(self.filedir)]
filedir = os.path.join(here, 'files')
self.files = [os.path.join(filedir, f) for f in os.listdir(filedir)]
self.lintdir = os.path.join(here, 'linters')
names = ('string.lint', 'regex.lint', 'external.lint')
@ -70,11 +70,6 @@ class TestLintRoller(TestCase):
self.assertEqual(len(result), 0)
def test_roll_with_invalid_extension(self):
self.lint.read(os.path.join(self.lintdir, 'external.lint'))
result = self.lint.roll(os.path.join(self.filedir, 'foobar.py'))
self.assertEqual(len(result), 0)
if __name__ == '__main__':
main()

Просмотреть файл

@ -71,7 +71,7 @@ class TestLinterTypes(TestCase):
self.lint.lintargs['use_filters'] = False
result = self.lint.roll(self.files)
self.assertEqual(len(result), 2)
self.assertEqual(len(result), 1)
if __name__ == '__main__':

Просмотреть файл

@ -53,7 +53,6 @@ linter. Here are the supported keys:
* payload - The actual linting logic, depends on the type (required)
* include - A list of glob patterns that must be matched (optional)
* exclude - A list of glob patterns that must not be matched (optional)
* extensions - A list of file extensions to be considered (optional)
* setup - A function that sets up external dependencies (optional)
In addition to the above, some ``.lint`` files correspond to a single lint rule. For these, the

Просмотреть файл

@ -45,7 +45,6 @@ The offset is of the form (lineno_offset, num_lines) and is passed
to the lineoffset property of `ResultContainer`.
"""
EXTENSIONS = ['.py', '.lint']
results = []
@ -98,6 +97,10 @@ def lint(files, **lintargs):
'"column":%(col)s,"rule":"%(code)s","message":"%(text)s"}',
]
exclude = lintargs.get('exclude')
if exclude:
cmdargs += ['--exclude', ','.join(lintargs['exclude'])]
# Run any paths with a .flake8 file in the directory separately so
# it gets picked up. This means only .flake8 files that live in
# directories that are explicitly included will be considered.
@ -109,14 +112,6 @@ def lint(files, **lintargs):
continue
run_process(cmdargs+[f])
# XXX For some reason passing in --exclude results in flake8 not using
# the local .flake8 file. So for now only pass in --exclude if there
# is no local config.
exclude = lintargs.get('exclude')
if exclude:
cmdargs += ['--exclude', ','.join(lintargs['exclude'])]
if no_config:
run_process(cmdargs+no_config)
@ -134,7 +129,6 @@ LINTER = {
'testing/talos/',
],
'exclude': [],
'extensions': EXTENSIONS,
'type': 'external',
'payload': lint,
}