Skip to content
Snippets Groups Projects
Commit 5a8fb63a authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

normalize-usercode: comments

parent 0f668716
No related branches found
No related tags found
No related merge requests found
...@@ -20,12 +20,15 @@ def normalize_text(ti, fname): ...@@ -20,12 +20,15 @@ def normalize_text(ti, fname):
def normalize_file(fname, inplace): def normalize_file(fname, inplace):
try: try:
# read file, normalize
with open(fname, 'r') as f: with open(fname, 'r') as f:
ti = f.read() ti = f.read()
t = normalize_text(ti, fname) t = normalize_text(ti, fname)
if t == ti: if t == ti:
print(f'FILE {fname}: WAS OK') print(f'FILE {fname}: WAS OK')
return return
# check invariance under second normalization
t2 = normalize_text(t, fname) t2 = normalize_text(t, fname)
if t2 != t: if t2 != t:
with open("out1.py", 'w') as f: with open("out1.py", 'w') as f:
...@@ -34,6 +37,7 @@ def normalize_file(fname, inplace): ...@@ -34,6 +37,7 @@ def normalize_file(fname, inplace):
f.write(t2) f.write(t2)
exit(f'FILE {fname}: BUG - changes under second normalization, see files out1.py and out2.py') exit(f'FILE {fname}: BUG - changes under second normalization, see files out1.py and out2.py')
# output
if inplace: if inplace:
with open(fname, 'w') as f: with open(fname, 'w') as f:
f.write(t) f.write(t)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment