Skip to content

Commit

Permalink
PRS: Explicitly list files to render
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Mar 11, 2022
1 parent 1a79345 commit f0115c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
21 changes: 0 additions & 21 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions pep_sphinx_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f0115c5

Please sign in to comment.