in Build/check_indents.py [0:0]
def check_file(filename : str) -> bool:
"""
Checks a single file, returning True and writing a cleaned file if a mix
of tabs and spaces was found.
"""
problem_found = False
found_spaces = False
found_tabs = False
with open(filename, 'r') as f:
contents = list(f.readlines())
for line in contents:
# Find the leading whitespace.
whitespace, rest = find_whitespace(line)
found_spaces = found_spaces or (' ' in whitespace)
found_tabs = found_tabs or ('\t' in whitespace)
problem_found = found_spaces and found_tabs
if problem_found:
print(f"Found mixed spaces and tabs in {filename}.")
# Time to normalize!
with open(filename, 'w') as f:
f.writelines(
whitespace.replace('\t', ' ') + rest
for whitespace, rest in map(find_whitespace, contents)
)
return problem_found