Skip to content

Commit

Permalink
Removed a manual file handler pitfall (apache#9435)
Browse files Browse the repository at this point in the history
  • Loading branch information
NaelsonDouglas authored and mehrdadh committed Dec 1, 2021
1 parent f2324ea commit 1b2fe06
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ def update(file_name, pattern, repl, dry_run=False):
update = []
hit_counter = 0
need_update = False
for l in open(file_name):
result = re.findall(pattern, l)
if result:
assert len(result) == 1
hit_counter += 1
if result[0] != repl:
l = re.sub(pattern, repl, l)
need_update = True
print("%s: %s -> %s" % (file_name, result[0], repl))
else:
print("%s: version is already %s" % (file_name, repl))

update.append(l)
with open(file_name) as file:
for l in file:
result = re.findall(pattern, l)
if result:
assert len(result) == 1
hit_counter += 1
if result[0] != repl:
l = re.sub(pattern, repl, l)
need_update = True
print("%s: %s -> %s" % (file_name, result[0], repl))
else:
print("%s: version is already %s" % (file_name, repl))

update.append(l)
if hit_counter != 1:
raise RuntimeError("Cannot find version in %s" % file_name)

Expand Down

0 comments on commit 1b2fe06

Please sign in to comment.