Skip to content

Commit

Permalink
Fix ./mach test-tidy --faster issue
Browse files Browse the repository at this point in the history
 issue number: 9778
  • Loading branch information
zakorgy committed Apr 5, 2016
1 parent 863c905 commit fad0b36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/servo/testing_commands.py
Expand Up @@ -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):
Expand Down
24 changes: 20 additions & 4 deletions python/tidy.py
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fad0b36

Please sign in to comment.