abakan-zz / ablog

ABlog for blogging with Sphinx
ablog.readthedocs.org
Other
122 stars 34 forks source link

Sphinx exception when using Ablog #89

Open DuyguKeskek opened 7 years ago

DuyguKeskek commented 7 years ago

I have a custom Sphinx website using bootstrap theme and I want to import Ablog into it. Whenever I import it, it returns an exception and I can not resolve it.

  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/transforms/__init__.py", line 91, in apply_transforms
    self.document.settings.env = self.env
AttributeError: 'dict' object has no attribute 'env'
The full traceback has been saved in /tmp/sphinx-err-zd7UFJ.log, if you want to report the issue to the developers.

It looks like a Sphinx bug, but I guess this error is related to Ablog. This also happens when I build a different website on my pc. Any help and fix ?

Also, the traceback is below

# Python version: 2.7.13 (CPython)
# Docutils version: 0.13.1 release
# Jinja2 version: 2.9.6
# Last messages:
#   preparing documents...
#   done
#   writing output... [ 25%] about
#   writing output... [ 50%] first-post
#   writing output... [ 75%] hey
#   writing output... [100%] index
#   
#   generating indices...
#   genindex
#   
# Loaded extensions:
#   ablog (0.8.4) from /home/duygu/.local/lib/python2.7/site-packages/ablog/__init__.pyc
#   sphinx.ext.todo (1.6.2) from /home/duygu/.local/lib/python2.7/site-packages/sphinx/ext/todo.pyc
#   sphinx.ext.intersphinx (1.6.2) from /home/duygu/.local/lib/python2.7/site-packages/sphinx/ext/intersphinx.pyc
#   alabaster (0.7.10) from /home/duygu/.local/lib/python2.7/site-packages/alabaster/__init__.pyc
#   sphinx.ext.extlinks (1.6.2) from /home/duygu/.local/lib/python2.7/site-packages/sphinx/ext/extlinks.pyc
Traceback (most recent call last):
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/cmdline.py", line 306, in main
    app.build(opts.force_all, filenames)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/application.py", line 339, in build
    self.builder.build_update()
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 328, in build_update
    'out of date' % len(to_build))
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 397, in build
    self.finish()
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/builders/html.py", line 574, in finish
    self.finish_tasks.add_task(self.gen_additional_pages)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/util/parallel.py", line 49, in add_task
    res = task_func()
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/builders/html.py", line 602, in gen_additional_pages
    self.handle_page(pagename, context, template)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/builders/html.py", line 945, in handle_page
    output = self.templates.render(templatename, ctx)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/jinja2glue.py", line 176, in render
    return self.environment.get_template(template).render(context)
  File "/home/duygu/.local/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/duygu/.local/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/duygu/.local/lib/python2.7/site-packages/ablog/templates/collection.html", line 1, in top-level template code
    {%- extends "page.html" %}
  File "/home/duygu/.local/lib/python2.7/site-packages/ablog/templates/page.html", line 2, in top-level template code
    {% set fa = ablog.fontawesome %}
  File "/home/duygu/.local/lib/python2.7/site-packages/alabaster/layout.html", line 1, in top-level template code
    {%- extends "basic/layout.html" %}
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/themes/basic/../basic/layout.html", line 171, in top-level template code
    {%- block content %}
  File "/home/duygu/.local/lib/python2.7/site-packages/alabaster/layout.html", line 40, in block "content"
    {{ super() }}
  File "/home/duygu/.local/lib/python2.7/site-packages/jinja2/sandbox.py", line 427, in call
    return __context.call(__obj, *args, **kwargs)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/themes/basic/../basic/layout.html", line 175, in block "content"
    {%- block document %}
  File "/home/duygu/.local/lib/python2.7/site-packages/alabaster/layout.html", line 30, in block "document"
    {% block body %} {% endblock %}
  File "/home/duygu/.local/lib/python2.7/site-packages/ablog/templates/collection.html", line 47, in block "body"
    {{ post.to_html(collection.docname) }}
  File "/home/duygu/.local/lib/python2.7/site-packages/jinja2/sandbox.py", line 427, in call
    return __context.call(__obj, *args, **kwargs)
  File "/home/duygu/.local/lib/python2.7/site-packages/ablog/blog.py", line 397, in to_html
    app.env.resolve_references(doctree, pagename, app.builder)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/environment/__init__.py", line 943, in resolve_references
    self.apply_post_transforms(doctree, fromdocname)
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/environment/__init__.py", line 955, in apply_post_transforms
    transformer.apply_transforms()
  File "/home/duygu/.local/lib/python2.7/site-packages/sphinx/transforms/__init__.py", line 90, in apply_transforms
    self.document.settings.env = self.env
AttributeError: 'dict' object has no attribute 'env'

I use Sphinx 1.6.2 but when I try to use older versions of Sphinx, it returns different exceptions. Currently no one who uses Sphinx 1.6.2 can use Ablog, that's why it would be better to fix this bug asap. Thanks.

nabobalis commented 7 years ago

A hack around this was comment out this line in ablog/blog.py

app.env.resolve_references(doctree, pagename, app.builder)

But this obvious affects the functionality of Ablog.