Skip to content
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
10 changes: 4 additions & 6 deletions src/extensions/score_draw_uml_funcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
get_impl_comp_from_logic_iface,
get_interface_from_component,
get_interface_from_int,
get_logical_interface_real,
get_module,
get_real_interface_logical,
)
from sphinx.application import Sphinx
from sphinx_needs.logging import get_logger
Expand Down Expand Up @@ -97,10 +95,10 @@ def draw_comp_incl_impl_int(

:param dict[str,str] need: Component which should be drawn
:param dict all_needs: Dictionary containing all needs
:param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented interfaces
which were already processed during this cycle
:param dict[str,dict] proc_used_interfaces: Dictionary containing all used interfaces
which were already processed during this cycle
:param dict[str,dict] proc_impl_interfaces: Dictionary containing
all implemented interfaces which were already processed during this cycle
:param dict[str,dict] proc_used_interfaces: Dictionary containing
all used interfaces which were already processed during this cycle
"""
# Draw outer component
structure_text = f"{gen_struct_element('component', need)} {{\n"
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/score_draw_uml_funcs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def get_logical_interface_real(
logical_ifop_need = all_needs.get(logical_ifop[0])
if not logical_ifop_need:
logger.info(
f"{real_ifop}: Logical Interface Operation Need not defined, probably misspelled!"
f"{real_ifop}: Logical Interface Operation Need not defined, "
"probably misspelled!"
)
continue

Expand Down
1 change: 1 addition & 0 deletions src/extensions/score_header_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
from sphinx.application import Sphinx

from src.extensions.score_header_service.header_service import register


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
from unittest.mock import ANY, MagicMock, patch

import pytest
import src.extensions.score_header_service.header_service as hs
from sphinx.util.docutils import SphinxDirective

import src.extensions.score_header_service.header_service as hs


@pytest.fixture(scope="session", autouse=True)
def add_metadata(record_testsuite_property: Callable[[str, str | list[str]], None]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from unittest.mock import MagicMock, patch

import pytest
import src.extensions.score_header_service.header_service as hs
from pytest import TempPathFactory
from sphinx.testing.util import SphinxTestApp

Expand Down Expand Up @@ -85,8 +84,8 @@ def wrapper(use_github_data: bool = True):
"src.extensions.score_header_service",
]
needs_types = [
dict(title = "Review Header", directive = "review_header", color="#BFD8D2", style="node",
prefix = "review_header__"),
dict(title = "Review Header", directive = "review_header",
color="#BFD8D2", style="node", prefix = "review_header__"),
]
needs_id_regex = ".*"
needs_extra_options = [
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/score_layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def update_config(app: Sphinx, _config: Any):

# Setting HTML static path
# For now this seems the only place this is used / needed.
# In the future it might be a good idea to make this available in other places, maybe via the 'find_runfiles' lib
# In the future it might be a good idea to make this available in other places,
# maybe via the 'find_runfiles' lib
if r := os.getenv("RUNFILES_DIR"):
dirs = [str(x) for x in Path(r).glob("*score_docs_as_code+")]
if dirs:
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/score_layout/html_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def return_html_context(app: Sphinx) -> dict[str, str]:
and not app.config.html_context.get("github_repo")
):
return {
# still required for use_edit_page_button and other elements except version switcher
# still required for use_edit_page_button and other elements
# except version switcher
"github_user": "dummy",
"github_repo": "dummy",
"github_version": "main",
Expand Down
14 changes: 5 additions & 9 deletions src/extensions/score_metamodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def _run_checks(app: Sphinx, exception: Exception | None) -> None:
if exception:
return

# Filter out external needs, as checks are only intended to be run on internal needs.
# Filter out external needs, as checks are only intended to be run
# on internal needs.
needs_all_needs = SphinxNeedsData(app.env).get_needs_view()

logger.debug(f"Running checks for {len(needs_all_needs)} needs")
Expand Down Expand Up @@ -145,21 +146,21 @@ def is_check_enabled(check: local_check_function | graph_check_function):

if log.has_infos:
log.info(
"Some needs have issues related to the new checks. See the log for more information."
"Some needs have issues related to the new checks. "
"See the log for more information."
)
# TODO: exit code


def convert_checks_to_dataclass(checks_dict) -> list[ProhibitedWordCheck]:
prohibited_words_checks = [
return [
ProhibitedWordCheck(
name=check_name,
option_check={k: v for k, v in check_config.items() if k != "types"},
types=check_config.get("types", []),
)
for check_name, check_config in checks_dict.items()
]
return prohibited_words_checks


def load_metamodel_data():
Expand Down Expand Up @@ -190,11 +191,6 @@ def load_metamodel_data():
proh_checks_dict = data.get("prohibited_words_checks", {})
prohibited_words_checks = convert_checks_to_dataclass(proh_checks_dict)

# prohibited_words_checks= [ProhibitedWordCheck(**check) for check in pro_checks.values()]

# stop_words_list = global_base_options.get("prohibited_words", {}).get("title", [])
# weak_words_list = global_base_options.get("prohibited_words", {}).get("content", [])

# Default options by sphinx, sphinx-needs or anything else we need to account for
default_options_list = default_options()

Expand Down
21 changes: 15 additions & 6 deletions src/extensions/score_metamodel/checks/attributes_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ def check_id_format(app: Sphinx, need: NeedsInfoType, log: CheckLogger):
if id_parts_len != expected_parts:
msg = ""
if expected_parts == 2:
msg = "expected to consist of this format: `<Req Type>__<Abbreviations>`. Only one '__' is allowed in this need's id."
msg = (
"expected to consist of this format: `<Req Type>__<Abbreviations>`. "
"Only one '__' is allowed in this need's id."
)
elif expected_parts == 3:
msg = (
"expected to consist of this format: "
"`<Req Type>__<Abbreviations>__<Architectural Element>`. Only two '__' are allowed in this need's id."
"`<Req Type>__<Abbreviations>__<Architectural Element>`. "
"Only two '__' are allowed in this need's id."
)
log.warning_for_option(need, "id", msg)

Expand All @@ -56,8 +60,9 @@ def check_id_length(app: Sphinx, need: NeedsInfoType, log: CheckLogger):
While the recommended limit is 30 characters, this check enforces a strict maximum
of 45 characters.
If the ID exceeds 45 characters, a warning is logged specifying the actual length.
Any examples that are required to have 3 parts (2x'__') have an exception, and get 17 extra characters
to compensate for the lenght of `_example_feature_` that would be replaced by actually feature names.
Any examples that are required to have 3 parts (2x'__') have an exception,
and get 17 extra characters to compensate for the lenght of `_example_feature_`
that would be replaced by actually feature names.
---
"""
max_lenght = 45
Expand All @@ -67,7 +72,8 @@ def check_id_length(app: Sphinx, need: NeedsInfoType, log: CheckLogger):
if len(need["id"]) > max_lenght:
msg = (
f"exceeds the maximum allowed length of 45 characters "
f"(current length: {len(need['id']) if 'example_feature' not in need['id'] else len(need['id']) - 17})."
"(current length: "
f"{len(need['id']) if 'example_feature' not in need['id'] else len(need['id']) - 17})."
)
log.warning_for_option(need, "id", msg)

Expand All @@ -82,7 +88,10 @@ def _check_options_for_prohibited_words(
forbidden_words = prohibited_word_checks.option_check[option]
for word in need[option].split():
if word in forbidden_words:
msg = f"contains a weak word: `{word}` in option: `{option}`. Please revise the wording."
msg = (
f"contains a weak word: `{word}` in option: `{option}`. "
"Please revise the wording."
)
log.warning_for_need(need, msg)


Expand Down
8 changes: 6 additions & 2 deletions src/extensions/score_metamodel/checks/graph_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def check_metamodel_graph(
check_to_perform: dict[str, str | dict] = check_config.get("check")
explanation = check_config.get("explanation", "")
assert explanation != "", (
f"Explanation for graph check {check_name} is missing. Explanations are mandatory for graph checks."
f"Explanation for graph check {check_name} is missing. "
"Explanations are mandatory for graph checks."
)
# Get all needs matching the selection criteria
selected_needs = filter_needs_by_criteria(
Expand All @@ -168,7 +169,10 @@ def check_metamodel_graph(
for need in selected_needs:
for parent_relation in list(check_to_perform.keys()):
if parent_relation not in need:
msg = f"Attribute not defined: `{parent_relation}` in need `{need['id']}`."
msg = (
f"Attribute not defined: `{parent_relation}` "
f"in need `{need['id']}`."
)
log.warning_for_need(need, msg)
continue

Expand Down
10 changes: 6 additions & 4 deletions src/extensions/score_metamodel/checks/id_contains_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
import os
import re

from sphinx.application import Sphinx
from sphinx_needs.data import NeedsInfoType

from score_metamodel import (
CheckLogger,
local_check,
)
from sphinx.application import Sphinx
from sphinx_needs.data import NeedsInfoType


@local_check
Expand Down Expand Up @@ -66,5 +65,8 @@ def id_contains_feature(app: Sphinx, need: NeedsInfoType, log: CheckLogger):
log.warning_for_option(
need,
"id",
f"Featurepart '{featureparts}' not in path '{docname}' or abbreviation not ok, expected: '{initials}'.",
(
f"Featurepart '{featureparts}' not in path '{docname}' "
f"or abbreviation not ok, expected: '{initials}'."
),
)
8 changes: 4 additions & 4 deletions src/extensions/score_metamodel/checks/standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ def my_pie_linked_standard_requirements_by_tag(
:labels: Linked, Not Linked
:legend:
:colors: LightSeaGreen, lightgray
:filter-func: score_metamodel.checks.standards.my_pie_linked_standard_requirements_by_tag(aspice40_man5)
:filter-func: path.to.function(tag_name)

The call:
=> score_metamodel.checks.standards.my_pie_linked_standard_requirements_by_tag(aspice40_man5)
=> path.to.function(tag_name)
would then pass 'aspice40_man5' as the arg1 and you have access to it then that way.

NOTE:: There can not be any `.`(dots) in the tag passed into this function


Return:
The direct return of this function is None. Sphinx-needs will get the mutated `results`
list, and use this to display/generate the piechart.
The direct return of this function is None. Sphinx-needs will get
the mutated `results`list, and use this to display/generate the piechart.

"""
count_linked = 0
Expand Down
12 changes: 7 additions & 5 deletions src/extensions/score_metamodel/external_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def _parse_bazel_external_need(s: str) -> ExternalNeedsSource | None:
return ExternalNeedsSource(
bazel_module=repo, path_to_target=path_to_target, target=target
)
else:
# Unknown data target. Probably not a needs.json file.
return None

# Unknown data target. Probably not a needs.json file.
return None


def parse_external_needs_sources_from_DATA(v: str) -> list[ExternalNeedsSource]:
Expand Down Expand Up @@ -148,7 +148,8 @@ def connect_external_needs(app: Sphinx, config: Config):
fixed_json_file = Path(r) / json_file
else:
logger.debug(
"Running outside bazel. Determining git root for external needs JSON file."
"Running outside bazel. "
"Determining git root for external needs JSON file."
)
git_root = Path.cwd().resolve()
while not (git_root / ".git").exists():
Expand Down Expand Up @@ -182,7 +183,8 @@ def connect_external_needs(app: Sphinx, config: Config):
"json_path": json_file,
}
)
# Making the prefixes uppercase here to match sphinx_needs, as it does this internally too.
# Making the prefixes uppercase here to match sphinx_needs,
# as it does this internally too.
assert isinstance(app.config.allowed_external_prefixes, list) # pyright: ignore[reportAny]
app.config.allowed_external_prefixes.append( # pyright: ignore[reportUnknownMemberType]
needs_json_data["project_prefix"].upper() # pyright: ignore[reportAny]
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/score_metamodel/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def assert_no_infos(self):

def assert_warning(self, expected_substring: str, expect_location: bool = True):
"""
Assert that the logger warning was called exactly once with a message containing
a specific substring.
Assert that the logger warning was called exactly once with a message
containing a specific substring.

This also verifies that the defaults from need() are used correctly.
So you must use need() to create the need object that is passed
Expand All @@ -71,8 +71,8 @@ def assert_warning(self, expected_substring: str, expect_location: bool = True):

def assert_info(self, expected_substring: str, expect_location: bool = True):
"""
Assert that the logger info was called exactly once with a message containing
a specific substring.
Assert that the logger info was called exactly once with a message
containing a specific substring.

This also verifies that the defaults from need() are used correctly.
So you must use need() to create the need object that is passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
from unittest.mock import Mock

import pytest
from sphinx.application import Sphinx

from score_metamodel.checks.check_options import (
check_extra_options,
check_options,
)
from score_metamodel.tests import fake_check_logger, need
from sphinx.application import Sphinx


@pytest.mark.metadata(
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/score_metamodel/tests/test_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# from sphinx.application import Sphinx
import pytest

from src.extensions.score_metamodel.checks import standards
from src.extensions.score_metamodel.tests import need # ,fake_check_logger

Expand Down Expand Up @@ -946,7 +947,8 @@ def test_assert_multiple_kwargs(self):
# Test if our assert works
with pytest.raises(
AssertionError,
match="Can only provide one tag to `my_pie_linked_standard_requirements_by_tag`",
match="Can only provide one tag to "
+ "`my_pie_linked_standard_requirements_by_tag`",
):
standards.my_pie_linked_standard_requirements_by_tag(
needs, results, arg1="test_tag", arg2="test_test_tag"
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/score_plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def get_runfiles_dir() -> Path:

def find_correct_path(runfiles: str) -> str:
"""
This ensures that the 'plantuml' binary path is found in local 'score_docs_as_code' and module use.
This ensures that the 'plantuml' binary path is found in local 'score_docs_as_code'
and module use.
"""
dirs = [str(x) for x in Path(runfiles).glob("*score_docs_as_code+")]
if dirs:
Expand Down
Loading
Loading