mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
Bug 1533152 - [flake8] Make sure glob patterns are honoured when passing files directly, r=andi
Flake8 ignores the 'exclude' section of the .flake8.yml if you pass in a direct path to a file. To get around this we have some custom logic to handle these exclusions for us, but this custom logic didn't account for globs. Differential Revision: https://phabricator.services.mozilla.com/D23145 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
14e690f5f3
commit
aac57cc8b5
@ -271,9 +271,13 @@ def expand_exclusions(paths, config, root):
|
||||
for path in paths:
|
||||
path = mozpath.normsep(path)
|
||||
if os.path.isfile(path):
|
||||
if not any(path.startswith(e) for e in exclude):
|
||||
yield path
|
||||
continue
|
||||
if any(path.startswith(e) for e in exclude if '*' not in e):
|
||||
continue
|
||||
|
||||
if any(mozpath.match(path, e) for e in exclude if '*' in e):
|
||||
continue
|
||||
|
||||
yield path
|
||||
|
||||
ignore = [e[len(path):].lstrip('/') for e in exclude
|
||||
if mozpath.commonprefix((path, e)) == path]
|
||||
|
@ -41,7 +41,7 @@ def paths(root):
|
||||
return _inner
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
@pytest.fixture
|
||||
def config(request):
|
||||
"""Finds, loads and returns the config for the linter name specified by the
|
||||
LINTER global variable in the calling module.
|
||||
@ -60,7 +60,7 @@ def config(request):
|
||||
return parser.parse(config_path)[0]
|
||||
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def run_setup(config):
|
||||
"""Make sure that if the linter named in the LINTER global variable has a
|
||||
setup function, it gets called before running the tests.
|
||||
@ -72,7 +72,7 @@ def run_setup(config):
|
||||
func(build.topsrcdir)
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
@pytest.fixture
|
||||
def lint(config, root):
|
||||
"""Find and return the 'lint' function for the external linter named in the
|
||||
LINTER global variable.
|
||||
|
@ -79,6 +79,20 @@ def test_lint_excluded_file(lint, paths, config):
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
def test_lint_excluded_file_with_glob(lint, paths, config):
|
||||
config['exclude'] = paths('ext/*.configure')
|
||||
|
||||
files = paths('ext')
|
||||
results = lint(files, config)
|
||||
print(results)
|
||||
assert len(results) == 0
|
||||
|
||||
files = paths('ext/bad.configure')
|
||||
results = lint(files, config)
|
||||
print(results)
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
def test_lint_uses_custom_extensions(lint, paths):
|
||||
assert len(lint(paths('ext'))) == 1
|
||||
assert len(lint(paths('ext/bad.configure'))) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user