Browse Source

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é <benjamin@zephyrproject.org>
pull/80595/head
Benjamin Cabé 8 months ago committed by Dan Kalowsky
parent
commit
3c83604b84
  1. 19
      doc/_extensions/zephyr/link-roles.py
  2. 3
      doc/conf.py

19
doc/_extensions/zephyr/link-roles.py

@ -9,7 +9,11 @@ from __future__ import unicode_literals
import re import re
import subprocess import subprocess
from docutils import nodes from docutils import nodes
from pathlib import Path
from sphinx.util import logging from sphinx.util import logging
from typing import Final
ZEPHYR_BASE: Final[str] = Path(__file__).parents[3]
try: try:
import west.manifest import west.manifest
@ -43,6 +47,7 @@ def setup(app):
app.add_config_value("link_roles_manifest_baseurl", None, "env") app.add_config_value("link_roles_manifest_baseurl", None, "env")
app.add_config_value("link_roles_manifest_project", None, "env") app.add_config_value("link_roles_manifest_project", None, "env")
app.add_config_value("link_roles_manifest_project_broken_links_ignore_globs", [], "env")
# The role just creates new nodes based on information in the # The role just creates new nodes based on information in the
# arguments; its behavior doesn't depend on any other documents. # arguments; its behavior doesn't depend on any other documents.
@ -59,7 +64,8 @@ def modulelink(default_module=None, format="blob"):
rev = get_github_rev() rev = get_github_rev()
config = inliner.document.settings.env.app.config config = inliner.document.settings.env.app.config
baseurl = config.link_roles_manifest_baseurl baseurl = config.link_roles_manifest_baseurl
trace = f"at '{inliner.parent.source}', line {lineno}" source, line = inliner.reporter.get_source_and_line(lineno)
trace = f"at '{source}:{line}'"
m = re.search(r"(.*)\s*<(.*)>", text) m = re.search(r"(.*)\s*<(.*)>", text)
if m: if m:
@ -99,6 +105,17 @@ def modulelink(default_module=None, format="blob"):
f"Configuration value `link_roles_manifest_baseurl` not set\n\t{trace}" f"Configuration value `link_roles_manifest_baseurl` not set\n\t{trace}"
) )
if module == config.link_roles_manifest_project:
p = Path(source).relative_to(inliner.document.settings.env.srcdir)
if not any(
p.match(glob)
for glob in config.link_roles_manifest_project_broken_links_ignore_globs
):
if not Path(ZEPHYR_BASE, link).exists():
logger.warning(
f"{link} not found in {config.link_roles_manifest_project} {trace}"
)
url = f"{baseurl}/{format}/{rev}/{link}" url = f"{baseurl}/{format}/{rev}/{link}"
node = nodes.reference(rawtext, link_text, refuri=url, **options) node = nodes.reference(rawtext, link_text, refuri=url, **options)
return [node], [] return [node], []

3
doc/conf.py

@ -258,6 +258,9 @@ html_redirect_pages = redirects.REDIRECTS
# -- Options for zephyr.link-roles ---------------------------------------- # -- Options for zephyr.link-roles ----------------------------------------
link_roles_manifest_project = "zephyr" link_roles_manifest_project = "zephyr"
link_roles_manifest_project_broken_links_ignore_globs = [
"releases/release-notes-[123].*.rst",
]
link_roles_manifest_baseurl = "https://github.com/zephyrproject-rtos/zephyr" link_roles_manifest_baseurl = "https://github.com/zephyrproject-rtos/zephyr"
# -- Options for notfound.extension --------------------------------------- # -- Options for notfound.extension ---------------------------------------

Loading…
Cancel
Save