Clear record_dependencies for each document (#10855)

This commit is contained in:
Adam Turner 2022-09-24 00:31:26 +01:00 committed by GitHub
parent 73a1ee4560
commit 8db24515ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from typing import (TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Sequence
from docutils import nodes
from docutils.nodes import Node
from docutils.utils import DependencyList
from sphinx.config import Config
from sphinx.deprecation import RemovedInSphinx70Warning
@ -490,6 +491,9 @@ class Builder:
filename = self.env.doc2path(docname)
filetype = get_filetype(self.app.config.source_suffix, filename)
publisher = self.app.registry.get_publisher(self.app, filetype)
# record_dependencies is mutable even though it is in settings,
# explicitly re-initialise for each document
publisher.settings.record_dependencies = DependencyList()
with sphinx_domains(self.env), rst.default_role(docname, self.config.default_role):
# set up error_handler for the target document
codecs.register_error('sphinx', UnicodeDecodeErrorHandler(docname)) # type: ignore

View File

@ -0,0 +1,4 @@
API
===
.. automodule:: example_module

View File

@ -0,0 +1,5 @@
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc']

View File

@ -0,0 +1,2 @@
def example_function():
return 42

View File

@ -0,0 +1,3 @@
.. toctree::
api

View File

@ -0,0 +1,10 @@
"""Tests for ``record_dependencies``."""
import pytest
@pytest.mark.sphinx('html', testroot='environment-record-dependencies')
def test_record_dependencies_cleared(app):
app.builder.read()
assert app.env.dependencies['index'] == set()
assert app.env.dependencies['api'] == {'example_module.py'}