Skip to content

Commit

Permalink
Allow --pdb option to also debug warnings
Browse files Browse the repository at this point in the history
Previously, warnings emitted during reading and writing were deferred,
which made --pdb ineffective for debugging them.

With this change, warnings are no longer deferred when --pdb and
--fail-on-warning are both specified.
  • Loading branch information
jbms committed Aug 2, 2024
1 parent df871ab commit 11e1a85
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import codecs
import contextlib
import pickle
import re
import time
Expand Down Expand Up @@ -313,7 +314,9 @@ def build(
logger.info(bold(__('building [%s]: ')) + summary, self.name)

# while reading, collect all warnings from docutils
with logging.pending_warnings():
with contextlib.ExitStack() as exit_stack:
if not self.app.pdb or not self.app.warningiserror:
exit_stack.enter_context(logging.pending_warnings())
updated_docnames = set(self.read())

doccount = len(updated_docnames)
Expand Down Expand Up @@ -613,7 +616,9 @@ def write(
self._write_serial(sorted(docnames))

def _write_serial(self, docnames: Sequence[str]) -> None:
with logging.pending_warnings():
with contextlib.ExitStack() as exit_stack:
if not self.app.pdb or not self.app.warningiserror:
exit_stack.enter_context(logging.pending_warnings())
for docname in status_iterator(docnames, __('writing output... '), "darkgreen",
len(docnames), self.app.verbosity):
self.app.phase = BuildPhase.RESOLVING
Expand Down

0 comments on commit 11e1a85

Please sign in to comment.