sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.58k stars 2.12k forks source link

IndexError: pop from empty list in depart_table when using sphinx_book_theme with custom extension djangodocs.py #13122

Open zypdominate opened 3 days ago

zypdominate commented 3 days ago

Describe the bug

When building documentation for Django using sphinx_book_theme, an IndexError: pop from empty list occurs in the depart_table function of a custom extension (djangodocs.py). The error seems related to table handling and compatibility with the theme or Sphinx version.

How to Reproduce

Clone the Django documentation source:

git clone https://github.com/django/django.git
cd django/docs

Install necessary dependencies:

pip install sphinx sphinx-book-theme

Build the documentation with the specified theme:

.\make.bat html

Observe the IndexError occurring in the console.

Environment Information

# Platform:         win32; (Windows-11-10.0.22631-SP0)
# Sphinx version:   8.1.3
# Python version:   3.12.0 (CPython)
# Docutils version: 0.21.2
# Jinja2 version:   3.1.1
# Pygments version: 2.18.0
Theme: sphinx_book_theme (latest version)
Django Documentation Source: Cloned from https://github.com/django/django

Sphinx extensions

No response

Additional context

Error log

# Last messages:
#   faq/help
#   
#   
#   writing output... [  1%]
#   faq/index
#   
#   
#   writing output... [  1%]
#   faq/install
#   

# Loaded extensions:
#   sphinx.ext.mathjax (8.1.3)
#   alabaster (1.0.0)
#   sphinxcontrib.applehelp (2.0.0)
#   sphinxcontrib.devhelp (2.0.0)
#   sphinxcontrib.htmlhelp (2.1.0)
#   sphinxcontrib.serializinghtml (2.0.0)
#   sphinxcontrib.qthelp (2.0.0)
#   djangodocs (unknown version)
#   sphinx.ext.extlinks (8.1.3)
#   sphinx.ext.intersphinx (8.1.3)
#   sphinx.ext.viewcode (8.1.3)
#   sphinx.ext.autosectionlabel (8.1.3)
#   sphinx_book_theme (unknown version)
#   pydata_sphinx_theme (unknown version)

# Traceback:
Traceback (most recent call last):
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\cmd\build.py", line 514, in build_main
    app.build(args.force_all, args.filenames)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\application.py", line 381, in build
    self.builder.build_update()
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\__init__.py", line 358, in build_update
    self.build(
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\__init__.py", line 437, in build
    self.write(docnames, list(updated_docnames), method)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\__init__.py", line 711, in write
    self.write_documents(docnames)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\__init__.py", line 725, in write_documents
    self._write_serial(sorted_docnames)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\__init__.py", line 744, in _write_serial
    self.write_doc(docname, doctree)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\builders\html\__init__.py", line 653, in write_doc
    self.docwriter.write(doctree, destination)
  File "D:\software\Python\Python312\Lib\site-packages\docutils\writers\__init__.py", line 80, in write
    self.translate()
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\writers\html.py", line 35, in translate
    self.document.walkabout(visitor)
  File "D:\software\Python\Python312\Lib\site-packages\docutils\nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\Python\Python312\Lib\site-packages\docutils\nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\Python\Python312\Lib\site-packages\docutils\nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\Python\Python312\Lib\site-packages\docutils\nodes.py", line 199, in walkabout
    visitor.dispatch_departure(self)
  File "D:\software\Python\Python312\Lib\site-packages\sphinx\util\docutils.py", line 740, in dispatch_departure
    method(node)
  File "D:\software\Python\Python312\Lib\site-packages\pydata_sphinx_theme\translator.py", line 66, in depart_table
    super().depart_table(node)
  File "D:\Download\Django-doc\django\docs\_ext\djangodocs.py", line 128, in depart_table
    self.compact_p = self.context.pop()
                     ^^^^^^^^^^^^^^^^^^
IndexError: pop from empty list
electric-coder commented 3 days ago

There's something strange about that extension list wanting 3 themes (alabaster, sphinx_book_theme (unknown version) and pydata_sphinx_theme (unknown version)) - did you install all those dependencies?

IndexError: pop from empty list occurs in the depart_table function of a custom extension (djangodocs.py)

You should likely ask at that extension's repository or the Django repository how their docs are supposed to be built, because there's also no djangodocs extension on pypi...