in utils/bump-version.py [0:0]
def find_and_replace(path, pattern, replace):
# Does a find and replace within a file path and complains
# if the given pattern isn't found in the file.
with open(path, "r") as f:
old_data = f.read()
if re.search(pattern, old_data, flags=re.MULTILINE) is None:
print(f"Didn't find the pattern {pattern!r} in {path!s}")
exit(1)
new_data = re.sub(pattern, replace, old_data, flags=re.MULTILINE)
with open(path, "w") as f:
f.truncate()
f.write(new_data)