Skip to content

Commit 0c52892

Browse files
cmarquAA-Turner
andauthored
Add SPHINX_AUTOBUILD_DEBUG to aid debugging (#192)
Co-authored-by: Adam Turner <[email protected]>
1 parent cc58cc1 commit 0c52892

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ or passing relevant ``filenames`` in addition to source and output directory in
167167

168168
__ https://github.com/sphinx-doc/sphinx-autobuild/issues/34
169169

170+
Debugging
171+
=========
172+
173+
If the ``SPHINX_AUTOBUILD_DEBUG`` environment variable is present,
174+
is not ``""`` (the empty string) or ``0``,
175+
and a file change is detected,
176+
its path and the currently active ignore expressions are printed.
177+
This is to help setting up the ignore expressions correctly.
178+
170179
Acknowledgements
171180
================
172181

sphinx_autobuild/filter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import fnmatch
6+
import os
67
import re
78
from pathlib import Path
89

@@ -23,6 +24,11 @@ def __repr__(self):
2324
def __call__(self, filename: str, /):
2425
"""Determine if 'path' should be ignored."""
2526
normalised_path = Path(filename).resolve().as_posix()
27+
if os.getenv("SPHINX_AUTOBUILD_DEBUG") not in {None, "", "0"}:
28+
print(
29+
f"SPHINX_AUTOBUILD_DEBUG: {normalised_path!r} has changed; "
30+
f"ignores are {self}"
31+
)
2632
# Any regular pattern matches.
2733
for pattern in self.regular_patterns:
2834
# separators are normalised before creating the IgnoreFilter

tests/test_ignore.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
3+
import pytest
4+
15
from sphinx_autobuild.filter import IgnoreFilter
26

37

@@ -72,3 +76,16 @@ def test_multiple_both():
7276
assert ignored("foo/random.txt")
7377
assert ignored("foo/module.pyc")
7478
assert ignored("bar/__pycache__/file.pyc")
79+
80+
81+
@pytest.mark.parametrize("val", [None, "0", "", "y", "1", "whatever"])
82+
def test_debug(val, capfd):
83+
if val is not None:
84+
os.environ["SPHINX_AUTOBUILD_DEBUG"] = val
85+
ignore_handler = IgnoreFilter([], [])
86+
ignore_handler("dummyfile")
87+
captured = capfd.readouterr()
88+
if val in ("y", "1", "whatever"):
89+
assert "SPHINX_AUTOBUILD_DEBUG" in captured.out
90+
else:
91+
assert "SPHINX_AUTOBUILD_DEBUG" not in captured.out

0 commit comments

Comments
 (0)