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

Epub: TemplateAssertionError: no test named 'index' (2.8) #5707

Closed
jacekpl opened this issue Sep 19, 2015 · 12 comments
Closed

Epub: TemplateAssertionError: no test named 'index' (2.8) #5707

jacekpl opened this issue Sep 19, 2015 · 12 comments

Comments

@jacekpl
Copy link
Contributor

jacekpl commented Sep 19, 2015

I get error below while trying to generate epub file:

# Sphinx version: 1.3.1
# Python version: 2.7.10 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.7.3
# Last messages:
#
#   looking for now-outdated files...
#   none found
#   pickling environment...
#   done
#   checking consistency...
#   done
#   preparing documents...
#   done
#   writing output... [  0%] best_practices/business-logic
# Loaded extensions:
#   sensio.sphinx.phpcode (unknown version) from /Library/Python/2.7/site-packages/sensio/sphinx/phpcode.pyc
#   sphinx.ext.autodoc (1.3.1) from /Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/ext/autodoc.pyc
#   sensio.sphinx.configurationblock (unknown version) from /Library/Python/2.7/site-packages/sensio/sphinx/configurationblock.pyc
#   sphinx.ext.doctest (1.3.1) from /Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/ext/doctest.pyc
#   alabaster (0.7.6) from /Library/Python/2.7/site-packages/alabaster-0.7.6-py2.7.egg/alabaster/__init__.pyc
#   sensio.sphinx.bestpractice (unknown version) from /Library/Python/2.7/site-packages/sensio/sphinx/bestpractice.pyc
#   sensio.sphinx.refinclude (unknown version) from /Library/Python/2.7/site-packages/sensio/sphinx/refinclude.pyc
#   symfonycom.sphinx (unknown version) from /Users/jacek/Downloads/symfony-docs/_theme/_exts/symfonycom/sphinx/__init__.pyc
#   sphinx.ext.todo (1.3.1) from /Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/ext/todo.pyc
#   sensio.sphinx.codeblock (unknown version) from /Library/Python/2.7/site-packages/sensio/sphinx/codeblock.pyc
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/cmdline.py", line 245, in main
    app.build(opts.force_all, filenames)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/application.py", line 264, in build
    self.builder.build_update()
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/__init__.py", line 245, in build_update
    'out of date' % len(to_build))
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/__init__.py", line 316, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/__init__.py", line 354, in write
    self._write_serial(sorted(docnames), warnings)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/__init__.py", line 362, in _write_serial
    self.write_doc(docname, doctree)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/epub.py", line 378, in write_doc
    return StandaloneHTMLBuilder.write_doc(self, docname, doctree)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/html.py", line 445, in write_doc
    self.handle_page(docname, ctx, event_arg=doctree)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/epub.py", line 465, in handle_page
    outfilename, event_arg)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/builders/html.py", line 786, in handle_page
    output = self.templates.render(templatename, ctx)
  File "/Library/Python/2.7/site-packages/Sphinx-1.3.1-py2.7.egg/sphinx/jinja2glue.py", line 138, in render
    return self.environment.get_template(template).render(context)
  File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jacek/Downloads/symfony-docs/_theme/_templates/layout.html", line 6, in <module>
    {% set isIndex = pagename is index %}
TemplateAssertionError: no test named 'index'

Any hints regarding that?

@AndoniZubimendi
Copy link

I have the same problem building the epub.

In the meantime you can comment templates_path = ['_theme/_templates'] in conf.py to build the epub without using the new templates.

@wouterj
Copy link
Member

wouterj commented Sep 24, 2015

The index test used in the new template is created by the symfonycom extension: https://github.com/symfony/symfony-docs/blob/2.8/_theme/_exts/symfonycom/sphinx/__init__.py#L25

This is done in the HTMLTranslator class, which of course isn't used by the epub builder. For some reason though, the epub builder tries to use the new symfony.com theme. I'll look for a way to extract the code from the HTMLTranslator to a more generic class, not very confident if it's possible though (as the current code already is kind of a hack).

@jacekpl
Copy link
Contributor Author

jacekpl commented Nov 28, 2015

Any news regarding that one? I'm still not able to create an epub file. Error message:
Exception occurred:
File "/Users/jacek/Downloads/symfony-docs/_theme/_templates/layout.html", line 6, in
{% set isIndex = pagename is index %}
TemplateAssertionError: no test named 'index'

I have updated all needed extensions.

@renoirb
Copy link

renoirb commented Jan 7, 2016

Same issue here with v 3.0 docs.

Current proposed solution:

Like @AndoniZubimendi said, we can comment templates_path line.

It's something dirty, but it's the only way I could successfully make an epub without digging in the whys —I have NO experience with Sphinx, sorry.

  diff --git i/conf.py w/conf.py
  index e7c6b9d..8d838e2 100644
  --- i/conf.py
  +++ w/conf.py
  @@ -39,7 +39,7 @@ extensions = [
   ]

   # Add any paths that contain templates here, relative to this directory.
  -templates_path = ['_theme/_templates']
  +#templates_path = ['_theme/_templates']

   # The suffix of source filenames.
   source_suffix = '.rst'

Platform:

  • Mac OS X 10.11.12
  • Python w/ Virtualenv Wrapper
  • bash, initialized from fish

Steps:

bash
bash-4.3$ bash --version
GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin14.5.0)
// ...
bash-4.3$ mkvirtualenv foo
bash-4.3$ lsvirtualenv
// (some virtualenvs, foo is now part of it)
bash-4.3$ workon foo
(foo)bash-4.3$ python -V
Python 2.7.10
(foo)bash-4.3$ pip list
pip (7.1.2)
setuptools (18.2)
wheel (0.24.0)
(foo)bash-4.3$ pip install sphinx~=1.3 git+https://github.com/fabpot/sphinx-php.git
Collecting git+https://github.com/fabpot/sphinx-php.git
  Cloning https://github.com/fabpot/sphinx-php.git to /var/folders/yd/nd6ys6x17qlgrnbs91l0jgmw0000gn/T/pip-T5_PRN-build
Collecting sphinx~=1.3
  Using cached Sphinx-1.3.3-py2.py3-none-any.whl
Collecting babel!=2.0,>=1.3 (from sphinx~=1.3)
  Using cached Babel-2.2.0-py2.py3-none-any.whl
Collecting snowballstemmer>=1.1 (from sphinx~=1.3)
  Using cached snowballstemmer-1.2.1-py2.py3-none-any.whl
Collecting sphinx-rtd-theme<2.0,>=0.1 (from sphinx~=1.3)
  Using cached sphinx_rtd_theme-0.1.9-py2-none-any.whl
Collecting six>=1.4 (from sphinx~=1.3)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting Pygments>=2.0 (from sphinx~=1.3)
  Downloading Pygments-2.0.2-py2-none-any.whl (672kB)
    100% |████████████████████████████████| 675kB 650kB/s
Collecting docutils>=0.11 (from sphinx~=1.3)
  Downloading docutils-0.12.tar.gz (1.6MB)
    100% |████████████████████████████████| 1.6MB 290kB/s
Collecting Jinja2>=2.3 (from sphinx~=1.3)
  Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
    100% |████████████████████████████████| 266kB 1.6MB/s
Collecting alabaster<0.8,>=0.7 (from sphinx~=1.3)
  Using cached alabaster-0.7.7-py2.py3-none-any.whl
Collecting pytz>=0a (from babel!=2.0,>=1.3->sphinx~=1.3)
  Using cached pytz-2015.7-py2.py3-none-any.whl
Collecting MarkupSafe (from Jinja2>=2.3->sphinx~=1.3)
  Downloading MarkupSafe-0.23.tar.gz
Building wheels for collected packages: docutils, MarkupSafe
  Running setup.py bdist_wheel for docutils
  Stored in directory: /Users/renoirb/Library/Caches/pip/wheels/d5/32/4f/1347e8ac67071e8150a5dc69354a51a04ac065d0b48334f608
  Running setup.py bdist_wheel for MarkupSafe
  Stored in directory: /Users/renoirb/Library/Caches/pip/wheels/94/a7/79/f79a998b64c1281cb99fa9bbd33cfc9b8b5775f438218d17a7
Successfully built docutils MarkupSafe
Installing collected packages: pytz, babel, snowballstemmer, sphinx-rtd-theme, six, Pygments, docutils, MarkupSafe, Jinja2, alabaster, sphinx, sphinx-php
  Running setup.py install for sphinx-php
Successfully installed Jinja2-2.8 MarkupSafe-0.23 Pygments-2.0.2 alabaster-0.7.7 babel-2.2.0 docutils-0.12 pytz-2015.7 six-1.10.0 snowballstemmer-1.2.1 sphinx-1.3.3 sphinx-php-1.0 sphinx-rtd-theme-0.1.9

make epub

with output

sphinx-build -b epub -d _build/doctrees   . _build/epub
Running Sphinx v1.3.3
A Translator for the html builder is changed.
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [epub]: targets for 467 source files that are out of date
updating environment: [config changed] 467 added, 0 changed, 0 removed
reading sources... [100%] reference/twig_reference
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [  0%] best_practices/business-logic
Exception occurred:
  File "/Users/renoirb/workspaces/sandbox/symfony-docs/symfony-docs/_theme/_templates/layout.html", line 6, in <module>
    {% set isIndex = pagename is index %}
TemplateAssertionError: no test named 'index'
The full traceback has been saved in /var/folders/yd/SOMETHING_RANDOM/T/sphinx-err-SOMETHING_RANDOM.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [epub] Error 1

When I cat the log sphinx-err-...log;

# Sphinx version: 1.3.3
# Python version: 2.7.10 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.8
# Last messages:
#
#   looking for now-outdated files...
#   none found
#   pickling environment...
#   done
#   checking consistency...
#   done
#   preparing documents...
#   done
#   writing output... [  0%] best_practices/business-logic
# Loaded extensions:
#   sensio.sphinx.phpcode (unknown version) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sensio/sphinx/phpcode.pyc
#   sphinx.ext.autodoc (1.3.3) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/ext/autodoc.pyc
#   sensio.sphinx.configurationblock (unknown version) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sensio/sphinx/configurationblock.pyc
#   sphinx.ext.doctest (1.3.3) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/ext/doctest.pyc
#   alabaster (0.7.7) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/alabaster/__init__.pyc
#   sensio.sphinx.bestpractice (unknown version) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sensio/sphinx/bestpractice.pyc
#   sensio.sphinx.refinclude (unknown version) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sensio/sphinx/refinclude.pyc
#   symfonycom.sphinx (unknown version) from /Users/renoirb/workspaces/sandbox/symfony-docs/symfony-docs/_theme/_exts/symfonycom/sphinx/__init__.pyc
#   sphinx.ext.todo (1.3.3) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/ext/todo.pyc
#   sensio.sphinx.codeblock (unknown version) from /Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sensio/sphinx/codeblock.pyc
Traceback (most recent call last):
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/cmdline.py", line 240, in main
    app.build(opts.force_all, filenames)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/application.py", line 266, in build
    self.builder.build_update()
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 252, in build_update
    'out of date' % len(to_build))
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 323, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 361, in write
    self._write_serial(sorted(docnames), warnings)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 369, in _write_serial
    self.write_doc(docname, doctree)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/epub.py", line 378, in write_doc
    return StandaloneHTMLBuilder.write_doc(self, docname, doctree)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/html.py", line 445, in write_doc
    self.handle_page(docname, ctx, event_arg=doctree)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/epub.py", line 465, in handle_page
    outfilename, event_arg)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/html.py", line 792, in handle_page
    output = self.templates.render(templatename, ctx)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/jinja2glue.py", line 138, in render
    return self.environment.get_template(template).render(context)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/renoirb/.virtualenvs/foo/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/renoirb/workspaces/sandbox/symfony-docs/symfony-docs/_theme/_templates/layout.html", line 6, in <module>
    {% set isIndex = pagename is index %}
TemplateAssertionError: no test named 'index'

@renoirb
Copy link

renoirb commented Jan 7, 2016

After some more debugging, it seems that -b epub doesn't load the same extensions as when we load -b html. Removing both get_type and index Jinja references from _theme/_templates/layout.html successfully builds epub version. Which means the epub doesn't load SensioHTMLTranslator class at all and is what breaks the epub build step. epub build step simply ignore extensions list in conf.py. Strangely enough the epub related options doesn't say anything about an epub specific list of extensions.

Either we find a way to adjust epub build options to work with Sphinx default, OR...

Find a way to do the same with Sphinx’s EpubBuilder class (e.g. using Virtualenv, in ~/.virtualenvs/foo/lib/python2.7/site-packages/sphinx/builders/epub.py) to hijack in a similar way as we do with in _theme/_exts/symfonycom/sphinx/__init__.py by changing sphinx.writers.html (SensioHTMLTranslator class) and add filters and tests in a similar way.

I have no idea how to make Sphinx do this.

@dupuchba
Copy link

still have the issue and done what @renoirb is saying without so much understanding :( ... @renoirb do you have any more insights ?

@renoirb
Copy link

renoirb commented Mar 11, 2016

I abandoned. Sorry about that.

@xabbuh
Copy link
Member

xabbuh commented Mar 11, 2016

Unfortunately I am not much of help here too. Since we have the integration with platform.sh I no longer build the documentation locally and didn't invest much time to find a solution for this.

@dupuchba
Copy link

Ok, it's not that important. I just wanted a cool way to have the docs on my kindle but I can live without it ^^

@xabbuh
Copy link
Member

xabbuh commented Mar 16, 2016

I know it's not so nice. In the past I used the PDF documents on Kindle readers too. It's not the best option but it is acceptable. Maybe that works for you too.

@michaelperrin
Copy link
Contributor

I could manage to generate the ePub file, adding a line to the __init__.py file, as shown in my repository: https://github.com/michaelperrin/symfony-docs/blob/epub-generation/_build/_theme/_exts/symfonycom/sphinx/__init__.py#L168

I have a few issues with the generated ePub file (but I could understand the reasons, and will have a look at it). I will open a PR if I manage to solve the remaining problems and if you think it can be useful.

@javiereguiluz
Copy link
Member

I'm closing this because we don't provide support for generating docs in ePub format. But you can keep discussing about this in #7347 if you want. Thanks!

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

8 participants