Commit 295b5de4 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Preserve space around version / build variables when updating recipes

parent 06cbbf5a
......@@ -64,12 +64,16 @@ def update_recipe_variable(text : str, varname : str, newvalue : str) -> str:
Returns the patched text.
"""
pat = r'{{% +set +{} += +[\'"](.*)[\'"] +%}}'.format(varname)
pat = r'{{% +set +{}( +)=( +)[\'"](.*)[\'"] +%}}'.format(varname)
lines = list(text.split('\n'))
for i, line in enumerate(lines):
if re.fullmatch(pat, line.strip()):
lines[i] = "{{% set {} = '{}' %}}".format(varname, newvalue)
match = re.fullmatch(pat, line.strip())
if match:
space1 = match.group(1)
space2 = match.group(2)
lines[i] = "{{% set {}{}={}'{}' %}}".format(
varname, space1, space2, newvalue)
break
return '\n'.join(lines)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment