Skip to content

Commit

Permalink
Do not generate redirects or error for files in Sphinx exclude_patterns
Browse files Browse the repository at this point in the history
Fixes wpilibsuite#59

Signed-off-by: Chance Zibolski <[email protected]>
  • Loading branch information
chancez committed Aug 13, 2024
1 parent dd1ee93 commit a873558
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sphinxext/rediraffe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sphinx.errors import ExtensionError
from sphinx.util import logging
from sphinx.util.console import green, red, yellow # pylint: disable=no-name-in-module
from sphinx.util.matching import Matcher

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -179,6 +180,7 @@ def build_redirects(app: Sphinx, exception: Union[Exception, None]) -> None:
graph_edges = rediraffe_redirects
elif isinstance(rediraffe_redirects, str):
# filename

path = Path(app.srcdir) / rediraffe_redirects
if not path.is_file():
logger.error(
Expand All @@ -188,7 +190,6 @@ def build_redirects(app: Sphinx, exception: Union[Exception, None]) -> None:
)
app.statuscode = 1
return

try:
graph_edges = create_graph(path)
except ExtensionError as e:
Expand Down Expand Up @@ -295,6 +296,7 @@ def init(self) -> None:

source_suffixes = set(self.app.config.source_suffix)
src_path = Path(self.app.srcdir)
excluded = Matcher(self.app.config.exclude_patterns)

rediraffe_redirects = self.app.config.rediraffe_redirects
redirects_path = None
Expand Down Expand Up @@ -374,6 +376,8 @@ def abs_path_in_src_dir_w_src_suffix(filename: str) -> Union[Path, None]:
deleted_files = list(filter(lambda x: x != None, deleted_files))

for deleted_file in deleted_files:
if excluded(str(deleted_file)):
continue
if deleted_file in absolute_redirects:
logger.info(
f"deleted file {deleted_file} redirects to {absolute_redirects[deleted_file]}."
Expand All @@ -387,6 +391,10 @@ def abs_path_in_src_dir_w_src_suffix(filename: str) -> Union[Path, None]:
for renamed_file in rename_hints:
hint_to, perc = rename_hints[renamed_file]


if excluded(str(renamed_file)):
continue

if renamed_file in absolute_redirects:
logger.info(
f"renamed file {renamed_file} redirects to {absolute_redirects[renamed_file]}."
Expand Down

0 comments on commit a873558

Please sign in to comment.