From 7639a17c11690f3f3a1b39e8d4bb185aa9ab5ac2 Mon Sep 17 00:00:00 2001 From: Maximilian Pollak Date: Wed, 19 Feb 2025 10:00:14 +0100 Subject: [PATCH 1/2] docs: Add 'app' to checks, and disabled two. Added the 'app' argument to missing checks. Disabled two checks which aren't possible to be fulfilled at the moment. Reverted deletion of ignoring '..._back' options Ref: closes #419 --- .../score_metamodel/checks/check_options.py | 5 +- .../checks/id_format_and_length.py | 5 +- .../score_metamodel/checks/standards.py | 162 +++++++++--------- 3 files changed, 92 insertions(+), 80 deletions(-) diff --git a/docs/_tooling/extensions/score_metamodel/checks/check_options.py b/docs/_tooling/extensions/score_metamodel/checks/check_options.py index 21c9cd828..4af9cc4bd 100644 --- a/docs/_tooling/extensions/score_metamodel/checks/check_options.py +++ b/docs/_tooling/extensions/score_metamodel/checks/check_options.py @@ -141,11 +141,14 @@ def check_extra_options( + list(optional_options.keys()) + default_options_list ) + # print("=================") + # print(allowed_options) + # pritn("===============\n\n") extra_options = [ option for option in list(need.keys()) - if option not in allowed_options and need[option] not in [None, {}, "", []] + if option not in allowed_options and need[option] not in [None, {}, "", []] and not option.endswith("_back") ] if extra_options: diff --git a/docs/_tooling/extensions/score_metamodel/checks/id_format_and_length.py b/docs/_tooling/extensions/score_metamodel/checks/id_format_and_length.py index 5b1e41491..c3f69e9f5 100644 --- a/docs/_tooling/extensions/score_metamodel/checks/id_format_and_length.py +++ b/docs/_tooling/extensions/score_metamodel/checks/id_format_and_length.py @@ -13,13 +13,14 @@ import os from sphinx_needs.data import NeedsInfoType +from sphinx.application import Sphinx from score_metamodel import CheckLogger, local_check # req-Id: TOOL_REQ__toolchain_sphinx_needs_build__requirement_attributes_uid @local_check -def check_id_format(need: NeedsInfoType, log: CheckLogger): +def check_id_format(app: Sphinx, need: NeedsInfoType, log: CheckLogger): """ Checking if the title, directory and feature are included in the requirement id or not. --- @@ -38,7 +39,7 @@ def check_id_format(need: NeedsInfoType, log: CheckLogger): @local_check -def check_id_length(need: NeedsInfoType, log: CheckLogger): +def check_id_length(app: Sphinx, need: NeedsInfoType, log: CheckLogger): """ Validates that the requirement ID does not exceed the hard limit of 40 characters. While the recommended limit is 30 characters, this check enforces a strict maximum of 40 characters. diff --git a/docs/_tooling/extensions/score_metamodel/checks/standards.py b/docs/_tooling/extensions/score_metamodel/checks/standards.py index 2ea37ec90..676ef4db7 100644 --- a/docs/_tooling/extensions/score_metamodel/checks/standards.py +++ b/docs/_tooling/extensions/score_metamodel/checks/standards.py @@ -85,84 +85,92 @@ def get_compliance_wp_needs(needs) -> set: } -@graph_check -def check_all_standard_req_linked_item_via_the_compliance_req( - app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger -): - """ - Checks if all standard requirements are linked to an item via the compliance_req tag. - Logs a warning for each unlinked standard requirement. - """ - standards_needs = get_standards_needs(needs) - compliance_req_needs = get_compliance_req_needs(needs) - - for need in standards_needs.values(): - if need["id"] not in compliance_req_needs: - msg = f"Standard requirement `{need['id']}` is not linked to at least one item via the complies tag. \n" - log.warning_for_option(need, "id", msg) - - -@graph_check -def check_all_standard_workproducts_linked_item_via_the_compliance_wp( - app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger -): - """ - Checks if all standard work products are linked to an item via the complies tag. - Logs a warning for each unlinked standard work product. - """ - standards_workproducts = get_standards_workproducts(needs) - compliance_wp_needs = get_compliance_wp_needs(needs) - - for need in standards_workproducts.values(): - if need["id"] not in compliance_wp_needs: - msg = ( - f"Standard workproduct `{need['id']}` is not linked to at least one item " - f"via the complies tag. \n" - ) - log.warning_for_option(need, "id", msg) - - -@graph_check -def check_workproduct_uniqueness_over_workflows( - app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger -): - """ - Check if all workproducts are contained in exactly one workflow. - Logs workflow IDs when a workproduct is contained in multiple workflows. - """ - all_workflows = get_workflows(needs) - all_workproducts = get_workproducts(needs) - - # Map to track counts for each workproduct and their associated workflows - workproduct_analysis = { - wp["id"]: {"count": 0, "workproduct": wp, "workflows": []} - for wp in all_workproducts.values() - } - - # Iterate over workflows and update the counts and workflows - for workflow_id, workflow in all_workflows.items(): - for output in workflow["output"]: - # If the workproduct is in the analysis, increment its count and add the workflow_id - if output in workproduct_analysis: - workproduct_analysis[output]["count"] += 1 - workproduct_analysis[output]["workflows"].append(workflow_id) +# ╭──────────────────────────────────────────────────────────────────────────────╮ +# │ Disabled temporarly │ +# ╰──────────────────────────────────────────────────────────────────────────────╯ +# @graph_check +# def check_all_standard_req_linked_item_via_the_compliance_req( +# app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger +# ): +# """ +# Checks if all standard requirements are linked to an item via the compliance_req tag. +# Logs a warning for each unlinked standard requirement. +# """ +# standards_needs = get_standards_needs(needs) +# compliance_req_needs = get_compliance_req_needs(needs) +# +# for need in standards_needs.values(): +# if need["id"] not in compliance_req_needs: +# msg = f"Standard requirement `{need['id']}` is not linked to at least one item via the complies tag. \n" +# log.warning_for_option(need, "id", msg) +# +# @graph_check +# def check_all_standard_workproducts_linked_item_via_the_compliance_wp( +# app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger +# ): +# """ +# Checks if all standard work products are linked to an item via the complies tag. +# Logs a warning for each unlinked standard work product. +# """ +# standards_workproducts = get_standards_workproducts(needs) +# compliance_wp_needs = get_compliance_wp_needs(needs) +# +# for need in standards_workproducts.values(): +# if need["id"] not in compliance_wp_needs: +# msg = ( +# f"Standard workproduct `{need['id']}` is not linked to at least one item " +# f"via the complies tag. \n" +# ) +# log.warning_for_option(need, "id", msg) +# +# +# @graph_check +# def check_workproduct_uniqueness_over_workflows( +# app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger +# ): +# """ +# Check if all workproducts are contained in exactly one workflow. +# Logs workflow IDs when a workproduct is contained in multiple workflows. +# """ +# all_workflows = get_workflows(needs) +# all_workproducts = get_workproducts(needs) +# +# # Map to track counts for each workproduct and their associated workflows +# workproduct_analysis = { +# wp["id"]: {"count": 0, "workproduct": wp, "workflows": []} +# for wp in all_workproducts.values() +# } +# +# # Iterate over workflows and update the counts and workflows +# for workflow_id, workflow in all_workflows.items(): +# for output in workflow["output"]: +# # If the workproduct is in the analysis, increment its count and add the workflow_id +# if output in workproduct_analysis: +# workproduct_analysis[output]["count"] += 1 +# workproduct_analysis[output]["workflows"].append(workflow_id) +# +# # Check for mismatches and log error +# for analysis in workproduct_analysis.values(): +# count = analysis["count"] +# workproduct = analysis["workproduct"] +# workflows = analysis["workflows"] +# +# if count != 1: # Mismatch found +# if count == 0: +# msg = "is not contained in any workflow, which is incorrect. \n" +# log.warning_for_need(workproduct, msg) +# else: +# workflows_str = ", ".join( +# f"`{workflow}`" for workflow in workflows +# ) # Join workflow IDs into a string +# msg = f"is contained in {count} workflows: {workflows_str}, which is incorrect. \n" +# log.warning_for_need(workproduct, msg) +# +# +# ╭──────────────────────────────────────────────────────────────────────────────╮ +# │ END OF TEMP DISABLING │ +# ╰──────────────────────────────────────────────────────────────────────────────╯ - # Check for mismatches and log error - for analysis in workproduct_analysis.values(): - count = analysis["count"] - workproduct = analysis["workproduct"] - workflows = analysis["workflows"] - - if count != 1: # Mismatch found - if count == 0: - msg = "is not contained in any workflow, which is incorrect. \n" - log.warning_for_need(workproduct, msg) - else: - workflows_str = ", ".join( - f"`{workflow}`" for workflow in workflows - ) # Join workflow IDs into a string - msg = f"is contained in {count} workflows: {workflows_str}, which is incorrect. \n" - log.warning_for_need(workproduct, msg) def my_pie_linked_standard_requirements(needs, results, **kwargs): From c6c08f125c71f84e976b93b6681e30298d0bf581 Mon Sep 17 00:00:00 2001 From: Maximilian Pollak Date: Wed, 19 Feb 2025 10:20:03 +0100 Subject: [PATCH 2/2] docs: Added 'app' args to and removed two checks. Fixed formatting Ref: closes #419 --- .../extensions/score_metamodel/checks/check_options.py | 4 +++- docs/_tooling/extensions/score_metamodel/checks/standards.py | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/_tooling/extensions/score_metamodel/checks/check_options.py b/docs/_tooling/extensions/score_metamodel/checks/check_options.py index 4af9cc4bd..cc25b4924 100644 --- a/docs/_tooling/extensions/score_metamodel/checks/check_options.py +++ b/docs/_tooling/extensions/score_metamodel/checks/check_options.py @@ -148,7 +148,9 @@ def check_extra_options( extra_options = [ option for option in list(need.keys()) - if option not in allowed_options and need[option] not in [None, {}, "", []] and not option.endswith("_back") + if option not in allowed_options + and need[option] not in [None, {}, "", []] + and not option.endswith("_back") ] if extra_options: diff --git a/docs/_tooling/extensions/score_metamodel/checks/standards.py b/docs/_tooling/extensions/score_metamodel/checks/standards.py index 676ef4db7..297c3d18d 100644 --- a/docs/_tooling/extensions/score_metamodel/checks/standards.py +++ b/docs/_tooling/extensions/score_metamodel/checks/standards.py @@ -172,7 +172,6 @@ def get_compliance_wp_needs(needs) -> set: # ╰──────────────────────────────────────────────────────────────────────────────╯ - def my_pie_linked_standard_requirements(needs, results, **kwargs): """ Function to render the chart of check for standard requirements linked to at least an item via compliance-gd.