Skip to content

Commit 79ca5bb

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

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

conf.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
sys.path.append(str(Path("pep_sphinx_extensions").absolute()))
1010

11+
# Add 'include_patterns' as a config variable
12+
from sphinx.config import Config
13+
Config.config_values['include_patterns'] = [], 'env', []
14+
del Config
15+
1116
# -- Project information -----------------------------------------------------
1217

1318
project = "PEPs"
@@ -25,24 +30,19 @@
2530
}
2631

2732
# List of patterns (relative to source dir) to ignore when looking for source files.
33+
include_patterns = [
34+
# Required for Sphinx
35+
"contents.rst",
36+
# PEP files
37+
"pep-????.???",
38+
# PEP ancillary files
39+
"pep-????/*.rst",
40+
# Documentation
41+
"docs/*.rst",
42+
]
2843
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",
44+
# PEP Template
45+
"pep-0012/pep-NNNN.rst",
4646
]
4747

4848
# -- Options for HTML output -------------------------------------------------

pep_sphinx_extensions/__init__.py

Lines changed: 32 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
@@ -16,6 +17,37 @@
1617

1718
if TYPE_CHECKING:
1819
from sphinx.application import Sphinx
20+
from sphinx.config import Config
21+
22+
23+
def find_files(self: environment.BuildEnvironment, config: Config, _b) -> None:
24+
"""Find all pep source files."""
25+
import fnmatch
26+
from pathlib import Path
27+
28+
root = Path(self.project.srcdir).absolute()
29+
self.project.docnames = set()
30+
for pattern in config.include_patterns:
31+
for path in root.glob(pattern):
32+
filename = str(path.relative_to(root))
33+
if any(fnmatch.fnmatch(filename, pattern) for pattern in config.exclude_patterns):
34+
continue
35+
36+
doc_name = self.project.path2doc(filename)
37+
if not doc_name:
38+
continue
39+
40+
if doc_name not in self.project.docnames:
41+
self.project.docnames.add(doc_name)
42+
continue
43+
44+
other_files = [str(f.relative_to(root)) for f in root.glob(f"{doc_name}.*")]
45+
project.logger.warning(
46+
f'multiple files found for the document "{doc_name}": {other_files!r}\n'
47+
f'Use {self.doc2path(doc_name)!r} for the build.', once=True)
48+
49+
50+
environment.BuildEnvironment.find_files = find_files
1951

2052

2153
def _depart_maths():

0 commit comments

Comments
 (0)