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

New jinja release leads to attributeerror? #641

Open
adamgayoso opened this issue Mar 24, 2022 · 6 comments
Open

New jinja release leads to attributeerror? #641

adamgayoso opened this issue Mar 24, 2022 · 6 comments

Comments

@adamgayoso
Copy link

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/nbsphinx.py", line 1032, in parse
    rststring, resources = exporter.from_notebook_node(nb, resources)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/nbsphinx.py", line 849, in from_notebook_node
    rststr, resources = super(Exporter, self).from_notebook_node(
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 392, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/jinja2/environment.py", line 1291, in render
    self.environment.handle_exception()
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/jinja2/environment.py", line 926, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 128, in top-level template code
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/rst/index.rst.j2", line 1, in top-level template code
    {%- extends 'display_priority.j2' -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/display_priority.j2", line 1, in top-level template code
    {%- extends 'base/null.j2' -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 26, in top-level template code
    {%- block body -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 29, in block 'body'
    {%- block body_loop -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 31, in block 'body_loop'
    {%- block any_cell scoped -%}
  File "<template>", line 17, in block 'any_cell'
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 34, in block 'any_cell'
    {%- block codecell scoped -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 44, in block 'codecell'
    {%- block output_group -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 48, in block 'output_group'
    {%- block outputs scoped -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 50, in block 'outputs'
    {%- block output scoped -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/share/jupyter/nbconvert/templates/base/null.j2", line 54, in block 'output'
    {%- block stream scoped -%}
  File "<template>", line 152, in block 'stream'
  File "<template>", line 138, in block 'nboutput'
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 66, in template
  File "/home/docs/checkouts/readthedocs.org/user_builds/scvi/envs/1459/lib/python3.8/site-packages/nbconvert/filters/ansi.py", line 60, in ansi2html
    text = jinja2.utils.escape(text)
AttributeError: module 'jinja2.utils' has no attribute 'escape'
@matthewfeickert
Copy link

We're seeing this too in scikit-hep/pyhf#1823

@kratsg
Copy link

kratsg commented Mar 24, 2022

Due to this change: pallets/jinja@824b4d3

Probably can replace jinja.utils.escape with from markupsafe import escape

matthewfeickert added a commit to scikit-hep/pyhf that referenced this issue Mar 24, 2022
…ror (#1824)

* Disallow Jinja2 v3.1.0 to avoid nbsphinx triggering attribute error:
    
    AttributeError: module 'jinja2.utils' has no attribute 'escape'

This is a stopgap measure and this line should be removed as soon as there
is a resolution and new nbsphinx release.
   - c.f. spatialaudio/nbsphinx#641
@mgeier
Copy link
Member

mgeier commented Apr 3, 2022

This has been reported to nbconvert in jupyter/nbconvert#1736, and it has been fixed in jupyter/nbconvert#1737, which should be available in the latest nbconvert release 6.4.5.

Please upgrade nbconvert.

If it still doesn't work, please let me know!

See also sphinx-doc/sphinx#10289, pallets/jinja#1626

@matthewfeickert
Copy link

This has been reported to nbconvert in jupyter/nbconvert#1736, and it has been fixed in jupyter/nbconvert#1737, which should be available in the latest nbconvert release 6.4.5.

Please upgrade nbconvert.

Thanks for this information @mgeier. nbconvert v6.4.5 is indeed fixing things in scikit-hep/pyhf#1837.

Given this, would you be open to updating/adding nbsphinx's lower bounds on nbconvert

nbsphinx/setup.py

Lines 16 to 23 in 80d9b26

install_requires=[
'docutils',
'jinja2',
'nbconvert!=5.4',
'traitlets>=5',
'nbformat',
'sphinx>=1.8',
],

to make it easier for the dependency solvers to avoid these sorts of conflicts?

matthewfeickert added a commit to scikit-hep/pyhf that referenced this issue Apr 3, 2022
* Revert PR #1824 to remove restrictions place on Jinja2 given
spatialaudio/nbsphinx#641. The issues
described there were resolved upstream of nbsphinx in
jupyter/nbconvert#1737.
   - Lower bounds of 'nbconvert>=6.4.5' are not added as lower
     bound restrictions should be applied upstream of pyhf in
     nbsphinx. PR #1824 was applied only because it was
     necessary.
@mgeier
Copy link
Member

mgeier commented Apr 4, 2022

I'm hesitant to add a lower bound to nbconvert because old versions of nbconvert work perfectly fine with old versions of jinja2. It's only a certain combination of versions that doesn't work. I don't know if that's possible to express in conf.py [UPDATE: I meant setup.py].

@matthewfeickert
Copy link

I made Issue #645 so that this Issue doesn't get drawn off topic and become less useful to other people coming here for the original motivation. Apologies in advance if this feels spammy or forceful (not the intent!).

douglatornell added a commit to rhwhite/numeric_2022 that referenced this issue Apr 5, 2022
nbconvert has been updated re: jinja=3.10.
See spatialaudio/nbsphinx#641 (comment)
and jupyter/nbconvert#1737
douglatornell added a commit to rhwhite/numeric_2022 that referenced this issue Apr 5, 2022
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

No branches or pull requests

4 participants