Sphinx: `import sphinxcontrib.serializinghtml` fails with circular import woes

Created on 2 Apr 2019  路  4Comments  路  Source: sphinx-doc/sphinx

Describe the bug
There seems to be a circular import problem when trying to import sphinxcontrib.serializinghtml.

To Reproduce
Steps to reproduce the behavior:

$ docker run -it --rm --entrypoint bash python:3.7

# Install sphinx & sphinxcontrib-serializinghtml
root@5a4dc3112f09:/# python3 -m pip install sphinx==2.0.0 sphinxcontrib-serializinghtml==1.1.1
...
Successfully installed Jinja2-2.10 MarkupSafe-1.1.1 Pygments-2.3.1 alabaster-0.7.12 babel-2.6.0 certifi-2019.3.9 chardet-3.0.4 docutils-0.14 idna-2.8 imagesize-1.1.0 packaging-19.0 pyparsing-2.3.1 pytz-2018.9 requests-2.21.0 six-1.12.0 snowballstemmer-1.2.1 sphinx-2.0.0 sphinxcontrib-applehelp-1.0.1 sphinxcontrib-devhelp-1.0.1 sphinxcontrib-htmlhelp-1.0.1 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.2 sphinxcontrib-serializinghtml-1.1.1 urllib3-1.24.1

# Attempt to import, fails
root@5a4dc3112f09:/# python3
Python 3.7.3 (default, Mar 27 2019, 23:40:30)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinxcontrib.serializinghtml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/sphinxcontrib/serializinghtml/__init__.py", line 15, in <module>
    from sphinx.builders.html import BuildInfo, StandaloneHTMLBuilder
  File "/usr/local/lib/python3.7/site-packages/sphinx/builders/html.py", line 1237, in <module>
    from sphinxcontrib.serializinghtml import (  # NOQA
ImportError: cannot import name 'LAST_BUILD_FILENAME' from 'sphinxcontrib.serializinghtml' (/usr/local/lib/python3.7/site-packages/sphinxcontrib/serializinghtml/__init__.py)
# Import sphinx.builders.html first, things work
>>> import sphinx.builders.html
>>> import sphinxcontrib.serializinghtml
>>>

Expected behavior
No other imports should be required before sphinxcontrib.serializinghtml.

Environment info

  • OS:
    root@5a4dc3112f09:/# uname -a
    Linux 5a4dc3112f09 4.19.20-1rodete1-amd64 #1 SMP Debian 4.19.20-1rodete1 (2019-02-12 > 2018) x86_64 GNU/Linux
  • Python version: [e.g. 3.7.1]
    root@5a4dc3112f09:/# python3 -V
    Python 3.7.3

  • Sphinx version: [e.g. 1.8.2]

  • Sphinx extensions: [e.g. sphinx.ext.autodoc, recommonmark]
    root@5a4dc3112f09:/# python3 -m pip list | grep -i sphinx
    Sphinx 2.0.0
    sphinxcontrib-applehelp 1.0.1
    sphinxcontrib-devhelp 1.0.1
    sphinxcontrib-htmlhelp 1.0.1
    sphinxcontrib-jsmath 1.0.1
    sphinxcontrib-qthelp 1.0.2
    sphinxcontrib-serializinghtml 1.1.1
bug

Most helpful comment

Fixed by #6249 and sphinx-doc/sphinxcontrib-serializinghtml#1 (No.1!!)
Thank you for reporting :-)

All 4 comments

Fixed by #6249 and sphinx-doc/sphinxcontrib-serializinghtml#1 (No.1!!)
Thank you for reporting :-)

Actually, it looks like I'm still hitting the same problem -- the new code you've added isn't used until after the failing import.

Notebook with repro: https://colab.research.google.com/drive/1PmL2l3f3BwAhwxmaEeM52XxE1fqksiML

Same as @craigcitro, I can't run Sphinx at all because the circular import still exists:

@ProgVal Could you file a new issue please? I'll check it later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Paebbels picture Paebbels  路  3Comments

jessetan picture jessetan  路  3Comments

susmita1d picture susmita1d  路  3Comments

shimizukawa picture shimizukawa  路  3Comments

shimizukawa picture shimizukawa  路  3Comments