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 de19354
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Deprecated
Features added
--------------

* #12727: build: Allow --pdb to debug warnings when --fail-on-warning is specified.
Patch by Jeremy Maitin-Shepard.

Bugs fixed
----------

Expand Down
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 de19354

Please sign in to comment.