From f0115c58356e289657b71050c1c9d7d2ba7af991 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Fri, 11 Mar 2022 21:04:44 +0000 Subject: [PATCH] PRS: Explicitly list files to render --- conf.py | 21 --------------------- pep_sphinx_extensions/__init__.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/conf.py b/conf.py index 37e4f7b5bf2e..293e23f64d72 100644 --- a/conf.py +++ b/conf.py @@ -24,27 +24,6 @@ ".txt": "pep", } -# List of patterns (relative to source dir) to ignore when looking for source files. -exclude_patterns = [ - # Windows: - "Thumbs.db", - ".DS_Store", - # Python: - ".venv", - "venv", - "requirements.txt", - # Sphinx: - "build", - "output.txt", # Link-check output - # PEPs: - "pep-0012", - "README.rst", - "CONTRIBUTING.rst", - "pep_sphinx_extensions/LICENCE.rst", - # Miscellaneous - ".codespell", -] - # -- Options for HTML output ------------------------------------------------- # HTML output settings diff --git a/pep_sphinx_extensions/__init__.py b/pep_sphinx_extensions/__init__.py index e9d366ca196a..9bc1396c1888 100644 --- a/pep_sphinx_extensions/__init__.py +++ b/pep_sphinx_extensions/__init__.py @@ -6,6 +6,7 @@ from docutils.writers.html5_polyglot import HTMLTranslator from sphinx import environment +from sphinx import project from pep_sphinx_extensions.pep_processor.html import pep_html_builder from pep_sphinx_extensions.pep_processor.html import pep_html_translator @@ -17,6 +18,36 @@ if TYPE_CHECKING: from sphinx.application import Sphinx +INCLUDE_PATTERNS = ("contents.rst", "pep-????.???", "docs/*.rst") + + +def _discover(self, _exclude_paths = None) -> set[str]: + """Find all pep files.""" + from pathlib import Path + + root = Path(self.srcdir).absolute() + self.docnames = set() + for pattern in INCLUDE_PATTERNS: + for path in root.glob(pattern): + filename = str(path.relative_to(root)) + doc_name = self.path2doc(filename) + if not doc_name: + continue + + if doc_name not in self.docnames: + self.docnames.add(doc_name) + continue + + other_files = [str(f.relative_to(root)) for f in root.glob(f"{doc_name}.*")] + project.logger.warning( + f'multiple files found for the document "{doc_name}": {other_files!r}\n' + f'Use {self.doc2path(doc_name)!r} for the build.', once=True) + + return self.docnames + + +project.Project.discover = _discover + def _depart_maths(): pass # No-op callable for the type checker