From 79ca5bb6fbe136c95db44cda0e3f157b8a32bade Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 12 Mar 2022 01:30:52 +0000 Subject: [PATCH 1/2] PRS: Explicitly list files to render --- conf.py | 34 +++++++++++++++---------------- pep_sphinx_extensions/__init__.py | 32 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/conf.py b/conf.py index 37e4f7b5bf2..446c8e34851 100644 --- a/conf.py +++ b/conf.py @@ -8,6 +8,11 @@ sys.path.append(str(Path("pep_sphinx_extensions").absolute())) +# Add 'include_patterns' as a config variable +from sphinx.config import Config +Config.config_values['include_patterns'] = [], 'env', [] +del Config + # -- Project information ----------------------------------------------------- project = "PEPs" @@ -25,24 +30,19 @@ } # List of patterns (relative to source dir) to ignore when looking for source files. +include_patterns = [ + # Required for Sphinx + "contents.rst", + # PEP files + "pep-????.???", + # PEP ancillary files + "pep-????/*.rst", + # Documentation + "docs/*.rst", +] 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", + # PEP Template + "pep-0012/pep-NNNN.rst", ] # -- Options for HTML output ------------------------------------------------- diff --git a/pep_sphinx_extensions/__init__.py b/pep_sphinx_extensions/__init__.py index e9d366ca196..d1726975a31 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 @@ -16,6 +17,37 @@ if TYPE_CHECKING: from sphinx.application import Sphinx + from sphinx.config import Config + + +def find_files(self: environment.BuildEnvironment, config: Config, _b) -> None: + """Find all pep source files.""" + import fnmatch + from pathlib import Path + + root = Path(self.project.srcdir).absolute() + self.project.docnames = set() + for pattern in config.include_patterns: + for path in root.glob(pattern): + filename = str(path.relative_to(root)) + if any(fnmatch.fnmatch(filename, pattern) for pattern in config.exclude_patterns): + continue + + doc_name = self.project.path2doc(filename) + if not doc_name: + continue + + if doc_name not in self.project.docnames: + self.project.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) + + +environment.BuildEnvironment.find_files = find_files def _depart_maths(): From 1f1f04edb71014baeab0e67ff0f9f6413da063c7 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 12 Mar 2022 22:09:08 +0000 Subject: [PATCH 2/2] Break to reST and plaintext --- conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf.py b/conf.py index 446c8e34851..3d39d1182be 100644 --- a/conf.py +++ b/conf.py @@ -34,7 +34,8 @@ # Required for Sphinx "contents.rst", # PEP files - "pep-????.???", + "pep-????.rst", + "pep-????.txt", # PEP ancillary files "pep-????/*.rst", # Documentation