Skip to content

Commit

Permalink
Adds additional comment describing the new Regex usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
MoseleyS committed Dec 14, 2023
1 parent 6ce2c02 commit d04bd9f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions improver/metadata/amend.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def amend_attributes(cube: Cube, attributes_dict: Dict[str, Any]) -> None:
"""
for attribute_name, value in attributes_dict.items():
re_now = r"({now:.*})"
# We use the DOTALL flag below to tell regex that . should match new-line
# characters as well as everything else. Therefore, the match below is for
# any string that contains the word now inside curly braces, with a colon
# and any format specifier. This now section is returned as a group in
# position 1 of has_now, which we will use to format the current time.
has_now = re.match(rf".*{re_now}.*", value, re.DOTALL)
if has_now:
now = has_now[1].format(now=datetime.now())
Expand Down

0 comments on commit d04bd9f

Please sign in to comment.