-
-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jinja import does not work inside conditional files #1164
Comments
Looks like a typo? Did you mean |
Thanks for the response. The name of the file is |
I'm able to reproduce the error. 👍 |
It doesn't fail when the file contains an include statement. It really happens only when there is an import statement in the file. 🤔 |
It might be an upstream bug in Jinja2. I can reproduce the problem with Jinja2 alone. |
It's an upstream bug caused by Jinja's code generation where generated code contains the templated filename in an f-string which leads to the error. I'll try to send a PR with a fix to the Jinja project, but it might have to wait until next week. If somebody would like to give it a try immediately, please let me know to avoid duplicate work. In the meantime, the error should not occur if you use, e.g., brackets for Jinja templates, i.e. |
Could you link to the upstream issue if you found/created one? That would help us coordinate. |
As it turns out, an issue had already been created: pallets/jinja#1792 I've submitted a PR that fixes it: pallets/jinja#1852 |
OK, let me close this issue, as it is not directly Copier's. When there's a new fixed jinja release, we'll get it and bug gone. |
Just bumping jinja2 to fix copier-org#1164.
Describe the problem
I use jinja import like this:
it works inside a static file with a name like
file.jinja
. However when I try to use the above import in a conditional file named{% if shouldCreate %}file{% endif %}.jinja
it gives an error as in the logs section.Template
copier.yaml:
common.jinja:
template/{% if shouldCreate %}file{% endif %}.jinja
To Reproduce
No response
Logs
Expected behavior
Import should work in conditional files.
Screenshots/screencasts/logs
No response
Operating system
macOS
Operating system distribution and version
13.3.1
Copier version
copier 7.2.0
Python version
Python 3.10.4
Installation method
pipx+pypi
Additional context
No response
The text was updated successfully, but these errors were encountered: