Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add 'app' to checks, and disabled two. #420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 │
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, my great boxes, just ruined by the formatter. 😧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you could have just commented the @graph_check line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I did so first, but I thought this makes it more obvious and clearer that these are truly disabled by choice, not accident.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you will fix it soon in any case :-)

# ╰──────────────────────────────────────────────────────────────────────────────╯


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