Skip to content

Commit e3337c7

Browse files
authored
Update include_patterns implementation (#10680)
1 parent 89db13d commit e3337c7

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

doc/usage/configuration.rst

-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ General configuration
233233
- ``'**/doc'`` -- all ``doc`` directories (this might be useful if
234234
documentation is co-located with source files)
235235

236-
:confval:`include_patterns` is also consulted when looking for static files
237-
in :confval:`html_static_path` and :confval:`html_extra_path`.
238-
239236
.. versionadded:: 5.1
240237

241238
.. confval:: templates_path

sphinx/builders/html/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ def onerror(filename: str, error: Exception) -> None:
840840
logger.warning(__('Failed to copy a file in html_static_file: %s: %r'),
841841
filename, error)
842842

843-
excluded = Matcher(self.config.exclude_patterns + ["**/.*"],
844-
self.config.include_patterns)
843+
excluded = Matcher(self.config.exclude_patterns + ["**/.*"])
845844
for entry in self.config.html_static_path:
846845
copy_asset(path.join(self.confdir, entry),
847846
path.join(self.outdir, '_static'),
@@ -881,7 +880,7 @@ def copy_extra_files(self) -> None:
881880
"""copy html_extra_path files."""
882881
try:
883882
with progress_message(__('copying extra files')):
884-
excluded = Matcher(self.config.exclude_patterns, self.config.include_patterns)
883+
excluded = Matcher(self.config.exclude_patterns)
885884
for extra_path in self.config.html_extra_path:
886885
entry = path.join(self.confdir, extra_path)
887886
copy_asset(entry, self.outdir, excluded)

sphinx/directives/other.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def parse_content(self, toctree: addnodes.toctree) -> List[Node]:
8484
all_docnames.remove(self.env.docname) # remove current document
8585

8686
ret: List[Node] = []
87-
excluded = Matcher(self.config.exclude_patterns, self.config.include_patterns)
87+
excluded = Matcher(self.config.exclude_patterns)
8888
for entry in self.content:
8989
if not entry:
9090
continue

sphinx/environment/adapters/toctree.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def resolve(self, docname: str, builder: "Builder", toctree: addnodes.toctree,
7474
# interactions between marking and pruning the tree (see bug #1046).
7575

7676
toctree_ancestors = self.get_toctree_ancestors(docname)
77-
excluded = Matcher(self.env.config.exclude_patterns, self.env.config.include_patterns)
77+
included = Matcher(self.env.config.include_patterns)
78+
excluded = Matcher(self.env.config.exclude_patterns)
7879

7980
def _toctree_add_classes(node: Element, depth: int) -> None:
8081
"""Add 'toctree-l%d' and 'current' classes to the toctree."""
@@ -166,6 +167,8 @@ def _entries_from_toctree(toctreenode: addnodes.toctree, parents: List[str],
166167
# this is raised if the included file does not exist
167168
if excluded(self.env.doc2path(ref, False)):
168169
message = __('toctree contains reference to excluded document %r')
170+
elif not included(self.env.doc2path(ref, False)):
171+
message = __('toctree contains reference to non-included document %r')
169172
else:
170173
message = __('toctree contains reference to nonexisting document %r')
171174

sphinx/ext/autosummary/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def run(self) -> List[Node]:
237237

238238
tree_prefix = self.options['toctree'].strip()
239239
docnames = []
240-
excluded = Matcher(self.config.exclude_patterns, self.config.include_patterns)
240+
excluded = Matcher(self.config.exclude_patterns)
241241
filename_map = self.config.autosummary_filename_map
242242
for _name, _sig, _summary, real_name in items:
243243
real_name = filename_map.get(real_name, real_name)

sphinx/project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def discover(self, exclude_paths: Iterable[str] = (),
3838
self.docnames = set()
3939
for filename in get_matching_files(
4040
self.srcdir,
41-
[*exclude_paths] + EXCLUDE_PATHS,
4241
include_paths,
42+
[*exclude_paths] + EXCLUDE_PATHS,
4343
):
4444
docname = self.path2doc(filename)
4545
if docname:

sphinx/util/matching.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class Matcher:
6464
For example, "**/index.rst" matches with "index.rst"
6565
"""
6666

67-
def __init__(self, exclude_patterns: Iterable[str],
68-
include_patterns: Iterable[str] = ()) -> None:
67+
def __init__(self, exclude_patterns: Iterable[str]) -> None:
6968
expanded = [pat[3:] for pat in exclude_patterns if pat.startswith('**/')]
7069
self.patterns = compile_matchers(list(exclude_patterns) + expanded)
7170

@@ -105,8 +104,8 @@ def patfilter(names: Iterable[str], pat: str) -> List[str]:
105104

106105
def get_matching_files(
107106
dirname: str,
107+
include_patterns: Iterable[str] = ("**",),
108108
exclude_patterns: Iterable[str] = (),
109-
include_patterns: Iterable[str] = ("**",)
110109
) -> Iterator[str]:
111110
"""Get all file names in a directory, recursively.
112111

tests/test_util_matching.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_get_matching_files_all(rootdir):
9898

9999

100100
def test_get_matching_files_all_exclude_single(rootdir):
101-
files = get_matching_files(rootdir / "test-root", ["**.html"])
101+
files = get_matching_files(rootdir / "test-root", exclude_patterns=["**.html"])
102102
assert sorted(files) == [
103103
'Makefile', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
104104
'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
@@ -112,7 +112,7 @@ def test_get_matching_files_all_exclude_single(rootdir):
112112

113113

114114
def test_get_matching_files_all_exclude_multiple(rootdir):
115-
files = get_matching_files(rootdir / "test-root", ["**.html", "**.inc"])
115+
files = get_matching_files(rootdir / "test-root", exclude_patterns=["**.html", "**.inc"])
116116
assert sorted(files) == [
117117
'Makefile', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
118118
'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
@@ -125,7 +125,7 @@ def test_get_matching_files_all_exclude_multiple(rootdir):
125125

126126

127127
def test_get_matching_files_all_exclude_nonexistent(rootdir):
128-
files = get_matching_files(rootdir / "test-root", ["halibut/**"])
128+
files = get_matching_files(rootdir / "test-root", exclude_patterns=["halibut/**"])
129129
assert sorted(files) == [
130130
'Makefile', '_templates/contentssb.html', '_templates/customsb.html',
131131
'_templates/layout.html', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
@@ -140,35 +140,35 @@ def test_get_matching_files_all_exclude_nonexistent(rootdir):
140140

141141

142142
def test_get_matching_files_all_include_single(rootdir):
143-
files = get_matching_files(rootdir / "test-root", [], ["subdir/**"])
143+
files = get_matching_files(rootdir / "test-root", include_patterns=["subdir/**"])
144144
assert sorted(files) == [
145145
'subdir/excluded.txt', 'subdir/images.txt', 'subdir/img.png', 'subdir/include.inc',
146146
'subdir/includes.txt', 'subdir/simg.png',
147147
]
148148

149149

150150
def test_get_matching_files_all_include_multiple(rootdir):
151-
files = get_matching_files(rootdir / "test-root", [], ["special/**", "subdir/**"])
151+
files = get_matching_files(rootdir / "test-root", include_patterns=["special/**", "subdir/**"])
152152
assert sorted(files) == [
153153
'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
154154
'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
155155
]
156156

157157

158158
def test_get_matching_files_all_include_nonexistent(rootdir):
159-
files = get_matching_files(rootdir / "test-root", [], ["halibut/**"])
159+
files = get_matching_files(rootdir / "test-root", include_patterns=["halibut/**"])
160160
assert sorted(files) == []
161161

162162

163163
def test_get_matching_files_all_include_prefix(rootdir):
164-
files = get_matching_files(rootdir / "test-root", [], ["autodoc*"])
164+
files = get_matching_files(rootdir / "test-root", include_patterns=["autodoc*"])
165165
assert sorted(files) == [
166166
'autodoc.txt', 'autodoc_target.py',
167167
]
168168

169169

170170
def test_get_matching_files_all_include_question_mark(rootdir):
171-
files = get_matching_files(rootdir / "test-root", [], ["img.???"])
171+
files = get_matching_files(rootdir / "test-root", include_patterns=["img.???"])
172172
assert sorted(files) == [
173173
'img.gif', 'img.pdf', 'img.png',
174174
]

0 commit comments

Comments
 (0)