Skip to content

Commit

Permalink
docs: Add 'app' to checks, and disabled two. (#420)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaximilianSoerenPollak authored Feb 19, 2025
1 parent 9c05877 commit 6298b15
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
---
Expand All @@ -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.
Expand Down
163 changes: 85 additions & 78 deletions docs/_tooling/extensions/score_metamodel/checks/standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,84 +85,91 @@ 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)

# 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)
# ╭──────────────────────────────────────────────────────────────────────────────╮
# │ 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 │
# ╰──────────────────────────────────────────────────────────────────────────────╯


def my_pie_linked_standard_requirements(needs, results, **kwargs):
Expand Down

0 comments on commit 6298b15

Please sign in to comment.