-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
In SciPy we had a bug where using pydata-sphinx-theme in serial builds was fine, but in parallel builds a jinja context did some incorrect HTML replacement. The short version is that the PST function looks for the ancestors of a given page using _get_toctree_ancestors(env.toctree_includes, pagename) and decides based on the ancestors what HTML to show.
In the correct-behavior case, which always happens in serial mode and sometimes happens in parallel mode, for the reference/cluster.hierarchy page we get what you'd expect:
ancestors=['reference/cluster.hierarchy', 'reference/cluster', 'reference/index']
In the incorrect case, which happens non-deterministically in parallel builds only, we get:
ancestors=['reference/cluster.hierarchy', 'reference/cluster', 'reference/index', 'dev/contributor/contributor_toc', 'dev/index']
You can see the addition of 'dev/contributor/contributor_toc' -- this isn't entirely unreasonable because reference/index is added to a hidden toctree of that page. But it does deviate from the serial behavior to have those in there.
I wonder if it's perhaps due to when the forked reading subprocesses return, and which env gets merged into which (and what takes precedence). There is also some setdefault code that could be involved. I'm not sure 🤷
How to Reproduce
After following SciPy's dev docs:
python dev.py doc -j6
or if you don't want it to build but have SciPy and pydata-sphinx-theme installed, clone SciPy main (before scipy/scipy#20897 gets merged, like on scipy/scipy@9d543ae) and then enter the doc dir and do:
python -msphinx -WT --keep-going -b html -d build/doctrees -E source build/html -j6
it will complain about bad refs and stuff but then if you inspect the output you might see the incorrect behavior (left) or the correct behavior (right) 🎲 :
| Incorrect | Correct |
|---|---|
![]() |
![]() |
Environment Information
Tried on latest `master` and Sphinx 5.3. Replicated on macOS but originally seen on Linux in CIs. Tried with Python 3.11 and 3.12, etc.
Sphinx extensions
I commented out a few of them to speed up the build but ultimately used:
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.intersphinx',
'numpydoc',
'sphinx_design',
'doi_role',
'matplotlib.sphinxext.plot_directive',Additional context
No response

