Skip to content
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

Extending rst.tpl fails in current master and 6.0.0a0 #1158

Closed
matthew-brett opened this issue Dec 31, 2019 · 7 comments · Fixed by #1173
Closed

Extending rst.tpl fails in current master and 6.0.0a0 #1158

matthew-brett opened this issue Dec 31, 2019 · 7 comments · Fixed by #1173

Comments

@matthew-brett
Copy link
Contributor

Extending rst.tpl with a DictLoader has worked up until the 6.0.0a0 alpha release, but now fails, in 6.0.0a0 as in current master (b31a5af).

import nbconvert
import nbformat
from jinja2 import DictLoader

DL = DictLoader({'rst_plus_stuff.tpl': """\
{%- extends 'rst.tpl' -%}
"""})


class MyExporter(nbconvert.RSTExporter):
    template_file = 'rst_plus_stuff.tpl'

exporter = MyExporter(extra_loaders=[DL])

nb = nbformat.v4.new_notebook()
output, resources = exporter.from_notebook_node(nb)

This succeeds on current stable on pip (5.6.1), but fails for current master, with:

Traceback (most recent call last):
  File "/Users/mb312/tmp/nbconvert_check.py", line 17, in <module>
    output, resources = plots_exporter.from_notebook_node(nb)
  File "/Users/mb312/dev_trees/nbconvert/nbconvert/exporters/templateexporter.py", line 357, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/Users/mb312/.virtualenvs/test3/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/Users/mb312/.virtualenvs/test3/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/mb312/.virtualenvs/test3/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/mb312/.virtualenvs/test3/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
jinja2.exceptions.TemplateNotFound: rst.tpl

Nbconvert version:

@MSeal
Copy link
Contributor

MSeal commented Jan 1, 2020

Yes, the 6.0.0 alpha has changes to the template patterns. Specifically templates now have directories with jinja (.j2) files. We released the alpha so libraries could start catching these issues early.

In this case 'rst.tpl' becomes 'rst/index.rst.j2' and the DictLoader will go back to working correctly.

@mgeier
Copy link
Contributor

mgeier commented Jan 1, 2020

@matthew-brett This is the corresponding fix in nbsphinx, created by @takluyver: spatialaudio/nbsphinx#344.

@matthew-brett
Copy link
Contributor Author

Thanks - I'll try that fix. I wonder how many of your upstream users are using --pre test envs? Is there any way of softening the backwards compatible break here? Like a DeprecationWarning, and auto-replace of rst.tpl (etc) with the new values?

@maartenbreddels
Copy link
Collaborator

maartenbreddels commented Jan 2, 2020 via email

@MSeal
Copy link
Contributor

MSeal commented Jan 3, 2020

We could try to emit a deprecation warning and convert the path when we detect an old-style path. That's probably a good idea for 6.0.0 and let's us wait until 6.1 to drop the older pattern completely.

@maartenbreddels
Copy link
Collaborator

#1173 is an alternative way to fix this. I think I should have done this from the start but didn't think it would be that simple to provide backward compatibility.

@matthew-brett
Copy link
Contributor Author

Excellent - thanks - that is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants