Skip to content

Commit

Permalink
Auto merge of #14853 - Manishearth:stylo-tidy, r=Wafflespeanut
Browse files Browse the repository at this point in the history
Make tidy work on stylo trees

This adds `./mach test-tidy --stylo`, which turns off the usage of git to search for files to check (fixes #14855), and also turns off the wpt lint, making it possible to run tidy in a stylo tree.

r? @jdm @wafflespeanut

cc @bzbarsky

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14853)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Feb 9, 2017
2 parents 368af6f + b60368d commit 9eaf96b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 2 additions & 0 deletions python/servo/lints/wpt_lint.py
Expand Up @@ -26,6 +26,8 @@ def _get_wpt_files(self, suite):
yield f[len(working_dir):]

def run(self):
if self.stylo:
return
wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))
for suite in SUITES:
files = self._get_wpt_files(suite)
Expand Down
6 changes: 4 additions & 2 deletions python/servo/testing_commands.py
Expand Up @@ -381,11 +381,13 @@ def test_content(self):
help="Don't show progress for tidy")
@CommandArgument('--self-test', default=False, action="store_true",
help="Run unit tests for tidy")
def test_tidy(self, all_files, no_progress, self_test):
@CommandArgument('--stylo', default=False, action="store_true",
help="Only handle files in the stylo tree")
def test_tidy(self, all_files, no_progress, self_test, stylo):
if self_test:
return test_tidy.do_tests()
else:
return tidy.scan(not all_files, not no_progress)
return tidy.scan(not all_files, not no_progress, stylo=stylo)

@Command('test-webidl',
description='Run the WebIDL parser tests',
Expand Down
41 changes: 26 additions & 15 deletions python/tidy/servo_tidy/tidy.py
Expand Up @@ -111,11 +111,19 @@ def progress_wrapper(iterator):


class FileList(object):
def __init__(self, directory, only_changed_files=False, exclude_dirs=[], progress=True):
def __init__(self, directory, only_changed_files=False, exclude_dirs=[], progress=True, stylo=False):
self.directory = directory
self.excluded = exclude_dirs
iterator = self._git_changed_files() if only_changed_files else \
self._filter_excluded() if exclude_dirs else self._default_walk()
iterator = self._filter_excluded() if exclude_dirs else self._default_walk()
if only_changed_files and not stylo:
try:
# Fall back if git doesn't work
newiter = self._git_changed_files()
obj = next(newiter)
iterator = itertools.chain((obj,), newiter)
except subprocess.CalledProcessError:
pass

# Raise `StopIteration` if the iterator is empty
obj = next(iterator)
self.generator = itertools.chain((obj,), iterator)
Expand Down Expand Up @@ -160,9 +168,10 @@ def filter_file(file_name):
return True


def filter_files(start_dir, only_changed_files, progress):
def filter_files(start_dir, only_changed_files, progress, stylo):
file_iter = FileList(start_dir, only_changed_files=only_changed_files,
exclude_dirs=config["ignore"]["directories"], progress=progress)
exclude_dirs=config["ignore"]["directories"], progress=progress,
stylo=stylo)
for file_name in file_iter:
base_name = os.path.basename(file_name)
if not any(fnmatch.fnmatch(base_name, pattern) for pattern in FILE_PATTERNS_TO_CHECK):
Expand Down Expand Up @@ -978,11 +987,12 @@ def check_dep_license_errors(filenames, progress=True):


class LintRunner(object):
def __init__(self, lint_path=None, only_changed_files=True, exclude_dirs=[], progress=True):
def __init__(self, lint_path=None, only_changed_files=True, exclude_dirs=[], progress=True, stylo=False):
self.only_changed_files = only_changed_files
self.exclude_dirs = exclude_dirs
self.progress = progress
self.path = lint_path
self.stylo = stylo

def check(self):
if not os.path.exists(self.path):
Expand All @@ -996,7 +1006,8 @@ def check(self):
module = imp.load_source(filename[:-3], self.path)
if hasattr(module, 'Lint'):
if issubclass(module.Lint, LintRunner):
lint = module.Lint(self.path, self.only_changed_files, self.exclude_dirs, self.progress)
lint = module.Lint(self.path, self.only_changed_files,
self.exclude_dirs, self.progress, stylo=self.stylo)
for error in lint.run():
if not hasattr(error, '__iter__'):
yield (self.path, 1, "errors should be a tuple of (path, line, reason)")
Expand All @@ -1017,8 +1028,8 @@ def run(self):
yield (self.path, 0, "class 'Lint' should implement 'run' method")


def run_lint_scripts(only_changed_files=False, progress=True):
runner = LintRunner(only_changed_files=only_changed_files, progress=progress)
def run_lint_scripts(only_changed_files=False, progress=True, stylo=False):
runner = LintRunner(only_changed_files=only_changed_files, progress=progress, stylo=stylo)
for path in config['lint-scripts']:
runner.path = path
for error in runner.check():
Expand All @@ -1040,26 +1051,26 @@ def check_commits(path='.'):
raise StopIteration


def scan(only_changed_files=False, progress=True):
def scan(only_changed_files=False, progress=True, stylo=False):
# check config file for errors
config_errors = check_config_file(CONFIG_FILE_PATH)
# check directories contain expected files
directory_errors = check_directory_files(config['check_ext'])
# standard checks
files_to_check = filter_files('.', only_changed_files, progress)
files_to_check = filter_files('.', only_changed_files, progress, stylo)
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json, check_yaml)
line_checking_functions = (check_license, check_by_line, check_toml, check_shell,
check_rust, check_spec, check_modeline)
file_errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
# check dependecy licenses
dep_license_errors = check_dep_license_errors(get_dep_toml_files(only_changed_files), progress)
# other lint checks
lint_errors = run_lint_scripts(only_changed_files, progress)
lint_errors = run_lint_scripts(only_changed_files, progress, stylo=stylo)
# check commits for WIP
commit_errors = check_commits()
commit_errors = [] if stylo else check_commits()
# chain all the iterators
errors = itertools.chain(config_errors, directory_errors, file_errors, dep_license_errors, lint_errors,
commit_errors)
errors = itertools.chain(config_errors, directory_errors, lint_errors,
file_errors, dep_license_errors, commit_errors)

error = None
for error in errors:
Expand Down

0 comments on commit 9eaf96b

Please sign in to comment.