Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRS: Explicitly list files to render #2415

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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-????.???",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"pep-????.???",
"pep-[0-9][0-9][0-9][0-9].rst",
"pep-[0-9][0-9][0-9][0-9].txt",

More precise; right now it will pick up anything starting with pep- and four characters, with any standard three-character extension. E.g. pep-0001.bak, pep-data.pkl, pep-0012.tmp, pep-help.rst, etc. This just detects PEPs that match the format in PEP 1/ PEP 12.

# PEP ancillary files
"pep-????/*.rst",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"pep-????/*.rst",
"pep-[0-9][0-9][0-9][0-9]/*.rst",

More precise like the above; right now any rst files in a directory named pep- and four characters will be picked up, e.g. pep-help/. pep-temp/, etc. This only detects directories that match the format in PEP 1/PEP 12.

# 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 -------------------------------------------------
Expand Down
32 changes: 32 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 @@ -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():
Expand Down