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
5 changes: 5 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ http_file(
)

bazel_dep(name = "score_process", version = "1.5.4")
git_override(
module_name = "score_process",
commit = "0113471d1dbb58d0890dae2569b18af69cd2025f",
remote = "https://github.com/eclipse-score/process_description.git",
)

# Provide the tools from the devcontainer to Bazel
bazel_dep(name = "score_devcontainer", version = "1.7.0")
2 changes: 0 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions src/extensions/score_metamodel/checks/check_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ def _get_normalized(need: NeedItem, key: str) -> list[str]:
return [raw_value]
if isinstance(raw_value, list):
# Verify all elements are strings
raw_list = cast(list[object], raw_value)
for item in raw_list:
if not isinstance(item, str):
raise ValueError
if not all(isinstance(item, str) for item in raw_value): # pyright: ignore[reportUnknownVariableType]
raise ValueError(
f"Expected a list of strings for key '{key}', got {raw_value}"
)
return cast(list[str], raw_value)
raise ValueError
if isinstance(raw_value, int):
# Doesnt make a lot of sense, but this preserves regex matching behavior for
# numeric values
return [str(raw_value)]
raise ValueError(
f"Expected a string or list of strings for key '{key}', got {type(raw_value)}"
)


def _validate_value_pattern(
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/score_metamodel/metamodel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ needs_types_base_options:
# Version will be mandatory global option in future releases
# For now giving grace periods to consumers
# req-Id: tool_req__docs_common_attr_version
version: ^.*$
version: ^[0-9]*$

# Custom semantic validation rules

Expand Down
64 changes: 25 additions & 39 deletions src/extensions/score_metamodel/yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from ruamel.yaml import YAML
from sphinx_needs import logging
from sphinx_needs.config import NeedsCoreFields

from src.extensions.score_metamodel.metamodel_types import (
ProhibitedWordCheck,
Expand Down Expand Up @@ -54,48 +55,13 @@ def default_options():
Helper function to get a list of all default options defined by
sphinx, sphinx-needs etc.
"""
return {
sn_fields = set(NeedsCoreFields.keys())
extra = {
"target_id",
"id",
"status",
"docname",
"lineno",
"type",
"lineno_content",
"doctype",
"content",
"type_name",
"type_color",
"type_style",
"title",
"full_title",
"layout",
"template",
"id_parent",
"id_complete",
"external_css",
"sections",
"section_name",
"type_prefix",
"constraints_passed",
"collapse",
"hide",
"delete",
"jinja_content",
"is_part",
"is_need",
"is_external",
"is_modified",
"modifications",
"has_dead_links",
"has_forbidden_dead_links",
"tags",
"arch",
"parts",
# Introduced with sphinx-needs 6.3.0
"is_import",
"constraints",
}
return sn_fields | extra


def _parse_need_type(
Expand Down Expand Up @@ -208,8 +174,28 @@ def _collect_all_custom_options(
defaults = default_options()
all_options = _collect_all_options(needs_types)

# These 5 are intentionally overwritten:
overlap = defaults & all_options
known_overlaps = {"id", "tags", "status", "content", "template"}
if known_overlaps != overlap:
logger.warning(
f"Some options overlap between the metamodel.yaml and default options, which may cause issues: {overlap}. "
f"Known overlaps that are intentionally kept are: {known_overlaps}."
)

# Add all fields, except for standard fields like "id", "content", "tags", "status"
# etc. that are already defined by sphinx-needs.
#
# Use params_int for "version" to ensure it's treated as an integer, and params_str
# for all other options.
#
# Note: "<integer>" is not encoded in the metamodel.yaml as there is no generic
# demand exists at the moment.
params_str = {"schema": {"type": "string"}, "default": ""}
params_int: dict[str, Any] = {"schema": {"type": "integer"}, "default": 0}

return {
name: {"schema": {"type": "string"}, "default": ""}
name: params_str if name != "version" else params_int
for name in sorted(all_options - defaults)
}

Expand Down
Loading