sphinx-doc / sphinx

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

NotImplementedError: <class 'sphinx_math_dollar.extension.MathDollarReplacer'> visiting unknown node type: pending_xref_condition #11121

Open randolf-scholz opened 1 year ago

randolf-scholz commented 1 year ago

Describe the bug

Sphinx doesn't want to play nice with sphinx-math-dollar. Probably related to https://github.com/sphinx-doc/sphinx/issues/9240. The problem seems to be that GenericNodeVisitor lacks a visit_pending_xref_condition method. After some digging I figured this is because Sphinx does not register pending_xref_condition as a node.

The relevant code sections are:

The issue seems to be that simply in https://github.com/sphinx-doc/sphinx/blob/e17f39e7b535f4849754d46f2cd2e411df8aa535/sphinx/addnodes.py#L521-L562 the statement app.add_node(pending_xref_condition) is missing.


I also tried the following, as per the sphinx-math-dollar documentation:

from sphinx_math_dollar import NODE_BLACKLIST
from docutils.nodes import header
from sphinx.addnodes import pending_xref_condition
math_dollar_debug = True
math_dollar_node_blacklist = NODE_BLACKLIST + (header, pending_xref_condition)

which didn't change anything, because pending_xref_condition is not registered as a node.

How to Reproduce

Will provide if necessary

Environment Information

bug report ```text # Platform: linux; (Linux-6.0.0-1009-oem-x86_64-with-glibc2.35) # Sphinx version: 6.1.2 # Python version: 3.10.8 (CPython) # Docutils version: 0.19 # Jinja2 version: 3.1.2 # Pygments version: 2.14.0 # Last messages: # reading sources... [ 5%] apidoc/modules # reading sources... [ 6%] apidoc/xxxx # reading sources... [ 7%] apidoc/xxxx.config # # ====================== slowest reading durations ======================= # 0.084 RECIPES # 0.012 CHANGELOG # 0.008 apidoc/xxxx # 0.007 README # 0.007 CONTRIBUTING # Loaded extensions: # sphinx.ext.mathjax (6.1.2) # sphinxcontrib.applehelp (1.0.3) # sphinxcontrib.devhelp (1.0.2) # sphinxcontrib.htmlhelp (2.0.0) # sphinxcontrib.serializinghtml (1.1.5) # sphinxcontrib.qthelp (1.0.3) # alabaster (0.7.12) # sphinx.ext.autodoc.preserve_defaults (6.1.2) # sphinx.ext.autodoc.type_comment (6.1.2) # sphinx.ext.autodoc.typehints (6.1.2) # sphinx.ext.autodoc (6.1.2) # sphinx.ext.autosectionlabel (6.1.2) # sphinx.ext.autosummary (6.1.2) # sphinx.ext.coverage (6.1.2) # sphinx.ext.doctest (6.1.2) # sphinx.ext.duration (6.1.2) # sphinx.ext.intersphinx (6.1.2) # sphinx.ext.napoleon (6.1.2) # sphinx.ext.todo (6.1.2) # sphinx.ext.viewcode (6.1.2) # sphinx_copybutton (0.5.1) # sphinx_math_dollar (unknown version) # pydata_sphinx_theme (unknown version) # Traceback: Traceback (most recent call last): File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/cmd/build.py", line 284, in build_main app.build(args.force_all, args.filenames) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/application.py", line 347, in build self.builder.build_update() File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 311, in build_update self.build(to_build, File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 327, in build updated_docnames = set(self.read()) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 434, in read self._read_serial(docnames) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 455, in _read_serial self.read_doc(docname) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 511, in read_doc publisher.publish() File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/core.py", line 226, in publish self.apply_transforms() File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/core.py", line 206, in apply_transforms self.document.transformer.apply_transforms() File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx/transforms/__init__.py", line 80, in apply_transforms super().apply_transforms() File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/transforms/__init__.py", line 173, in apply_transforms transform.apply(**kwargs) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/sphinx_math_dollar/extension.py", line 80, in apply self.document.walk(MathDollarReplacer(self.document)) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 150, in walk if child.walk(visitor): File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 150, in walk if child.walk(visitor): File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 150, in walk if child.walk(visitor): [Previous line repeated 6 more times] File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 142, in walk visitor.dispatch_visit(self) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 2005, in dispatch_visit return method(node) File "/home/rscholz/Projects/KIWI/xxxx/.venv/lib/python3.10/site-packages/docutils/nodes.py", line 2028, in unknown_visit raise NotImplementedError( NotImplementedError: visiting unknown node type: pending_xref_condition ```

Sphinx extensions

see bug report

Additional context

No response

AA-Turner commented 1 year ago

Quoted from the closed PR:

AFAIK, the way sphinx-math-dollar works, is that it traveses all nodes, and whenever it encounters a text node tries to replace math $$ ... $$ with actual RST math-tags. So if there are these "hanging nodes" that should be no issue? (sorry I am not that familiar with the internals of sphinx and docutils).

This sounds like a bug in SMD -- can you link to discussion there of this issue please?

As @picnixz noted, this class is an internal implementation detail.

A

randolf-scholz commented 1 year ago

This sounds like a bug in SMD -- can you link to discussion there of this issue please?

I can create an issue there. As I already commented here, this resolution will mean that each and every extension that uses a NodeVisitor and doesn't implement unknown_visit is potentially broken.