Open
Description
If i run the following code:
from pathlib import Path
from yasha.cli import cli
Path('template.j2').write_text("{{ var is string }}, {{ var }}")
cli(['--var=foo', 'template.j2'], standalone_mode=False)
assert Path('template').read_text() == 'True, foo'
cli(['--var=foo', 'template.j2'], standalone_mode=False)
assert Path('template').read_text() == 'True, foo'
everything works fine.
If, instead, i run this code:
from pathlib import Path
from yasha.cli import cli
Path('template.j2').write_text("<< var is string >>, << var >>")
Path('extensions.py').write_text("""
BLOCK_START_STRING = '<%'
BLOCK_END_STRING = '%>'
VARIABLE_START_STRING = '<<'
VARIABLE_END_STRING = '>>'
COMMENT_START_STRING = '<#'
COMMENT_END_STRING = '#>'
""")
cli(['--var=foo', '-e', 'extensions.py', 'template.j2'], standalone_mode=False)
assert Path('template').read_text() == 'True, foo'
Path('template.j2').write_text("{{ var is string }}, {{ var }}")
cli(['--var=foo', 'template.j2'], standalone_mode=False)
assert Path('template').read_text() == 'True, foo' # -> AssertionError
Path('template').read_text() # -> '{{ var is string }}, {{ var }}'
The second call to cli
fails, it prints the entire template, unrendered, to the output file. It appears jinja no longer recognizes that second template as a template, and just treats it as text. I suspect that although the second cli
call doesn't use the extensions file, the jinja configuration overrides in that file are persisting somewhere in the python interpreter's global state
Metadata
Assignees
Labels
No labels
Activity