Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Apr 25, 2022
1 parent 2825025 commit 38e20ac
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cylc/rose/jinja2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@


def _lexer_wrap(fcn):
"""Helper for patch_jinja2_leading_zeros.
Patches the jinja2.lexer.Lexer.wrap method.
"""
instances = set()

def _stream(stream):
nonlocal instances
"""Patch the token stream to strip the leading zero where necessary."""
nonlocal instances # record of uses of deprecated syntax
for lineno, token, value_str in stream:
if (
token == jinja2.lexer.TOKEN_INTEGER
and len(value_str) > 1
and value_str[0] == '0'
):
instances.add(value_str)
value_str = value_str[1:]
value_str = value_str[1:] # strip the leading zero
yield (lineno, token, value_str)

def _inner(
Expand All @@ -58,8 +63,8 @@ def _inner(
nonlocal fcn
return fcn(self, _stream(stream), name, filename)

_inner.__wrapped__ = fcn
_inner._instances = instances
_inner.__wrapped__ = fcn # save the un-patched function
_inner._instances = instances # save the set of uses of deprecated syntax

return _inner

Expand Down Expand Up @@ -115,7 +120,7 @@ def patch_jinja2_leading_zeros():
'Support for integers with leading zeros was dropped'
' in Jinja2 v3.'
' Rose will extend support until a future version.'
'\nPlease amend your configuration e.g:'
'\nPlease amend your Rose configuration files e.g:'
'\n * '
+ (
'\n * '.join(
Expand Down

0 comments on commit 38e20ac

Please sign in to comment.