Skip to content

Commit f0115c5

Browse files
committed
PRS: Explicitly list files to render
1 parent 1a79345 commit f0115c5

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

conf.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,6 @@
2424
".txt": "pep",
2525
}
2626

27-
# List of patterns (relative to source dir) to ignore when looking for source files.
28-
exclude_patterns = [
29-
# Windows:
30-
"Thumbs.db",
31-
".DS_Store",
32-
# Python:
33-
".venv",
34-
"venv",
35-
"requirements.txt",
36-
# Sphinx:
37-
"build",
38-
"output.txt", # Link-check output
39-
# PEPs:
40-
"pep-0012",
41-
"README.rst",
42-
"CONTRIBUTING.rst",
43-
"pep_sphinx_extensions/LICENCE.rst",
44-
# Miscellaneous
45-
".codespell",
46-
]
47-
4827
# -- Options for HTML output -------------------------------------------------
4928

5029
# HTML output settings

pep_sphinx_extensions/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from docutils.writers.html5_polyglot import HTMLTranslator
88
from sphinx import environment
9+
from sphinx import project
910

1011
from pep_sphinx_extensions.pep_processor.html import pep_html_builder
1112
from pep_sphinx_extensions.pep_processor.html import pep_html_translator
@@ -17,6 +18,36 @@
1718
if TYPE_CHECKING:
1819
from sphinx.application import Sphinx
1920

21+
INCLUDE_PATTERNS = ("contents.rst", "pep-????.???", "docs/*.rst")
22+
23+
24+
def _discover(self, _exclude_paths = None) -> set[str]:
25+
"""Find all pep files."""
26+
from pathlib import Path
27+
28+
root = Path(self.srcdir).absolute()
29+
self.docnames = set()
30+
for pattern in INCLUDE_PATTERNS:
31+
for path in root.glob(pattern):
32+
filename = str(path.relative_to(root))
33+
doc_name = self.path2doc(filename)
34+
if not doc_name:
35+
continue
36+
37+
if doc_name not in self.docnames:
38+
self.docnames.add(doc_name)
39+
continue
40+
41+
other_files = [str(f.relative_to(root)) for f in root.glob(f"{doc_name}.*")]
42+
project.logger.warning(
43+
f'multiple files found for the document "{doc_name}": {other_files!r}\n'
44+
f'Use {self.doc2path(doc_name)!r} for the build.', once=True)
45+
46+
return self.docnames
47+
48+
49+
project.Project.discover = _discover
50+
2051

2152
def _depart_maths():
2253
pass # No-op callable for the type checker

0 commit comments

Comments
 (0)