Skip to content

Commit d428a31

Browse files
committed
feat: add logging for existing links and warnings for missing needs in schema validation
1 parent ce37b35 commit d428a31

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

src/extensions/score_source_code_linker/__init__.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,38 @@ def find_need(all_needs: NeedsMutable, id: str) -> NeedItem | None:
318318
return all_needs.get(id)
319319

320320

321+
def _log_needs_with_existing_links(needs: NeedsMutable) -> None:
322+
"""Log needs that already have source_code_link or testlink set."""
323+
if LOGGER.getEffectiveLevel() >= 10:
324+
for id, need in needs.items():
325+
if need.get("source_code_link"):
326+
LOGGER.debug(
327+
f"?? Need {id} already has source_code_link: "
328+
f"{need.get('source_code_link')}"
329+
)
330+
if need.get("testlink"):
331+
LOGGER.debug(
332+
f"?? Need {id} already has testlink: {need.get('testlink')}"
333+
)
334+
335+
336+
def _warn_missing_need(source_code_links: SourceCodeLinks) -> None:
337+
"""Log warnings when a need referenced by source/test links is not found."""
338+
# TODO: print github annotations as in https://github.com/eclipse-score/bazel_registry/blob/7423b9996a45dd0a9ec868e06a970330ee71cf4f/tools/verify_semver_compatibility_level.py#L126-L129
339+
for n in source_code_links.links.CodeLinks:
340+
LOGGER.warning(
341+
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
342+
"in documentation [CODE LINK]",
343+
type="score_source_code_linker",
344+
)
345+
for n in source_code_links.links.TestLinks:
346+
LOGGER.warning(
347+
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
348+
"in documentation [TEST LINK]",
349+
type="score_source_code_linker",
350+
)
351+
352+
321353
# re-qid: gd_req__req__attr_impl
322354
def inject_links_into_needs(app: Sphinx, env: BuildEnvironment) -> None:
323355
"""
@@ -339,17 +371,7 @@ def inject_links_into_needs(app: Sphinx, env: BuildEnvironment) -> None:
339371
) # TODO: why do we create a copy? Can we also needs_copy = needs[:]? copy(needs)?
340372

341373
# Enabled automatically for DEBUGGING
342-
if LOGGER.getEffectiveLevel() >= 10:
343-
for id, need in needs.items():
344-
if need.get("source_code_link"):
345-
LOGGER.debug(
346-
f"?? Need {id} already has source_code_link: "
347-
f"{need.get('source_code_link')}"
348-
)
349-
if need.get("testlink"):
350-
LOGGER.debug(
351-
f"?? Need {id} already has testlink: {need.get('testlink')}"
352-
)
374+
_log_needs_with_existing_links(needs)
353375

354376
source_code_links_by_need = load_source_code_links_combined_json(
355377
get_cache_filename(app.outdir, "score_scl_grouped_cache.json")
@@ -358,19 +380,7 @@ def inject_links_into_needs(app: Sphinx, env: BuildEnvironment) -> None:
358380
for source_code_links in source_code_links_by_need:
359381
need = find_need(needs_copy, source_code_links.need)
360382
if need is None:
361-
# TODO: print github annotations as in https://github.com/eclipse-score/bazel_registry/blob/7423b9996a45dd0a9ec868e06a970330ee71cf4f/tools/verify_semver_compatibility_level.py#L126-L129
362-
for n in source_code_links.links.CodeLinks:
363-
LOGGER.warning(
364-
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
365-
"in documentation [CODE LINK]",
366-
type="score_source_code_linker",
367-
)
368-
for n in source_code_links.links.TestLinks:
369-
LOGGER.warning(
370-
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
371-
"in documentation [TEST LINK]",
372-
type="score_source_code_linker",
373-
)
383+
_warn_missing_need(source_code_links)
374384
continue
375385

376386
need_as_dict = cast(dict[str, object], need)

0 commit comments

Comments
 (0)