Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log differences in configuration from the pickled environment #12949

Merged
merged 9 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
from sphinx.transforms import SphinxTransformer
from sphinx.util import logging
from sphinx.util._files import DownloadFiles, FilenameUniqDict
from sphinx.util._serialise import stable_str
from sphinx.util._timestamps import _format_rfc3339_microseconds
from sphinx.util.docutils import LoggingReporter
from sphinx.util.i18n import CatalogRepository, docname_to_domain
from sphinx.util.nodes import is_translatable
from sphinx.util.osutil import _last_modified_time, canon_path, os_path

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Iterator
from collections.abc import Callable, Iterable, Iterator, Sequence
from pathlib import Path
from typing import Any, Literal

Expand Down Expand Up @@ -296,6 +297,27 @@ def _config_status(*, old_config: Config | None, new_config: Config) -> tuple[in
extension = f'{len(extensions)}'
return CONFIG_EXTENSIONS_CHANGED, f' ({extension!r})'

# Log any changes in configuration keys
if changed_keys := _differing_config_keys(old_config, new_config):
changed_num = len(changed_keys)
if changed_num == 1:
logger.info(
__('1 configuration option has changed: %s'),
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
changed_keys[0],
)
elif changed_num <= 10:
logger.info(
__('%d configuration options have changed: %s'),
changed_num,
', '.join(changed_keys),
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
)
else:
logger.info(
__('%d configuration options have changed: %s, ...'),
changed_num,
', '.join(changed_keys[:10]),
)
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved

# check if a config value was changed that affects how doctrees are read
for item in new_config.filter(frozenset({'env'})):
if old_config[item.name] != item.value:
Expand Down Expand Up @@ -714,6 +736,18 @@ def check_consistency(self) -> None:
self.events.emit('env-check-consistency', self)


def _differing_config_keys(old: Config, new: Config) -> Sequence[str]:
"""Return a sorted list of keys that differ between two config objects."""
old_vals = {c.name: c.value for c in old}
new_vals = {c.name: c.value for c in new}
not_in_both = old_vals.keys() ^ new_vals.keys()
different_values = {
key for key in old_vals.keys() & new_vals.keys()
if stable_str(old_vals[key]) != stable_str(new_vals[key])
}
return sorted(not_in_both | different_values)


def _traverse_toctree(
traversed: set[str],
parent: str | None,
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/_serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _stable_str_prep(obj: Any) -> dict[str, Any] | list[Any] | str:
return dict(obj)
if isinstance(obj, list | tuple | set | frozenset):
# Convert to a sorted list
return sorted(map(_stable_str_prep, obj))
return sorted(map(_stable_str_prep, obj), key=str)
if isinstance(obj, type | types.FunctionType):
# The default repr() of functions includes the ID, which is not ideal.
# We use the fully qualified name instead.
Expand Down