diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 4346fe6b7f6a..66785e30abef 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -267,7 +267,8 @@ def test_content(self): description='Run the source code tidiness check', category='testing') @CommandArgument('--faster', default=False, action="store_true", - help="Only check changed files and skip the WPT lint in tidy") + help="Only check changed files and skip the WPT lint in tidy, " + "if there are no changes in the WPT files") @CommandArgument('--no-progress', default=False, action="store_true", help="Don't show progress for tidy") def test_tidy(self, faster, no_progress): diff --git a/python/tidy.py b/python/tidy.py index 89b8b6db4e8a..febd9cd6a958 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -68,6 +68,14 @@ ] +def is_iter_empty(iterator): + try: + obj = iterator.next() + return True, itertools.chain((obj,), iterator) + except StopIteration: + return False, iterator + + # A simple wrapper for iterators to show progress (note that it's inefficient for giant iterators) def progress_wrapper(iterator): list_of_stuff = list(iterator) @@ -90,6 +98,9 @@ def filter_file(file_name): def filter_files(start_dir, faster, progress): file_iter = get_file_list(start_dir, faster, ignored_dirs) + (has_element, file_iter) = is_iter_empty(file_iter) + if not has_element: + raise StopIteration if progress: file_iter = progress_wrapper(file_iter) for file_name in file_iter: @@ -100,6 +111,7 @@ def filter_files(start_dir, faster, progress): continue yield file_name + EMACS_HEADER = "/* -*- Mode:" VIM_HEADER = "/* vim:" MAX_LICENSE_LINESPAN = max(len(license.splitlines()) for license in licenses) @@ -554,7 +566,10 @@ def check_spec(file_name, lines): def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions): - print 'Checking files for tidiness...' + (has_element, files_to_check) = is_iter_empty(files_to_check) + if not has_element: + raise StopIteration + print '\rChecking files for tidiness...' for filename in files_to_check: with open(filename, "r") as f: contents = f.read() @@ -569,9 +584,12 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f def get_wpt_files(only_changed_files, progress): - print '\nRunning the WPT lint...' wpt_dir = os.path.join(".", "tests", "wpt", "web-platform-tests" + os.sep) file_iter = get_file_list(os.path.join(wpt_dir), only_changed_files) + (has_element, file_iter) = is_iter_empty(file_iter) + if not has_element: + raise StopIteration + print '\nRunning the WPT lint...' if progress: file_iter = progress_wrapper(file_iter) for f in file_iter: @@ -618,12 +636,10 @@ def scan(faster=False, progress=True): checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json) line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec) errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions) - # wpt lint checks wpt_lint_errors = check_wpt_lint_errors(get_wpt_files(faster, progress)) # collect errors errors = itertools.chain(errors, wpt_lint_errors) - error = None for error in errors: print "\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)