Skip to content

Commit 3c83604

Browse files
kartbendkalowsk
authored andcommitted
doc: extensions: check dead zephyr_file/zephyr_raw links
Add a check to ensure that all zephyr_file/zephyr_raw links are pointing to valid paths in the current zephyr tree. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 14d0a19 commit 3c83604

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

doc/_extensions/zephyr/link-roles.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import re
1010
import subprocess
1111
from docutils import nodes
12+
from pathlib import Path
1213
from sphinx.util import logging
14+
from typing import Final
15+
16+
ZEPHYR_BASE: Final[str] = Path(__file__).parents[3]
1317

1418
try:
1519
import west.manifest
@@ -43,6 +47,7 @@ def setup(app):
4347

4448
app.add_config_value("link_roles_manifest_baseurl", None, "env")
4549
app.add_config_value("link_roles_manifest_project", None, "env")
50+
app.add_config_value("link_roles_manifest_project_broken_links_ignore_globs", [], "env")
4651

4752
# The role just creates new nodes based on information in the
4853
# arguments; its behavior doesn't depend on any other documents.
@@ -59,7 +64,8 @@ def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
5964
rev = get_github_rev()
6065
config = inliner.document.settings.env.app.config
6166
baseurl = config.link_roles_manifest_baseurl
62-
trace = f"at '{inliner.parent.source}', line {lineno}"
67+
source, line = inliner.reporter.get_source_and_line(lineno)
68+
trace = f"at '{source}:{line}'"
6369

6470
m = re.search(r"(.*)\s*<(.*)>", text)
6571
if m:
@@ -99,6 +105,17 @@ def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
99105
f"Configuration value `link_roles_manifest_baseurl` not set\n\t{trace}"
100106
)
101107

108+
if module == config.link_roles_manifest_project:
109+
p = Path(source).relative_to(inliner.document.settings.env.srcdir)
110+
if not any(
111+
p.match(glob)
112+
for glob in config.link_roles_manifest_project_broken_links_ignore_globs
113+
):
114+
if not Path(ZEPHYR_BASE, link).exists():
115+
logger.warning(
116+
f"{link} not found in {config.link_roles_manifest_project} {trace}"
117+
)
118+
102119
url = f"{baseurl}/{format}/{rev}/{link}"
103120
node = nodes.reference(rawtext, link_text, refuri=url, **options)
104121
return [node], []

doc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
# -- Options for zephyr.link-roles ----------------------------------------
259259

260260
link_roles_manifest_project = "zephyr"
261+
link_roles_manifest_project_broken_links_ignore_globs = [
262+
"releases/release-notes-[123].*.rst",
263+
]
261264
link_roles_manifest_baseurl = "https://github.com/zephyrproject-rtos/zephyr"
262265

263266
# -- Options for notfound.extension ---------------------------------------

0 commit comments

Comments
 (0)