check_sources.py
54 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
/ tools / check_sources.py
Fernando Perez
|
r2115 | #!/usr/bin/env python | ||
"""Utility to look for hard tabs and \r characters in all sources. | ||||
Fernando Perez
|
r2116 | |||
Usage: | ||||
./check_sources.py | ||||
It prints summaries and if chosen, line-by-line info of where \\t or \\r | ||||
characters can be found in our source tree. | ||||
Fernando Perez
|
r2115 | """ | ||
Fernando Perez
|
r2116 | # Config | ||
# If true, all lines that have tabs are printed, with line number | ||||
full_report_tabs = True | ||||
# If true, all lines that have tabs are printed, with line number | ||||
full_report_rets = False | ||||
Fernando Perez
|
r2115 | |||
Fernando Perez
|
r2116 | # Code begins | ||
from IPython.external.path import path | ||||
vivainio
|
r503 | |||
Fernando Perez
|
r2115 | rets = [] | ||
Fernando Perez
|
r2116 | tabs = [] | ||
Fernando Perez
|
r2115 | |||
Fernando Perez
|
r2116 | for f in path('..').walkfiles('*.py'): | ||
vivainio
|
r503 | errs = '' | ||
cont = f.bytes() | ||||
if '\t' in cont: | ||||
errs+='t' | ||||
Fernando Perez
|
r2116 | tabs.append(f) | ||
vivainio
|
r503 | |||
if '\r' in cont: | ||||
errs+='r' | ||||
Fernando Perez
|
r2115 | rets.append(f) | ||
vivainio
|
r503 | |||
if errs: | ||||
print "%3s" % errs, f | ||||
Fernando Perez
|
r2116 | |||
if 't' in errs and full_report_tabs: | ||||
for ln,line in enumerate(f.lines()): | ||||
if '\t' in line: | ||||
print 'TAB:',ln,':',line, | ||||
if 'r' in errs and full_report_rets: | ||||
for ln,line in enumerate(open(f.abspath(),'rb')): | ||||
if '\r' in line: | ||||
print 'RET:',ln,':',line, | ||||
# Summary at the end, to call cleanup tools if necessary | ||||
if tabs: | ||||
print 'Hard tabs found. These can be cleaned with untabify:' | ||||
for f in tabs: print f, | ||||
if rets: | ||||
print 'Carriage returns (\\r) found in:' | ||||
for f in rets: print f, | ||||