Skip to content

Commit 7f7a000

Browse files
committed
Give reason when ignoring directories under page_dir
1 parent 55a8e1c commit 7f7a000

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

ford/pagetree.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,25 @@ def __iter__(self):
106106
return iter(retlist)
107107

108108

109-
def is_excluded_dir(path: Path, settings: ProjectSettings) -> bool:
109+
def is_excluded_dir(path: Path, settings: ProjectSettings) -> Optional[str]:
110110
"""Should `path` be excluded from the pagetree?"""
111-
paths_to_exclude: set[Path] = {
112-
path
113-
for path in [settings.graph_dir, settings.media_dir, settings.output_dir]
114-
if path is not None
115-
}
116-
paths_to_exclude.update(settings.html_template_dir)
117-
paths_to_exclude.update(settings.src_dir)
118111

119-
return path in paths_to_exclude
112+
if path == settings.graph_dir:
113+
return "it is set as 'graph_dir'"
114+
115+
if path == settings.media_dir:
116+
return "it is set as 'media_dir'"
117+
118+
if path == settings.output_dir:
119+
return "it is set as 'output_dir'"
120+
121+
if path in settings.html_template_dir:
122+
return "it is set as 'html_template_dir'"
123+
124+
if path in settings.src_dir:
125+
return "it is set as 'src_dir'"
126+
127+
return None
120128

121129

122130
def get_page_tree(
@@ -134,13 +142,19 @@ def get_page_tree(
134142
# I will use this later to remove duplicates from a list in a short way.
135143
from collections import OrderedDict
136144

137-
if is_excluded_dir(topdir, settings):
138-
# Would be nice to be able to report if directory was excluded and why
139-
return None
140-
141145
# look for files within topdir
142146
index_file = topdir / "index.md"
143147

148+
# Ignore Ford directories if they're under `page_dir`, giving a warning if
149+
# there's an `index.md` under them
150+
if (reason := is_excluded_dir(topdir, settings)) is not None:
151+
if index_file.exists():
152+
warn(
153+
f"Ignoring '{topdir}' from pages, because {reason}.\n"
154+
f" Either remove '{index_file}' or move it to another directory\n"
155+
)
156+
return None
157+
144158
if not index_file.exists():
145159
warn(f"'{index_file}' does not exist")
146160
return None

test/test_pagetree.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,20 @@ def test_non_utf8_encoding(tmp_path):
104104
def test_exclude_ford_dirs(tmp_path, capsys):
105105
"""Test that we exclude some user-settable directories"""
106106

107-
with open(tmp_path / "index.md", "w") as f:
108-
f.write("title: Index")
107+
(tmp_path / "index.md").write_text("title: Index")
109108

110109
media_dir: Path = tmp_path / "media"
111110
media_dir.mkdir(parents=True)
112111

112+
graph_dir: Path = tmp_path / "graph"
113+
graph_dir.mkdir(parents=True)
114+
(graph_dir / "index.md").write_text("title: Graphs")
115+
113116
md = MetaMarkdown()
114-
settings = ProjectSettings(media_dir=media_dir)
117+
settings = ProjectSettings(media_dir=media_dir, graph_dir=graph_dir)
115118
result_dir = tmp_path / "result"
116119
get_page_tree(tmp_path, result_dir, tmp_path / "doc", md, settings)
117120

118121
captured = capsys.readouterr().out.replace("\n", " ").replace(" ", " ")
119122
assert f"'{media_dir / 'index.md'}' does not exist" not in captured
123+
assert f"Ignoring '{graph_dir}'" in captured

0 commit comments

Comments
 (0)