sphinx-doc / sphinx

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

Sphinx 7.2: unknown node type: only #13022

Open JasperCraeghs opened 1 month ago

JasperCraeghs commented 1 month ago

Describe the bug

The use of an only-directive that is nested inside of a parent only-directive to conditionally include a directive of the Sphinx plugin breathe fails since Sphinx 7.2. Sphinx<=7.1.2 supports this use case.

/home/user/git/minimal-doc/<partial node>:: WARNING: unknown node type: <only: <list_item...><list_item...><list_item...>>

Traceback (most recent call last):
...
  File "/home/user/git/minimal-doc/venv/lib/python3.10/site-packages/sphinx/util/docutils.py", line 743, in dispatch_departure
    super().dispatch_departure(node)
  File "/home/user/git/minimal-doc/venv/lib/python3.10/site-packages/docutils/nodes.py", line 2005, in dispatch_departure
    return method(node)
  File "/home/user/git/minimal-doc/venv/lib/python3.10/site-packages/docutils/nodes.py", line 2027, in unknown_departure
    raise NotImplementedError(
NotImplementedError: <class 'sphinx.writers.html5.HTML5Translator'> departing unknown node type: only

Exception occurred:
  File "/home/user/git/minimal-doc/venv/lib/python3.10/site-packages/docutils/nodes.py", line 2027, in unknown_departure
    raise NotImplementedError(
NotImplementedError: <class 'sphinx.writers.html5.HTML5Translator'> departing unknown node type: only

How to Reproduce

My minimal git repository contains build output of doxygen, needed for the breathe directive (doxygenfile) to function, which is required to reproduce the bug.

git clone git@github.com:JasperCraeghs/minimal-doc.git
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
make html

My index.rst:

minimal-doc documentation
=========================

.. only:: html

    hello world

    .. only:: not text

        .. doxygenfile:: component.c

Environment Information

Platform:              linux; (Linux-6.8.0-45-generic-x86_64-with-glibc2.35)
Python version:        3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0])
Python implementation: CPython
Sphinx version:        8.1.3
Docutils version:      0.21.2
Jinja2 version:        3.1.2
Pygments version:      2.18.0

Sphinx extensions

["breathe"]

Additional context

The following made me realize that this is likely a bug in sphinx and not in breathe: https://github.com/sphinx-doc/sphinx/pull/10502

I can use directives of other Sphinx plugins in a nested only-directive. The crash is specific to the directives of the breathe plugin. The version of docutils doesn't seem to matter.

ArnaudD-FR commented 3 days ago

I got this error to with the following minimalist doc: My index.rst

=======
World 1
=======

.. only:: hello

   .. only:: foo

      Hello foo
      =========

Command output:

$ sphinx-build -W -b html -t hello -t foo . _build

Running Sphinx v7.4.7
loading translations [en]... done
making output directory... done
Converting `source_suffix = ['.rst']` to `source_suffix = {'.rst': 'restructuredtext'}`.
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... 
copying static files... done
copying extra files... done
copying assets: done
writing output... [100%] index
Warning, treated as error:
/home/arnaud/dev/sphinx_only/<partial node>::unknown node type: <only: <list_item...>>