% include in TemplateWriterTask raises "no loader" error

When I attempt to include another file in Template using {include 'blah.txt' } I get the following error:

TypeError: no loader for this environment specified

From a quick google, this is apparently a fairly common problem for client codes using jinja2. The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work. Is this a bug or something I’m doing wrong on my end?

I am using windows with anaconda2 and python 2.7.

The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work.

Could you point me to where you see this in the docs?

I haven’t worked with trying more complex templates with the %include command myself, so might not be able to help

···

On Friday, February 8, 2019 at 10:23:50 AM UTC-8, [email protected] wrote:

When I attempt to include another file in Template using {include 'blah.txt' } I get the following error:

TypeError: no loader for this environment specified

From a quick google, this is apparently a fairly common problem for client codes using jinja2. The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work. Is this a bug or something I’m doing wrong on my end?

I am using windows with anaconda2 and python 2.7.

Sure. In the TemplateWriterTask documentation under “A more advanced template” the last paragraph reads:

Therefore, with Jinja2’s templating language we can write fairly general templates. While variable substitutions, if/then statements, and for loops should cover the majority of cases, you can see even more features in the official Jinja2 documentation. For example, you can use template inheritance or insert templates into other templates.

I don’t know what subset is broken because of this issue, but import and include are. This is something that I’ve seen mentioned in reports to other projects as well, so likely there is a workaround somewhere we could borrow. I just wanted to make sure it wasn’t me.

Eli

···

On Friday, February 8, 2019 at 10:57:34 AM UTC-8, Anubhav Jain wrote:

The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work.

Could you point me to where you see this in the docs?

I haven’t worked with trying more complex templates with the %include command myself, so might not be able to help

On Friday, February 8, 2019 at 10:23:50 AM UTC-8, [email protected] wrote:

When I attempt to include another file in Template using {include 'blah.txt' } I get the following error:

TypeError: no loader for this environment specified

From a quick google, this is apparently a fairly common problem for client codes using jinja2. The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work. Is this a bug or something I’m doing wrong on my end?

I am using windows with anaconda2 and python 2.7.

Hi Eli

I think that documentation is just recapitulating features of Jinja that would be expected to work, but I am not sure that we tested it. I am going to remove that last part from the docs as probably it’s not accurate based on what you report.

Sorry to not have a solution, but we have no evidence that anyone has gotten the template inheritance to work with TemplateWriterTask in the past.

Best,

Anubhav

···

Best,
Anubhav

Anubhav,

Rather than altering the docs, I have includes going on my copy. I imagine it would work for inheritance too. I made the obvious assumption that includes are best identified relative to the original template directory. It just requires one line change in templatewriter_task.py plus a corresponding change in the imports. Let me know if you need it in the form of a pull request.

from jinja2 import Environment,FileSystemLoader # Template is no longer needed

#t = Template(f.read()) This line is eliminated in favor of the one below
t = Environment(loader=FileSystemLoader(self.template_dir)).from_string(f.read())

``

···

On Friday, February 8, 2019 at 2:09:54 PM UTC-8, ajain wrote:

Hi Eli

I think that documentation is just recapitulating features of Jinja that would be expected to work, but I am not sure that we tested it. I am going to remove that last part from the docs as probably it’s not accurate based on what you report.

Sorry to not have a solution, but we have no evidence that anyone has gotten the template inheritance to work with TemplateWriterTask in the past.

Best,

Anubhav

On Fri, Feb 8, 2019 at 11:33 AM [email protected] wrote:

Sure. In the TemplateWriterTask documentation under “A more advanced template” the last paragraph reads:

Therefore, with Jinja2’s templating language we can write fairly general templates. While variable substitutions, if/then statements, and for loops should cover the majority of cases, you can see even more features in the official Jinja2 documentation. For example, you can use template inheritance or insert templates into other templates.

I don’t know what subset is broken because of this issue, but import and include are. This is something that I’ve seen mentioned in reports to other projects as well, so likely there is a workaround somewhere we could borrow. I just wanted to make sure it wasn’t me.

Eli

On Friday, February 8, 2019 at 10:57:34 AM UTC-8, Anubhav Jain wrote:

The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work.

Could you point me to where you see this in the docs?

I haven’t worked with trying more complex templates with the %include command myself, so might not be able to help

On Friday, February 8, 2019 at 10:23:50 AM UTC-8, [email protected] wrote:

When I attempt to include another file in Template using {include 'blah.txt' } I get the following error:

TypeError: no loader for this environment specified

From a quick google, this is apparently a fairly common problem for client codes using jinja2. The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work. Is this a bug or something I’m doing wrong on my end?

I am using windows with anaconda2 and python 2.7.

You received this message because you are subscribed to the Google Groups “fireworkflows” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

Visit this group at https://groups.google.com/group/fireworkflows.

For more options, visit https://groups.google.com/d/optout.


Best,
Anubhav

Thanks! My preference is that you submit a PR so that we can keep track of contributions correctly.

However, if you’d rather I implement it myself, let me know.

···

On Friday, February 8, 2019 at 5:28:53 PM UTC-8, [email protected] wrote:

Anubhav,

Rather than altering the docs, I have includes going on my copy. I imagine it would work for inheritance too. I made the obvious assumption that includes are best identified relative to the original template directory. It just requires one line change in templatewriter_task.py plus a corresponding change in the imports. Let me know if you need it in the form of a pull request.

from jinja2 import Environment,FileSystemLoader # Template is no longer needed

#t = Template(f.read()) This line is eliminated in favor of the one below
t = Environment(loader=FileSystemLoader(self.template_dir)).from_string(f.read())

``

On Friday, February 8, 2019 at 2:09:54 PM UTC-8, ajain wrote:

Hi Eli

I think that documentation is just recapitulating features of Jinja that would be expected to work, but I am not sure that we tested it. I am going to remove that last part from the docs as probably it’s not accurate based on what you report.

Sorry to not have a solution, but we have no evidence that anyone has gotten the template inheritance to work with TemplateWriterTask in the past.

Best,

Anubhav

On Fri, Feb 8, 2019 at 11:33 AM [email protected] wrote:

Sure. In the TemplateWriterTask documentation under “A more advanced template” the last paragraph reads:

Therefore, with Jinja2’s templating language we can write fairly general templates. While variable substitutions, if/then statements, and for loops should cover the majority of cases, you can see even more features in the official Jinja2 documentation. For example, you can use template inheritance or insert templates into other templates.

I don’t know what subset is broken because of this issue, but import and include are. This is something that I’ve seen mentioned in reports to other projects as well, so likely there is a workaround somewhere we could borrow. I just wanted to make sure it wasn’t me.

Eli

On Friday, February 8, 2019 at 10:57:34 AM UTC-8, Anubhav Jain wrote:

The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work.

Could you point me to where you see this in the docs?

I haven’t worked with trying more complex templates with the %include command myself, so might not be able to help

On Friday, February 8, 2019 at 10:23:50 AM UTC-8, [email protected] wrote:

When I attempt to include another file in Template using {include 'blah.txt' } I get the following error:

TypeError: no loader for this environment specified

From a quick google, this is apparently a fairly common problem for client codes using jinja2. The include capability is part of the Fireworks documentation, so I gather there is an intention for it to work. Is this a bug or something I’m doing wrong on my end?

I am using windows with anaconda2 and python 2.7.

You received this message because you are subscribed to the Google Groups “fireworkflows” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

Visit this group at https://groups.google.com/group/fireworkflows.

For more options, visit https://groups.google.com/d/optout.


Best,
Anubhav