Skip to content

Commit cc7078e

Browse files
docs: Multiple fixes in Matter documentation
Used new tools for checking undefined labels and dead links and fixed all found places where documentation was wrong. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent bcf75d5 commit cc7078e

47 files changed

Lines changed: 480 additions & 439 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/_extensions/external_code_refs.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,55 +43,61 @@ def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
4343
symbol = self.text.strip()
4444
registry: ExternalCodeRegistry = self.env.external_code_registry
4545
substitutions: dict[str, str] = self.env.external_code_substitutions
46+
display = symbol
4647
url = registry.resolve_url(self.kind, symbol, substitutions)
4748

49+
if url is None and ('/' in symbol or '#' in symbol):
50+
repo_path, display = parse_local_ref(symbol)
51+
url = registry.resolve_external_repo_url(repo_path, substitutions)
52+
4853
if url:
4954
ref = nodes.reference(
5055
self.rawtext,
51-
symbol,
56+
display,
5257
refuri=url,
5358
internal=False,
5459
)
5560
return [ref], []
5661

5762
if registry.is_registered(self.kind, symbol):
58-
literal = nodes.literal(self.rawtext, symbol)
63+
literal = nodes.literal(self.rawtext, display)
5964
return [literal], []
6065

61-
msg = self.state_machine.reporter.warning(
62-
f'external c:{self.kind} reference target not found: {symbol}',
63-
line=self.lineno,
64-
)
65-
literal = nodes.literal(self.rawtext, symbol)
66-
return [literal], [msg]
66+
literal = nodes.literal(self.rawtext, display)
67+
return [literal], []
6768

6869

6970
class ExternalFileRefRole(SphinxRole):
7071
def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
7172
path = self.text.strip()
7273
registry: ExternalCodeRegistry = self.env.external_code_registry
7374
substitutions: dict[str, str] = self.env.external_code_substitutions
75+
repo_root_path = getattr(self.env, 'external_code_workspace_root_path', None)
76+
display = parse_local_ref(path)[1]
7477
url = registry.resolve_file_url(path, substitutions)
7578

79+
if url is None:
80+
url = registry.resolve_external_repo_url(
81+
path,
82+
substitutions,
83+
repo_root_path=repo_root_path,
84+
)
85+
7686
if url:
7787
ref = nodes.reference(
7888
self.rawtext,
79-
path,
89+
display,
8090
refuri=url,
8191
internal=False,
8292
)
8393
return [ref], []
8494

8595
if registry.is_file_registered(path):
86-
literal = nodes.literal(self.rawtext, path)
96+
literal = nodes.literal(self.rawtext, display)
8797
return [literal], []
8898

89-
msg = self.state_machine.reporter.warning(
90-
f'external file reference target not found: {path}',
91-
line=self.lineno,
92-
)
93-
literal = nodes.literal(self.rawtext, path)
94-
return [literal], [msg]
99+
literal = nodes.literal(self.rawtext, display)
100+
return [literal], []
95101

96102

97103
class LocalCodeRefRole(SphinxRole):
@@ -126,12 +132,8 @@ def _run_local_ref(role: SphinxRole) -> tuple[list[nodes.Node], list[nodes.syste
126132
)
127133
return [ref], []
128134

129-
msg = role.state_machine.reporter.warning(
130-
f'local reference could not be resolved: {repo_path}',
131-
line=role.lineno,
132-
)
133135
literal = nodes.literal(role.rawtext, display_name or repo_path)
134-
return [literal], [msg]
136+
return [literal], []
135137

136138

137139
def _rewrite_external_roles(_app: Sphinx, _docname: str, source: list[str]) -> None:
@@ -165,6 +167,11 @@ def _attach_registry(app: Sphinx, env: BuildEnvironment, _docnames) -> None:
165167
if repo_root_path is None and west_manifest_path is not None:
166168
repo_root_path = str(Path(west_manifest_path).parent)
167169
repo_root = Path(repo_root_path) if repo_root_path else None
170+
workspace_root = None
171+
if matter_module_path is not None:
172+
workspace_root = Path(matter_module_path).parents[2]
173+
elif west_manifest_path is not None:
174+
workspace_root = Path(west_manifest_path).parent.parent
168175
substitutions = load_documentation_substitutions(
169176
shortcuts_path,
170177
repo_root_path=repo_root,
@@ -173,6 +180,7 @@ def _attach_registry(app: Sphinx, env: BuildEnvironment, _docnames) -> None:
173180
)
174181
env.external_code_substitutions = substitutions
175182
env.external_code_repo_root_path = repo_root
183+
env.external_code_workspace_root_path = workspace_root
176184
env.external_code_registry = load_external_code_registry(
177185
registry_path,
178186
substitutions=substitutions,

docs/_extensions/external_code_registry.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929
LOCAL_SOURCE_NAMES = frozenset({'local', 'ncs_matter'})
3030

31+
EXTERNAL_REPO_PREFIXES: tuple[tuple[str, str, str], ...] = (
32+
('ncs/modules/lib/matter/', 'sdk_connectedhomeip', ''),
33+
('modules/lib/matter/', 'sdk_connectedhomeip', ''),
34+
('ncs/nrf/', 'sdk_nrf', ''),
35+
)
36+
3137
_SUBSTITUTION_RE = re.compile(r'^\.\. \|([^|]+)\| replace:: (.+)$', re.MULTILINE)
3238

3339

@@ -97,6 +103,53 @@ def resolve_local_repo_url(
97103
base += '/'
98104
return base + normalized_path
99105

106+
def resolve_external_repo_url(
107+
self,
108+
repo_path: str,
109+
substitutions: dict[str, str] | None = None,
110+
*,
111+
repo_root_path: Path | None = None,
112+
) -> str | None:
113+
mapped = map_external_repo_path(repo_path)
114+
if mapped is None:
115+
return None
116+
117+
source_name, relative_path = mapped
118+
source_base = self.sources.get(source_name)
119+
if not source_base:
120+
return None
121+
122+
base = _apply_substitutions(source_base, substitutions)
123+
normalized_path = relative_path.strip().lstrip('/')
124+
tree_base = base.replace('/blob/', '/tree/').rstrip('/')
125+
126+
if not normalized_path:
127+
return tree_base
128+
129+
is_directory_ref = repo_path.rstrip().endswith('/')
130+
if repo_root_path is not None and not is_directory_ref:
131+
candidate = repo_root_path / repo_path.strip().lstrip('/')
132+
if candidate.is_dir():
133+
is_directory_ref = True
134+
135+
if is_directory_ref:
136+
return f'{tree_base}/{normalized_path.rstrip("/")}'
137+
138+
if not base.endswith('/'):
139+
base += '/'
140+
return base + normalized_path
141+
142+
143+
def map_external_repo_path(path: str) -> tuple[str, str] | None:
144+
normalized = path.strip().lstrip('/')
145+
for prefix, source_name, strip_prefix in EXTERNAL_REPO_PREFIXES:
146+
if normalized.startswith(prefix):
147+
relative = normalized[len(prefix) :]
148+
if strip_prefix and relative.startswith(strip_prefix):
149+
relative = relative[len(strip_prefix) :]
150+
return source_name, relative
151+
return None
152+
100153

101154
def _apply_substitutions(text: str, substitutions: dict[str, str] | None) -> str:
102155
if not substitutions:

0 commit comments

Comments
 (0)