Skip to content

Commit 745814a

Browse files
feat: remove outdated options (#590)
* feat: remove outdated options * check more overlaps
1 parent e1ec741 commit 745814a

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

src/extensions/score_metamodel/metamodel.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ needs_types:
262262
# req-Id: tool_req__docs_common_attr_security
263263
security: ^(YES|NO)$
264264
optional_options:
265-
codelink: ^.*$
266-
testlink: ^.*$
267265
# req-Id: tool_req__docs_req_attr_reqcov
268266
reqcovered: ^(YES|NO)$
269267
# req-Id: tool_req__docs_req_attr_testcov
@@ -296,8 +294,6 @@ needs_types:
296294
# req-Id: tool_req__docs_req_link_satisfies_allowed
297295
satisfies: stkh_req
298296
optional_options:
299-
codelink: ^.*$
300-
testlink: ^.*$
301297
# req-Id: tool_req__docs_req_attr_reqcov
302298
reqcovered: ^(YES|NO)$
303299
# req-Id: tool_req__docs_req_attr_testcov
@@ -334,8 +330,6 @@ needs_types:
334330
satisfies: feat_req
335331
belongs_to: comp
336332
optional_options:
337-
codelink: ^.*$
338-
testlink: ^.*$
339333
# req-Id: tool_req__docs_req_attr_reqcov
340334
reqcovered: ^(YES|NO)$
341335
# req-Id: tool_req__docs_req_attr_testcov
@@ -360,7 +354,6 @@ needs_types:
360354
# TODO: make it mandatory
361355
satisfies: gd_req, stkh_req, feat_req, comp_req
362356
optional_options:
363-
codelink: ^.*$
364357
tags: ^.*$
365358
# req-Id: tool_req__docs_req_attr_reqcov
366359
reqcovered: ^(YES|NO)$
@@ -392,8 +385,6 @@ needs_types:
392385
# req-Id: tool_req__docs_common_attr_description
393386
content: ^[\s\S]+$
394387
optional_options:
395-
codelink: ^.*$
396-
testlink: ^.*$
397388
# req-Id: tool_req__docs_req_attr_reqcov
398389
reqcovered: ^(YES|NO)$
399390
# req-Id: tool_req__docs_req_attr_testcov

src/extensions/score_metamodel/yaml_parser.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,43 @@ def _parse_need_type(
104104
global_base_opts: dict[str, Any],
105105
):
106106
"""Build a single ScoreNeedType dict from the metamodel entry, incl defaults."""
107+
108+
# Check for overlapping option names between mandatory / optional options / links
109+
# and global_base_opts, as this would cause issues for usability.
110+
mandatory_options = yaml_data.get("mandatory_options", {})
111+
optional_options = yaml_data.get("optional_options", {})
112+
mandatory_links = yaml_data.get("mandatory_links", {})
113+
optional_links = yaml_data.get("optional_links", {})
114+
115+
overlap_checks: list[tuple[str, dict[str, Any], str, dict[str, Any]]] = [
116+
("mandatory_options", mandatory_options, "optional_options", optional_options),
117+
("mandatory_options", mandatory_options, "global_base_opts", global_base_opts),
118+
("optional_options", optional_options, "global_base_opts", global_base_opts),
119+
("mandatory_links", mandatory_links, "optional_links", optional_links),
120+
("mandatory_links", mandatory_links, "global_base_opts", global_base_opts),
121+
("optional_links", optional_links, "global_base_opts", global_base_opts),
122+
]
123+
errors: list[str] = []
124+
for a_name, a, b_name, b in overlap_checks:
125+
if overlap := set(a.keys()) & set(b.keys()):
126+
# FIXME: remove once "version" is clarified with process team
127+
if overlap == {"version"}:
128+
continue
129+
130+
errors.append(
131+
f"Directive '{directive_name}': {a_name} and {b_name} overlap: {overlap}."
132+
)
133+
107134
t: ScoreNeedType = {
108135
"directive": directive_name,
109136
"title": yaml_data["title"],
110137
"prefix": yaml_data.get("prefix", f"{directive_name}__"),
111138
"tags": yaml_data.get("tags", []),
112139
"parts": yaml_data.get("parts", 3),
113-
"mandatory_options": yaml_data.get("mandatory_options", {}),
114-
"optional_options": yaml_data.get("optional_options", {}) | global_base_opts,
115-
"mandatory_links": yaml_data.get("mandatory_links", {}),
116-
"optional_links": yaml_data.get("optional_links", {}),
140+
"mandatory_options": mandatory_options,
141+
"optional_options": optional_options | global_base_opts,
142+
"mandatory_links": mandatory_links,
143+
"optional_links": optional_links,
117144
}
118145

119146
# Ensure ID regex is set
@@ -126,7 +153,7 @@ def _parse_need_type(
126153
if "style" in yaml_data:
127154
t["style"] = yaml_data["style"]
128155

129-
return t
156+
return t, errors
130157

131158

132159
def _parse_needs_types(
@@ -136,14 +163,21 @@ def _parse_needs_types(
136163
"""Parse the 'needs_types' section of the metamodel.yaml."""
137164

138165
needs_types: dict[str, ScoreNeedType] = {}
166+
all_errors: list[str] = []
139167
for directive_name, directive_data in types_dict.items():
140168
assert isinstance(directive_name, str)
141169
assert isinstance(directive_data, dict)
142170

143-
needs_types[directive_name] = _parse_need_type(
171+
needs_types[directive_name], parsing_errors = _parse_need_type(
144172
directive_name, directive_data, global_base_options_optional_opts
145173
)
174+
all_errors.extend(parsing_errors)
146175

176+
if all_errors:
177+
raise SystemExit(
178+
"ERROR: Please resolve these overlaps in the metamodel.yaml to ensure proper functionality:\n"
179+
+ "\n".join(all_errors)
180+
)
147181
return needs_types
148182

149183

@@ -207,7 +241,6 @@ def load_metamodel_data(yaml_path: Path | None = None) -> MetaModelData:
207241
)
208242

209243
# Convert "types" from {directive_name: {...}, ...} to a list of dicts
210-
211244
needs_types = _parse_needs_types(
212245
data.get("needs_types", {}), global_base_options_optional_opts
213246
)

0 commit comments

Comments
 (0)