Skip to content

Commit edccf5c

Browse files
committed
update change_version_number to not break config headers
1 parent f75045c commit edccf5c

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

SU2_PY/change_version_number.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,20 @@
110110

111111
# Loop through and correct all files
112112
for fname in filelist:
113-
s = open(fname, "r").read()
114-
s_new = s.replace(oldvers, newvers)
115-
s_new = s_new.replace(oldvers_q, newvers_q)
113+
lines = open(fname, "r").readlines()
114+
for i, line in enumerate(lines):
115+
if oldvers in line:
116+
# Avoid breaking the formating of some testcase headers
117+
if line.endswith("%\n"):
118+
n = len(newvers) - len(oldvers)
119+
lines[i] = line.replace(
120+
oldvers + " " * max(0, n), newvers + " " * max(0, -n)
121+
)
122+
else:
123+
lines[i] = line.replace(oldvers, newvers)
124+
lines[i] = line.replace(oldvers_q, newvers_q)
116125
f = open(fname, "w")
117-
f.write(s_new)
126+
f.writelines(lines)
118127
f.close()
119128

120129
os.system("rm -rf version.txt")

0 commit comments

Comments
 (0)